public function __construct($args = array()) { // Load our helper function require_once 'icit-helpers.php'; // notification helper require_once 'icit-notices.php'; // Makes it easier to set default options on get_option. require_once 'icit-defaults.php'; if (isset($args['dir'])) { $this->dir = $args['dir']; } if (isset($args['url'])) { $this->url = $args['url']; } // Set the folder for the core $this->dir === null && ($this->dir = dirname(__FILE__)); // Load the translation stuff.. $locale = get_locale(); if (file_exists($this->dir . '/lang/' . self::DOM . '-' . $locale . '.mo')) { load_textdomain(self::DOM, $this->dir . '/lang/' . self::DOM . '-' . $locale . '.mo'); } // add core class autoloaders spl_autoload_register(array($this, '__autoload')); //spl_autoload_register( array( $this, '__autoload_psr0' ) ); spl_autoload_register(array($this, '__autoload_wp')); if (did_action('init') && !(isset($_GET['action']) && $_GET['action'] == 'activate' && isset($_GET['plugin']))) { _doing_it_wrong('icit_core', __('icit_core should be included at the top of your theme or plug-in file and should load before the init action.', self::DOM), 'icit_core:1.0'); } else { if (!did_action('plugins_loaded') && !did_action('setup_theme') && $this->is_plugin == null) { $this->is_plugin = true; } elseif (did_action('plugins_loaded') && !did_action('setup_theme') && $this->is_plugin === null) { $this->is_plugin = false; } } }
function tribe_is_recurring_event($post_id = null) { $post_id = Tribe__Events__Main::postIdHelper($post_id); if (!$post_id) { _doing_it_wrong(__FUNCTION__, 'You need to pass a post ID or use it in the loop.', '3.10'); return false; } $post = get_post($post_id); if ($post->post_type != Tribe__Events__Main::POSTTYPE) { return false; } $recurring = false; if ($post->post_parent > 0) { $recurring = true; } else { $recurrence_meta = get_post_meta($post_id, '_EventRecurrence', true); if (!empty($recurrence_meta['rules'])) { foreach ($recurrence_meta['rules'] as &$recurrence) { if ('None' !== $recurrence['type']) { $recurring = true; break; } } } } return apply_filters('tribe_is_recurring_event', $recurring, $post_id); }
/** * Create an MS Object. * * @since 1.0.0 * * @param string $class The class to create object from. * @return object The created object. */ public static function create($class, $init_arg = null) { $singletons = array('MS_Model_Pages', 'MS_Model_Settings', 'MS_Model_Addon', 'MS_Model_Rule', 'MS_Model_Simulate'); $class = trim($class); if (in_array($class, $singletons)) { _doing_it_wrong('MS_Factory::create()', 'This class is a singleton and should be fetched via MS_Factory::load() -> ' . $class, '1.0.4.5'); } if (class_exists($class)) { if (null === $init_arg) { $obj = new $class(); } else { $obj = new $class($init_arg); } } else { throw new Exception('Class ' . $class . ' does not exist.'); } /* * Assign a new unique-ID to the object right after loading it. * * Purpose: * This helps us to spot duplicates of the same object. * We can also identify objects that were not created by MS_Factory. */ $obj->_factory_id = uniqid('object-'); self::prepare_obj($obj); return apply_filters('ms_factory_create_' . $class, $obj); }
/** * __set function. * @todo use set_* methods * @param mixed $property * @param mixed $key */ public function __set($key, $value) { _doing_it_wrong($key, 'Customer properties should not be set directly.', '2.7'); $key = $this->filter_legacy_key($key); $this->_data[$key] = $value; $this->_changed = true; }
/** * Constructor */ public static function construct() { /** * The auto-switch should always work */ self::_load_plugin_list(); self::_setup_automatic_switch(); /** * The rest relies on user privileges, and therefore must wait until necessary WP functions are loaded */ if (!did_action('plugins_loaded')) { _doing_it_wrong(__METHOD__, __('Must call in of after the "plugins_loaded" action.', 'redux-framework'), '14.03.19'); return; } /** * Low-level users won't see anything */ if (!current_user_can(TIVWP_DM::MIN_CAPABILITY)) { return; } /** * The main actions happen in the admin area */ if (is_admin()) { self::_setup_i18n(); self::_setup_plugin_composer(); self::_setup_admin_interface(); } }
/** * Class Constructor * * @since 1.0 * @param array $config the configuration required for the updater to work * @see has_minimum_config() * @return void */ public function __construct($config = array()) { require_once plugin_dir_path(__FILE__) . "Parsedown.php"; $defaults = array('slug' => plugin_basename(__FILE__), 'proper_folder_name' => dirname(plugin_basename(__FILE__)), 'sslverify' => true, 'access_token' => '', 'changelog', 'githubAPIResult'); $this->config = wp_parse_args($config, $defaults); //print_r($this->config);die(); // if the minimum config isn't set, issue a warning and bail if (!$this->has_minimum_config()) { $message = 'The GitHub Updater was initialized without the minimum required configuration, please check the config in your plugin. The following params are missing: '; $message .= implode(',', $this->missing_config); _doing_it_wrong(__CLASS__, $message, self::VERSION); return; } $this->set_defaults(); add_filter('pre_set_site_transient_update_plugins', array($this, 'api_check')); // Hook into the plugin details screen if (strpos($_SERVER['SCRIPT_NAME'], 'plugin-install.php')) { if (isset($_GET['tab']) && strpos($_GET['tab'], 'rapidology') > 0) { add_filter('plugins_api', array($this, 'get_plugin_info'), 10, 3); } } if (isset($_GET['tab'])) { if (isset($_GET['plugin']) && $_GET['plugin'] == 'rapidology') { add_filter('plugins_api', array($this, 'get_plugin_info'), 10, 3); } } add_filter('upgrader_post_install', array($this, 'upgrader_post_install'), 10, 3); // set timeout add_filter('http_request_timeout', array($this, 'http_request_timeout')); // set sslverify for zip download add_filter('http_request_args', array($this, 'http_request_sslverify'), 10, 2); }
/** * Set key/value within an array, can set a key nested inside of a multidimensional array. * * Example: set( $a, [ 0, 1, 2 ], 'hi' ) sets $a[0][1][2] = 'hi' and returns $a. * * @param mixed $array The array containing the key this sets. * @param string|array $key To set a key nested multiple levels deep pass an array * specifying each key in order as a value. * Example: array( 'lvl1', 'lvl2', 'lvl3' ); * @param mixed $value The value. * * @return array Full array with the key set to the specified value. */ public static function set(array $array, $key, $value) { // Convert strings and such to array. $key = (array) $key; // Setup a pointer that we can point to the key specified. $key_pointer =& $array; // Iterate through every key, setting the pointer one level deeper each time. foreach ($key as $i) { // Ensure current array depth can have children set. if (!is_array($key_pointer)) { // $key_pointer is set but is not an array. Converting it to an array // would likely lead to unexpected problems for whatever first set it. $error = sprintf('Attempted to set $array[%1$s] but %2$s is already set and is not an array.', implode($key, ']['), $i); _doing_it_wrong(__FUNCTION__, esc_html($error), '4.3'); break; } elseif (!isset($key_pointer[$i])) { $key_pointer[$i] = array(); } // Dive one level deeper into the nested array. $key_pointer =& $key_pointer[$i]; } // Set the value for the specified key $key_pointer = $value; return $array; }
/** * Registers a REST API route. * * @since 4.4.0 * * @global WP_REST_Server $wp_rest_server ResponseHandler instance (usually WP_REST_Server). * * @param string $namespace The first URL segment after core prefix. Should be unique to your package/plugin. * @param string $route The base URL for route you are adding. * @param array $args Optional. Either an array of options for the endpoint, or an array of arrays for * multiple methods. Default empty array. * @param bool $override Optional. If the route already exists, should we override it? True overrides, * false merges (with newer overriding if duplicate keys exist). Default false. * @return bool True on success, false on error. */ function register_rest_route($namespace, $route, $args = array(), $override = false) { /** @var WP_REST_Server $wp_rest_server */ global $wp_rest_server; if (empty($namespace)) { /* * Non-namespaced routes are not allowed, with the exception of the main * and namespace indexes. If you really need to register a * non-namespaced route, call `WP_REST_Server::register_route` directly. */ _doing_it_wrong('register_rest_route', __('Routes must be namespaced with plugin or theme name and version.'), '4.4.0'); return false; } else { if (empty($route)) { _doing_it_wrong('register_rest_route', __('Route must be specified.'), '4.4.0'); return false; } } if (isset($args['callback'])) { // Upgrade a single set to multiple. $args = array($args); } $defaults = array('methods' => 'GET', 'callback' => null, 'args' => array()); foreach ($args as $key => &$arg_group) { if (!is_numeric($arg_group)) { // Route option, skip here. continue; } $arg_group = array_merge($defaults, $arg_group); } $full_route = '/' . trim($namespace, '/') . '/' . trim($route, '/'); $wp_rest_server->register_route($namespace, $full_route, $args, $override); return true; }
/** * Save module options. * * @return void */ public function update_modules() { check_admin_referer($this->nonce_action); if (!current_user_can('manage_network_options')) { wp_die('FU'); } $this->set_module_activation_status(); /** * Runs before the redirect. * * Process your fields in the $_POST superglobal here and then call update_site_option(). * * @param array $_POST */ do_action('mlp_modules_save_fields', $_POST); // backwards compatibility if (has_action('mlp_settings_save_fields')) { _doing_it_wrong('mlp_settings_save_fields', 'mlp_settings_save_fields is deprecated, use mlp_modules_save_fields instead.', '1.2'); /** * @see mlp_modules_save_fields * @deprecated */ do_action('mlp_settings_save_fields'); } wp_safe_redirect(network_admin_url('settings.php?page=mlp&message=updated')); exit; }
/** * Unset a nav array value at the specified offset. * * @since 2.6.0 * * @param mixed $offset Array offset. */ public function offsetUnset($offset) { _doing_it_wrong('bp_nav', __('These globals should not be used directly and are deprecated. Please use the BuddyPress nav functions instead.', 'buddypress'), '2.6.0'); $this->get_component_nav($offset)->delete_nav($offset, $this->get_parent_slug()); // Clear the cached nav. unset($this->backcompat_nav[$offset]); }
/** * Wrapper for wc_doing_it_wrong. * * @since 2.7.0 * @param string $function * @param string $version * @param string $replacement */ function wc_doing_it_wrong($function, $message, $version) { if (is_ajax()) { error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}."); } else { _doing_it_wrong($function, $message, $version); } }
/** * Main function for returning orders, uses the WC_Order_Factory class. * * @since 2.2 * @param mixed $the_order Post object or post ID of the order. * @return WC_Order */ function wc_get_order($the_order = false) { if (!did_action('woocommerce_init')) { _doing_it_wrong(__FUNCTION__, __('wc_get_order should not be called before the woocommerce_init action.', 'woocommerce'), '2.5'); return false; } return WC()->order_factory->get_order($the_order); }
public function __construct() { if (empty($this->type)) { _doing_it_wrong('WP_JSON_Authentication::__construct', __('The type of authentication must be set'), 'WPAPI-0.9'); return; } add_filter('json_check_authentication', array($this, 'authenticate'), 0); }
/** * __set function. * @todo use set_* methods * @param mixed $property * @param mixed $key */ public function __set($key, $value) { _doing_it_wrong($key, 'Customer properties should not be set directly.', '2.7'); $key = $this->filter_legacy_key($key); if (is_callable(array($this, "set_{$key}"))) { $this->{"set_{$key}"}($value); } }
/** * Return an object of type Charitable_Benefactor, given a benefactor record and an extension. * * @param Object $benefactor * @param string $extension * @return Charitable_Benefactor * @access public * @static * @since 1.0.0 */ public static function get_object($benefactor, $extension) { $class = apply_filters('charitable_benefactor_class_' . $extension, false); if (!class_exists($class)) { _doing_it_wrong(__METHOD__, __('Benefactor class does not exist for given extension.', '1.0.0')); } return new $class($benefactor); }
public function set_min_wp($version) { if (!is_string($version)) { _doing_it_wrong(__METHOD__, sprintf('Version parameter must be of type string, %s given', esc_html(gettype($version))), null); return; } $this->required_wp = $version; }
/** * Main function for returning products, uses the WC_Product_Factory class. * * @param mixed $the_product Post object or post ID of the product. * @param array $args (default: array()) Contains all arguments to be used to get this product. * @return WC_Product */ function wc_get_product($the_product = false, $args = array()) { if (!did_action('woocommerce_init')) { _doing_it_wrong(__FUNCTION__, __('wc_get_product should not be called before the woocommerce_init action.', 'woocommerce'), '2.5'); return false; } return WC()->product_factory->get_product($the_product, $args); }
/** * Add extra CSS styles to a registered stylesheet. * * Styles will only be added if the stylesheet in already in the queue. * Accepts a string $data containing the CSS. If two or more CSS code blocks * are added to the same stylesheet $handle, they will be printed in the order * they were added, i.e. the latter added styles can redeclare the previous. * * @see WP_Styles::add_inline_style() * * @since 3.3.0 * * @param string $handle Name of the stylesheet to add the extra styles to. Must be lowercase. * @param string $data String containing the CSS styles to be added. * @return bool True on success, false on failure. */ function wp_add_inline_style($handle, $data) { _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); if (false !== stripos($data, '</style>')) { _doing_it_wrong(__FUNCTION__, __('Do not pass style tags to wp_add_inline_style().'), '3.7'); $data = trim(preg_replace('#<style[^>]*>(.*)</style>#is', '$1', $data)); } return wp_styles()->add_inline_style($handle, $data); }
function enlightenment_register_settings() { $option_name = current_theme_supports('enlightenment-theme-settings', 'option_name'); if (empty($option_name)) { _doing_it_wrong(__FUNCTION__, 'Please specify an Option Name for your Theme Setings.', ''); return; } register_setting(current_theme_supports('enlightenment-theme-settings', 'option_group'), current_theme_supports('enlightenment-theme-settings', 'option_name'), current_theme_supports('enlightenment-theme-settings', 'sanitize_callback')); }
function yarpp_related_exist($reference_ID = false, $args = array()) { global $yarpp; if (is_array($reference_ID)) { _doing_it_wrong(__FUNCTION__, "YARPP's (internal) related function signature now takes the \$reference_ID first.", '3.4'); return; } return $yarpp->related_exist($reference_ID, $args, $echo); }
/** * Add extra CSS styles to a registered stylesheet. * * Styles will only be added if the stylesheet in already in the queue. * Accepts a string $data containing the CSS. If two or more CSS code blocks * are added to the same stylesheet $handle, they will be printed in the order * they were added, i.e. the latter added styles can redeclare the previous. * * @see WP_Styles::add_inline_style() * * @since 3.3.0 * * @param string $handle Name of the stylesheet to add the extra styles to. * @param string $data String containing the CSS styles to be added. * @return bool True on success, false on failure. */ function wp_add_inline_style($handle, $data) { _wp_scripts_maybe_doing_it_wrong(__FUNCTION__); if (false !== stripos($data, '</style>')) { _doing_it_wrong(__FUNCTION__, sprintf(__('Do not pass %1$s tags to %2$s.'), '<code><style></code>', '<code>wp_add_inline_style()</code>'), '3.7.0'); $data = trim(preg_replace('#<style[^>]*>(.*)</style>#is', '$1', $data)); } return wp_styles()->add_inline_style($handle, $data); }
/** * @deprecated since 2.4.0 * @return string */ function geoip_detect_get_abs_db_filename() { _doing_it_wrong('GeoIP Detection: geoip_detect_get_abs_db_filename', 'geoip_detect_get_abs_db_filename should not be called directly', '2.4.0'); $source = \YellowTree\GeoipDetect\DataSources\DataSourceRegistry::getInstance()->getCurrentSource(); if (method_exists($source, 'maxmindGetFilename')) { return $source->maxmindGetFilename(); } return ''; }
/** * Registers new contextual help tab * @param string $page Page path that is compared to the pagenow global * @param string $id Help tab id * @param string $title Help tab title * @param array $args Arguments for the tab */ static function register_tab($id, $title, $args) { if (empty($args['page'])) { _doing_it_wrong(__METHOD__, 'Cannot register help tab without specifying the page or pages to display it on', '0.0.1'); } $page = $args['page']; unset($args['page']); self::$tabs[$id] = array('page' => $page, 'id' => $id, 'title' => $title, 'args' => $args); }
/** * Set up the currently logged-in user. * * @uses did_action() To make sure the user isn't loaded out of order. * @uses do_action() Calls 'bp_setup_current_user'. */ function bp_setup_current_user() { // If the current user is being setup before the "init" action has fired, // strange (and difficult to debug) role/capability issues will occur. if (!did_action('after_setup_theme')) { _doing_it_wrong(__FUNCTION__, __('The current user is being initialized without using $wp->init().', 'buddypress'), '1.7'); } do_action('bp_setup_current_user'); }
private function current_user_can($capabilities) { // If the current user is being setup before the "init" action has fired, // strange (and difficult to debug) role/capability issues will occur. if (!did_action('set_current_user')) { _doing_it_wrong(__FUNCTION__, "Trying to call current_user_is_*() before the current user has been set.", '3.3.1'); } return $this->user_can($this->request->get_current_user(), $capabilities); }
function related_entries($args = array(), $reference_ID = false, $echo = true) { global $hw_yarpp; if (false !== $reference_ID && is_bool($reference_ID)) { _doing_it_wrong(__FUNCTION__, "This YARPP function now takes \$args first and \$reference_ID second.", '3.5'); return; } $args['post_type'] = $hw_yarpp->get_post_types(); return yarpp_related($args, $reference_ID, $echo); }
/** * Load a view from the admin/views folder. * * If the view is not found, an Exception will be thrown. * * Example usage: charitable_admin_view('metaboxes/cause-metabox'); * * @param string $view The view to display. * @param array $view_args Optional. Arguments to pass through to the view itself * @return void * @since 1.0.0 */ function charitable_admin_view($view, $view_args = array()) { $filename = apply_filters('charitable_admin_view_path', charitable()->get_path('admin') . 'views/' . $view . '.php', $view, $view_args); if (!is_readable($filename)) { _doing_it_wrong(__FUNCTION__, __('Passed view (' . $filename . ') not found or is not readable.', 'charitable'), '1.0.0'); } ob_start(); include $filename; ob_end_flush(); }
public function add($attributes) { $attributes = apply_filters('cornerstone_generator_map', $attributes); if (!isset($attributes['id']) || !is_string($attributes['id'])) { return _doing_it_wrong('xsg_add', 'Invalid `id` attribute', '2.7'); } $this->shortcodes[$attributes['id']] = $attributes; if (isset($attributes['section']) && !in_array($attributes['section'], $this->sections)) { array_push($this->sections, $attributes['section']); } }
/** * Construct the API handler object. */ public function __construct() { if (empty($this->parent_type)) { _doing_it_wrong('WP_REST_Meta_Controller::__construct', __('The object type must be overridden'), 'WPAPI-2.0'); return; } if (empty($this->parent_base)) { _doing_it_wrong('WP_REST_Meta_Controller::__construct', __('The parent base must be overridden'), 'WPAPI-2.0'); return; } }
public function add($attributes) { if (isset($attributes['id']) && is_string($attributes['id'])) { $this->shortcodes[$attributes['id']] = $attributes; if (isset($attributes['section']) && !in_array($attributes['section'], $this->sections)) { array_push($this->sections, $attributes['section']); } } else { _doing_it_wrong('xsg_add', 'Invalid `id` attribute', '2.7'); } }