[wp-trac] [WordPress Trac] #27208: Make add_filter and add_action available in wp-config.php

WordPress Trac noreply at wordpress.org
Tue Mar 4 13:26:38 UTC 2014


#27208: Make add_filter and add_action available in wp-config.php
-------------------------------+------------------------------
 Reporter:  Denis-de-Bernardy  |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Bootstrap/Load     |     Version:  3.8.1
 Severity:  normal             |  Resolution:
 Keywords:                     |     Focuses:
-------------------------------+------------------------------

Comment (by Denis-de-Bernardy):

 @nacin or sergey: any odds you could get `27208.4.diff` into 2.9? The only
 thing it does is change a `require` statement into a `require_once`
 statement, so as to allow developers to add WP filters prior to loading WP
 if needed.

 In case it matters, my use-case is the following:

 {{{
 # www/index.php
 $kernel = require __DIR__.'/../app/bootstrap.php';
 $request = Request::createFromGlobals();
 $response = $kernel->handle($request);

 if ($response instanceof WPResponse) {
     # Load WordPress in the global scope and
     # re-inject the response back into Symfony using an output buffer
     $response->bootstrap($kernel, $request);
     require __DIR__.'/wp/index.php';
 }
 else {
     # Let Symfony send the response and terminate normally
     $response->send();
     $kernel->terminate($request, $response);
 }
 }}}

 That method being:

 {{{
 # WordPressBundle\Component\Response class:
     /**
      * Sets up filters and post-processing needed to catch the WordPress
 output
      *
      * @param HttpKernelInterface $kernel
      * @param Request $request
      * @return Response $this
      */
     public function bootstrap(HttpKernelInterface $kernel, Request
 $request)
     {
         # Catch WP status header
 $GLOBALS['wp_filter']['status_header'][PHP_INT_MAX][__CLASS__.'::catchStatusCode']
 = array(
             'function' => array($this, 'catchStatusCode'),
             'accepted_args' => 4,
         );

         ...
     }
 }}}

 As you can see in the above, things would be more sensible with an
 `add_filter()` call.  I could admittedly require PHP 5.4 instead of PHP
 5.3, since the latter allows to catch the status code using a built-in
 function. But I can readily picture other scenarios where adding a filter
 here and there without needing to load WP in full might be useful.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27208#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list