kayue/WordpressBundle — Issue #4: Make bootstrapping Wordpress optional (if already loaded) 
Author: kayue
Created: 2011-12-23 04:49:56+00:00
State: open

Currently WordpressBundle will force the Symfony app to load ```wp-load.php``` to make ```wp_get_current_user()``` available, however this is not needed if Symfony app is loaded *within* a Wordpress.

I have already figured out a way to initiate a Symfony app within a Wordpress theme (or plugin). Simply place the following code to the top of a Wordpress theme's functions.php :

loadClassCache();

if('Not Found' === substr($status,strlen('Not Found') * -1)) {
$response = $kernel->handle(Request::createFromGlobals());

if(404 !== $response->getStatusCode()) {
// Send the page from Silex.
$response->send();

// We have got what we want. Exit from Wordpress.
exit();
}
}

return $status;
});

This way we can use most of the template function (if not all) in Symfony.

I have created a Wordpress Twig extension (https://github.com/kayue/WordpressBundle/blob/master/Extensions/WordpressTwigExtension.php).