private function init_controller($controller) { global $wp_query; if (empty($controller)) { return; } $controller_args = trim(get_query_var('wpsc_controller_args'), '/'); $controller_args = explode('/', $controller_args); if (!is_array($controller_args)) { $controller_args = array(); } $slug = array_shift($controller_args); $method = str_replace(array(' ', '-'), '_', $slug); if (!$method) { $slug = $method = 'index'; } $this->controller_slug = $slug; $this->controller_method = $method; $this->controller_name = $controller; $this->controller = _wpsc_load_controller($controller); // If method/path not found, show the 404 page if (!is_callable(array($this->controller, $method))) { _wpsc_doing_it_wrong(__FUNCTION__, __('Invalid controller method: ' . get_class($this->controller) . '::' . $method . '()', 'wpsc'), '4.0'); return $this->not_found(); } do_action('wpsc_router_init'); $this->controller_args = $controller_args; if (is_callable(array($this->controller, '_pre_action'))) { call_user_func(array($this->controller, '_pre_action'), $this->controller_method, $this->controller_args); } call_user_func_array(array($this->controller, $this->controller_method), $this->controller_args); if (is_callable(array($this->controller, '_post_action'))) { call_user_func(array($this->controller, '_post_action'), $this->controller_method, $this->controller_args); } }
private function init_controller($controller) { if (empty($controller)) { return; } $controller_args = trim(get_query_var('wpsc_controller_args'), '/'); $controller_args = explode('/', $controller_args); if (!is_array($controller_args)) { $controller_args = array(); } $slug = array_shift($controller_args); $method = str_replace(array(' ', '-'), '_', $slug); if (!$method) { $slug = $method = 'index'; } $this->controller_slug = $slug; $this->controller_method = $method; $this->controller_name = $controller; $this->controller = _wpsc_load_controller($controller); if (!is_callable(array($this->controller, $method))) { trigger_error('Invalid controller method: ' . get_class($this->controller) . '::' . $method . '()', E_USER_ERROR); } do_action('wpsc_router_init'); $this->controller_args = $controller_args; if (is_callable(array($this->controller, '_pre_action'))) { call_user_func(array($this->controller, '_pre_action'), $method, $controller_args); } call_user_func_array(array($this->controller, $method), $controller_args); }