Example #1
0
 /**
  * Handle the admin_init action.  All page handling is done on admin_init
  * so we have the opportunity to run code prior to WP rendering any output.
  *
  * @param string $page The name of the page to route to (e.g. "Index" or "Edit").
  * @param Response $response Inject a response object, usually for tests.
  *
  * @param ComponentInterface $component
  * @param string|null $page
  * @param Response|null $response
  * @return ComponentInterface
  */
 public function adminInit(ComponentInterface $component, $page = null, Response $response = null)
 {
     if ($this->componentIsCurrentlyActive($component)) {
         $page = $component->createPageObject($component->getRequest()->getQuery('route', 'Index'));
         $this->enqueueClientSideDependencies($page->getView());
         if (null === $response) {
             $response = new Response();
         }
         if ($page) {
             $response->setPage($page);
             $this->output = $component->dispatchPage($page, $response);
             // If AJAX or non-layout response, render now to avoid WP shell mucking it up
             if ($component->getRequest()->isAjax() || !$component->shouldRenderLayout()) {
                 echo $this->output;
                 exit;
             }
         }
     }
     return $this;
 }