public function init() { $this->_activateNonceName = $this->_pm->getAbbrLower() . '-activate-module'; $this->_deactivateNonceName = $this->_pm->getAbbrLower() . '-deactivate-module'; $this->_deleteNonceName = $this->_pm->getAbbrLower() . '-delete-module'; if (isset($_GET['activate']) && wp_verify_nonce($_GET[$this->_activateActionName], $this->_activateNonceName)) { $id = esc_attr($_GET['id']); $module = $this->_pm->getBootstrap()->getModuleManager()->getModule($id); if ($module instanceof IfwPsn_Wp_Module_Bootstrap_Abstract) { $module->activate(); if ($this->_pm->hasController()) { $this->_pm->getController()->gotoRoute($this->getController(), $this->getAppaction(), $this->getPage()); } } } elseif (isset($_GET['deactivate']) && wp_verify_nonce($_GET[$this->_deactivateActionName], $this->_deactivateNonceName)) { $id = esc_attr($_GET['id']); $module = $this->_pm->getBootstrap()->getModuleManager()->getModule($id); if ($module instanceof IfwPsn_Wp_Module_Bootstrap_Abstract) { $module->deactivate(); if ($this->_pm->hasController()) { $this->_pm->getController()->gotoRoute($this->getController(), $this->getAppaction(), $this->getPage()); } } } elseif (isset($_GET['delete']) && wp_verify_nonce($_GET[$this->_deleteActionName], $this->_deleteNonceName)) { $id = esc_attr($_GET['id']); $module = $this->_pm->getBootstrap()->getModuleManager()->getModule($id); if ($module instanceof IfwPsn_Wp_Module_Bootstrap_Abstract) { $module->delete(); if ($this->_pm->hasController()) { $this->_pm->getController()->gotoRoute($this->getController(), $this->getAppaction(), $this->getPage()); } } } }
/** * Sets custom controller name * * @param IfwPsn_Vendor_Zend_Controller_Request_Abstract $request * @return bool */ public function preDispatch(IfwPsn_Vendor_Zend_Controller_Request_Abstract $request) { $response = $this->getResponse(); $response->headersSentThrowsException = false; try { if ($request->getControllerName() == $this->_pm->getAbbrLower() . '-error') { return; } elseif ($this->_isPatchesRedirect($request)) { $request->setModuleName('default'); $request->setControllerName($this->_pm->getAbbrLower() . '-patches'); $request->setActionName('index'); } else { $customController = $this->_getCustomController($request); if ($customController != false) { // set the custom controller if exists $request->setControllerName($customController); } } } catch (Exception $e) { // Repoint the request to the default error handler $request->setModuleName('default'); $request->setControllerName('Psn-wwerror'); $request->setActionName('error'); // Set up the error handler $error = new IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler($this->_pm); $error->type = IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER; $error->request = clone $request; $error->exception = $e; $request->setParam('error_handler', $error); } }
/** * @return IfwPsn_Wp_Ajax_Response_Abstract */ public function getResponse() { $tpl = IfwPsn_Wp_Tpl::getInstance($this->_pm); if ($this->_iframeSrc !== null) { $iframeSrc = $this->_iframeSrc; } elseif (strpos($this->_pm->getConfig()->plugin->optionsPage, 'options-general.php') !== false) { $iframeSrc = IfwPsn_Wp_Proxy_Admin::getUrl() . IfwPsn_Wp_Proxy_Admin::getMenuUrl($this->_pm, 'selftest'); $iframeSrc = str_replace('wp-admin//', 'wp-admin/', $iframeSrc); } else { $iframeSrc = IfwPsn_Wp_Proxy_Admin::getAdminPageUrl($this->_pm, $this->_pm->getAbbrLower() . '_selftest', $this->_pm->getAbbrLower() . '_selftest'); } $context = array('ajax' => $this, 'iframe_src' => $iframeSrc, 'img_path' => $this->_pm->getEnv()->getUrlAdminImg()); $timestamp = $this->_pm->getBootstrap()->getSelftester()->getTimestamp(); if (!empty($timestamp)) { require_once $this->_pm->getPathinfo()->getRootLib() . 'IfwPsn/Wp/Date.php'; $timestamp = IfwPsn_Wp_Date::format($timestamp); } $context['timestamp'] = $timestamp; $status = $this->_pm->getBootstrap()->getSelftester()->getStatus(); if ($status === true || $status === 'true' || $status == '1') { $context['status'] = 'true'; } elseif ($status === false || $status === 'false' || $status == '0') { $context['status'] = 'false'; } else { $context['status'] = 'null'; } $html = $tpl->render('metabox_pluginstatus.html.twig', $context); $success = true; $response = new IfwPsn_Wp_Ajax_Response_Json($success); $response->addData('html', $html); return $response; }
/** * Loads the application */ public function load() { IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_before_application_load', $this); $this->_pm->getLogger()->logPrefixed('Trying to load application...'); $this->_adapter->load(); IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_after_application_load', $this); }
/** * @param IfwPsn_Wp_Plugin_Manager $pm */ public function __construct(IfwPsn_Wp_Plugin_Manager $pm) { $this->_pm = $pm; if (method_exists($this, '_init')) { $this->_init(); } do_action($this->_pm->getAbbrLower() . '_add_feature', $this); }
public function activate() { IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_selftester_activate', $this); $this->_pm->getBootstrap()->getOptionsManager()->registerExternalOption($this->_timestampOptionName); $this->_pm->getBootstrap()->getOptionsManager()->registerExternalOption($this->_statusOptionName); if (!$this->_skipAutorun()) { $this->_initAutorun(); } }
/** * Inits the controller object on bootstrap to place WP actions on before page load * * @throws IfwPsn_Vendor_Zend_Application_Bootstrap_Exception */ public function initController() { $front = $this->getResource('FrontController'); $default = $front->getDefaultModule(); if (null === $front->getControllerDirectory($default)) { throw new IfwPsn_Vendor_Zend_Application_Bootstrap_Exception('No default controller directory registered with front controller'); } $front->registerPlugin(new IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler(array('controller' => $this->_pm->getAbbrLower() . '-error'))); $front->setParam('bootstrap', $this); $front->initController($this->_pm); }
/** * @param Exception $e */ protected function _handleException(Exception $e) { $this->_pm->getLogger()->error($e->getMessage()); $request = IfwPsn_Zend_Controller_Front::getInstance()->getRequest(); // Repoint the request to the default error handler // $request->setModuleName('default'); // $request->setControllerName('Psn-ewrror'); // $request->setActionName('error'); // Set up the error handler $error = new IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler(array('controller' => $this->_pm->getAbbrLower() . '-error')); $error->type = IfwPsn_Vendor_Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER; if (is_object($request)) { $error->request = clone $request; } $error->exception = $e; $request->setParam('error_handler', $error); }
/** * @return array */ protected function _getColumns() { return IfwPsn_Wp_Proxy_Filter::apply($this->_pm->getAbbrLower() . '_' . $this->_id . '_get_columns', $this->getColumns()); }
/** * @param $callback */ public function addPluginOptions($callback) { if ($this->isAccess() && is_callable($callback)) { add_action($this->_pm->getAbbrLower() . '_on_options_load', $callback); } }
protected function _init() { $this->_optionName = $this->_pm->getAbbrLower() . '-custom-modules'; // init custom modules activation storage $this->_pm->getBootstrap()->getOptionsManager()->registerExternalOption($this->_optionName); }
/** * @param IfwPsn_Wp_Plugin_Manager $pm * @param $tag * @param $function_to_remove * @param int $priority * @return bool */ public static function removePlugin(IfwPsn_Wp_Plugin_Manager $pm, $tag, $function_to_remove, $priority = 10) { return remove_action($pm->getAbbrLower() . '_' . $tag, $function_to_remove, $priority); }
protected function _init() { IfwPsn_Wp_Proxy_Action::add($this->_pm->getAbbrLower() . '_general_options_init', array($this, 'registerOptionsCallback')); IfwPsn_Wp_Proxy_Action::add($this->_pm->getAbbrLower() . '_external_options_init', array($this, 'registerOptionsCallback')); }
/** * @return bool */ public function isOptionsSubmit() { return isset($_POST) && isset($_POST['option_page']) && $_POST['option_page'] == $this->_pm->getAbbrLower() . '_options'; }
/** * Alias for apply_filters * * @param IfwPsn_Wp_Plugin_Manager $pm * @param $tag * @param $value * @return mixed|void * @deprecated */ public static function applyPlugin(IfwPsn_Wp_Plugin_Manager $pm, $tag, $value) { $tag = $pm->getAbbrLower() . '_' . $tag; return self::apply($tag, $value); }
/** * @param string $name * @param array $arguments */ public function __call($name, $arguments) { $controller = $this->_request->get('controller'); $controller = esc_attr($controller); IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_' . $controller . '_action-' . str_replace('Action', '', $name), $this, $arguments); }
/** * Runs after the plugin bootstrap */ private function _postBootstrap() { // trigger action after_bootstrap IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_after_bootstrap', $this); $this->_notifyObservers(self::OBSERVER_POST_BOOTSTRAP); }
/** * Adds a content block * * @param $id * @param string $label * @param string $content * @param string $iconClass */ public function addBlock($id, $label, $content, $iconClass) { IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_plugininfo_before_' . $id, $this); $this->_infoBlocks[] = array('id' => $id, 'label' => $label, 'content' => $content, 'iconClass' => $iconClass); IfwPsn_Wp_Proxy_Action::doAction($this->_pm->getAbbrLower() . '_plugininfo_after_' . $id, $this); }