Installation:
composer require ekino/wordpress-bundle
Add to AppKernel.php:
new Ekino\WordpressBundle\EkinoWordpressBundle(),
Configure config.yml:
ekino_wordpress:
wordpress_root: "%kernel.root_dir%/../wordpress"
symfony_root: "%kernel.root_dir%"
First Use Case:
Inject the ekino_wordpress.wordpress service into a Symfony controller to interact with WordPress core:
use Ekino\WordpressBundle\Service\Wordpress;
class MyController extends Controller
{
public function indexAction(Wordpress $wp)
{
$posts = $wp->getPosts(['numberposts' => 5]);
return $this->render('my_template.html.twig', ['posts' => $posts]);
}
}
Verify Integration:
security.context.// src/Ekino/WordpressBundle/EventListener/WordpressListener.php
class WordpressListener
{
public function onWordpressInit(WordpressInitEvent $event)
{
$wp = $event->getWordpress();
$wp->addAction('wp_footer', function() {
echo '<script>console.log("Hello from Symfony!");</script>';
});
}
}
Register in services.yml:
services:
ekino_wordpress.listener.wordpress:
class: Ekino\WordpressBundle\EventListener\WordpressListener
tags:
- { name: kernel.event_listener, event: wordpress.init, method: onWordpressInit }
Doctrine to query WordPress tables (e.g., wp_posts):
$posts = $wp->getPosts(['posts_per_page' => 10]);
// Or via Doctrine:
$em = $this->getDoctrine()->getManager();
$posts = $em->getRepository('EkinoWordpressBundle:Post')->findAll();
Ekino\WordpressBundle\Entity\Post to map WordPress tables to Doctrine entities.// In a controller:
$user = $this->get('security.context')->getToken()->getUser();
// $user now includes WordPress roles (e.g., 'administrator', 'editor').
# app/config/routing.yml
my_wordpress_route:
path: /blog/{slug}
defaults: { _controller: MyBundle:Post:show }
requirements:
slug: \w+
public function showAction($slug, Wordpress $wp)
{
$post = $wp->getPost(['name' => $slug]);
return $this->render('post.html.twig', ['post' => $post]);
}
return $this->render('template.html.twig', [
'wp_posts' => $wp->getPosts(['numberposts' => 3]),
]);
{{ post.title|wp_title }}).Separate Environments:
wordpress_root and symfony_root in config to point to the correct paths.Caching:
DoctrineCache or Symfony\Component\HttpFoundation\Cache) to reduce database load:
$cache = $this->get('cache.app');
$posts = $cache->get('wp_posts', function() use ($wp) {
return $wp->getPosts(['numberposts' => 10]);
});
Asset Management:
assets_install in WordPress and linking to Symfony’s web/ directory.Media Handling:
Flysystem or VichUploaderBundle to manage WordPress uploads (e.g., wp-content/uploads) as Symfony files:
$adapter = new \League\Flysystem\Adapter\Local($wp->getUploadsDir());
$filesystem = new \League\Flysystem\Filesystem($adapter);
Debugging:
_profiler) and WordPress’s SAVEQUERIES to debug mixed queries:
define('SAVEQUERIES', true); // In wp-config.php
Archived Package:
Plugin Dependency:
ekino-wordpress-symfony plugin is required for authentication sync and event dispatching. Without it, features like role mapping and event listeners won’t work.Database Conflicts:
users). Avoid naming collisions by:
table option in entities.wp-config.php:
$table_prefix = 'wp_';
Session Incompatibility:
# config.yml
framework:
session:
handler_id: ~ # Use Symfony's default or configure a custom handler
Autoloading Issues:
vendor/ directory, autoloading conflicts may arise. Use separate composer.json files or vendor directories.Hook Timing:
init, wp_enqueue_scripts) run at specific times. Symfony events may not align perfectly. Test hook execution order with:
$wp->addAction('init', function() {
error_log('Symfony hook fired at ' . microtime(true));
});
Performance Overhead:
Enable WordPress Debugging:
Add to wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true); // Logs to /wp-content/debug.log
define('WP_DEBUG_DISPLAY', false);
Symfony + WordPress Logs:
app/logs/dev.log.wp-content/debug.log.Check Event Dispatching:
public function onKernelRequest(GetResponseEvent $event)
{
error_log('Symfony kernel request event fired');
}
Database Queries:
/_profiler) to inspect Doctrine queries.SAVEQUERIES and dump queries in a template:
global $wpdb;
error_log(print_r($wpdb->queries, true));
Authentication Debugging:
ekino-wordpress-symfony plugin is active in WordPress.$token = $this->get('security.context')->getToken();
error_log('User: ' . print_r($token->getUser(), true));
Ekino\WordpressBundle\Service\Wordpress class to add custom methods:
class CustomWordpress extends Word
How can I help you explore Laravel packages today?