public function init() { Shortcode::registerHandler('add_shortcode'); $this->actions(); $this->viewSections(); $this->filters(); add_action('wp_register_scripts', function () { Hook::run('scripts-register'); }); add_action('wp_register_style', function () { Hook::run('style-register'); }); }
/** * Renders a controller and its action. * * @param string $controller * @param string $action * * @throws RenderException */ public function render($controller, $action) { if (!$this->canRender()) { return; } $view_path = $this->views->findView($controller, $action, $this->getTemplate()); if ($view_path) { Hook::run('rendering-render', [$controller, strtolower($action), $this->controller]); $tags = Filter::run('view-tags', array(array(), $this->controller)); $engine = RenderingEngines::getEngine($this->getTemplate(), $this->controller->getViewPath()); $view_content = $engine->render($view_path, array_merge($this->getBag(), $tags, ['bag' => $this->getBag() + $tags])); $layout_path = $this->views->findLayout($this->getTemplate()); if ($layout_path) { $engine = RenderingEngines::getEngine($this->getTemplate(), $view_path); $view_content = $engine->render($layout_path, array_merge($this->getBag(), $tags, ['bag' => $this->getBag() + $tags], Filter::run("{$this->controllerName}-{$action}-blocks", array(array('view' => $view_content))))); } $this->disableRendering(); RenderedContent::set($view_content); return; } $view_content = "Could not find view for {$controller}, {$action} in: " . $view_path; trigger_error($view_content, E_USER_WARNING); }
/** * Executes an action on the controller. * * @param string $action The name of the action to execute. * @param array $getParams values part of routing * * @throws \Exception Thrown if action is not found. */ public function executeAction($action, $getParams = array()) { if (method_exists($this, $action)) { $reflection = new ReflectionMethod($this, $action); if (!$reflection->isPublic()) { trigger_error(sprintf('The action you tried to execute is not public: %s', $action)); if (method_exists($this, 'notFound')) { $this->notFound(); } } $this->action = $action; $perform = true; $action_params = $reflection->getParameters(); $this->params = $getParams; $paramValues = $this->getParameters($getParams, $action_params); $this->performForEvent($this, $this->getValues(), 'beforeAction', $action, $perform); if ($perform) { Hook::run($this->controller . '-pre' . ucfirst($action), $this); call_user_func_array(array($this, $action), $paramValues); $this->actionRan = true; Hook::run($this->controller . '-post' . ucfirst($action), $this); } if ($this->actionHasRun()) { $this->performForEvent($this, $this->getValues(), 'afterActionHasRun', $action); } $this->performForEvent($this, $this->getValues(), 'afterAction', $action); if ($this->renderer->canRender()) { $this->renderer->RenderToAction($action); } $this->setupHeadersAndResponseCode(); } elseif (method_exists($this, 'notFound')) { $this->notFound(); } else { throw new \Exception('There are no action that corresponds to request.'); } }
/** * Called on plugins loaded. runs hooks. aoisora-libraries, aoisora-loaded */ public function loaded() { Events\Hook::run('cloudless-libraries'); Events\Hook::run('cloudless-loaded'); }
function aoisora_loaded() { Hook::run('aoisora-loaded'); }