/** * Registers all actions, hooks and filters to provide full functionality/event triggers * * A note on the use of "$this" versus the often seen "&$this": In PHP5 a copy of the object is * only returned when using "clone". Also, for other use of references, the Zend Engine employs * a "copy-on-write" logic, meaning that variables will be referenced instead of copied until * it's actually written to. Do not circumvent Zend's optimizations! * * @see construct() * @api */ public function registerActions() { if ($this->registered || empty($this->plugin_file)) { return; } // Load locale $locale = get_locale(); if (!empty($locale)) { $mofile_locations = array($this->getPluginDir() . static::LOCALIZATION_DIR . $locale . '.mo', WP_LANG_DIR . '/' . $this->name . '-' . get_locale() . '.mo'); foreach ($mofile_locations as $mofile_location) { if (@is_file($mofile_location) && @is_readable($mofile_location)) { load_textdomain($this->name, $mofile_location); $this->locale_loaded = true; break; } } } // Plugin events (also in Multisite) if (!Helpers::doingAjax() && is_admin()) { add_action('after_plugin_row_' . plugin_basename($this->plugin_file), array($this, '_onAfterPluginText'), 10, 0); } // Do not register any actions after this if we're in Network Admin mode (unless override with register_admin_mode) if (Helpers::isNetworkAdminMode() && !$this->register_admin_mode) { $this->registered = true; return; } // Template Engine initialization $use_template_engine = Helpers::doingAjax() ? $this->ajax_uses_template : true; $views_dir = $this->getPluginDir() . static::VIEWS_DIR; $template_engine = false; if ($use_template_engine) { if (class_exists($this->template_engine)) { $rc = new \ReflectionClass($this->template_engine); if ($rc->implementsInterface('Pf4wp\\Template\\EngineInterface')) { $template_engine = $this->template_engine; } } if ($template_engine && @is_dir($views_dir) && @is_readable($views_dir)) { $options = array('_textdomain' => $this->name); if (defined('WP_DEBUG') && WP_DEBUG) { $options['debug'] = true; } if (($cache = StoragePath::validate($this->getPluginDir() . static::VIEWS_CACHE_DIR)) !== false) { $options['cache'] = $cache; } // Replace these options with those specified by the plugin developer, if any $options = array_replace($options, $this->template_options); $this->template = new $template_engine($views_dir, $options); } } // Set JS console define, if ours if (!defined('PF4WP_JS_CONSOLE') && $this->internal_options->remote_js_console) { define('PF4WP_JS_CONSOLE', $this->internal_options->remote_js_console); } if (!Helpers::doingAjax() && is_admin()) { // Internal and Admin events add_action('admin_menu', array($this, '_onAdminRegister'), 10, 0); add_action('wp_dashboard_setup', array($this, 'onDashboardWidgetRegister'), 10, 0); add_action('admin_notices', array($this, '_onAdminNotices'), 10, 0); // Plugin events add_filter('plugin_action_links_' . plugin_basename($this->plugin_file), array($this, '_onPluginActionLinks'), 10, 1); } // Public events add_action('parse_request', array($this, '_onPublicInit'), 10, 0); // AJAX events add_action('wp_ajax_' . $this->name, array($this, '_onAjaxCall'), 10, 0); if ($this->public_ajax) { add_action('wp_ajax_nopriv_' . $this->name, array($this, '_onPublicAjaxCall'), 10, 0); } // Register a final action when WP has been loaded add_action('wp_loaded', array($this, '_onWpLoaded'), 10, 0); $this->onRegisterActions(); // Check if there are any on-demand admin filters requested if (is_admin()) { $filters = array(); if (isset($_REQUEST['filter'])) { $filters = explode(',', $_REQUEST['filter']); } // And check the referer arguments as well if this is a POST request if (!empty($_POST) && isset($_SERVER['HTTP_REFERER'])) { $referer_args = explode('&', ltrim(strstr($_SERVER['HTTP_REFERER'], '?'), '?')); foreach ($referer_args as $referer_arg) { if (!empty($referer_arg) && strpos($referer_arg, '=') !== false) { list($arg_name, $arg_value) = explode('=', $referer_arg); if ($arg_name == 'filter') { $filters = array_replace($filters, explode(',', $arg_value)); break; } } } } // Remove any possible duplicates from filters $filters = array_unique($filters); // Fire filter events foreach ($filters as $filter) { $this->onFilter($filter); } } // Done! $this->registered = true; }