Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Wordpress Bundle Laravel Package

ekino/wordpress-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require ekino/wordpress-bundle
    

    Add to AppKernel.php:

    new Ekino\WordpressBundle\EkinoWordpressBundle(),
    
  2. Configure config.yml:

    ekino_wordpress:
        wordpress_root: "%kernel.root_dir%/../wordpress"
        symfony_root: "%kernel.root_dir%"
    
  3. 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]);
        }
    }
    
  4. Verify Integration:

    • Install the ekino-wordpress-symfony plugin in WordPress.
    • Test authentication sync by logging into WordPress and checking Symfony’s security.context.

Implementation Patterns

Core Workflows

1. Symfony Services in WordPress

  • Hook into WordPress with Symfony: Dispatch WordPress hooks as Symfony events. Example in a service:
    // 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 }
    

2. Database Manipulation

  • Use Symfony’s 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();
    
  • Custom Entities: Extend Ekino\WordpressBundle\Entity\Post to map WordPress tables to Doctrine entities.

3. Authentication Sync

  • After installing the plugin, WordPress users automatically log into Symfony with roles mapped from WordPress capabilities:
    // In a controller:
    $user = $this->get('security.context')->getToken()->getUser();
    // $user now includes WordPress roles (e.g., 'administrator', 'editor').
    

4. Custom Routes

  • Create Symfony routes that interact with WordPress data:
    # app/config/routing.yml
    my_wordpress_route:
        path:     /blog/{slug}
        defaults: { _controller: MyBundle:Post:show }
        requirements:
            slug: \w+
    
  • Fetch WordPress posts in the controller:
    public function showAction($slug, Wordpress $wp)
    {
        $post = $wp->getPost(['name' => $slug]);
        return $this->render('post.html.twig', ['post' => $post]);
    }
    

5. Twig Integration

  • Pass WordPress data to Twig templates:
    return $this->render('template.html.twig', [
        'wp_posts' => $wp->getPosts(['numberposts' => 3]),
    ]);
    
  • Use Twig filters/extensions to format WordPress data (e.g., {{ post.title|wp_title }}).

Integration Tips

  1. Separate Environments:

    • Keep WordPress and Symfony in separate directories (as per the README) to avoid conflicts. Use wordpress_root and symfony_root in config to point to the correct paths.
  2. Caching:

    • Cache WordPress queries in Symfony (e.g., using 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]);
      });
      
  3. Asset Management:

    • Serve Symfony assets (CSS/JS) from WordPress by configuring assets_install in WordPress and linking to Symfony’s web/ directory.
  4. Media Handling:

    • Use Symfony’s 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);
      
  5. Debugging:

    • Enable Symfony’s profiler (_profiler) and WordPress’s SAVEQUERIES to debug mixed queries:
      define('SAVEQUERIES', true); // In wp-config.php
      

Gotchas and Tips

Pitfalls

  1. Archived Package:

    • The bundle is archived (last release in 2015). Expect no updates or compatibility fixes for modern Laravel/Symfony (5.4+). Use at your own risk or fork it.
  2. Plugin Dependency:

    • The ekino-wordpress-symfony plugin is required for authentication sync and event dispatching. Without it, features like role mapping and event listeners won’t work.
  3. Database Conflicts:

    • WordPress and Symfony may use the same database tables (e.g., users). Avoid naming collisions by:
      • Using Doctrine’s table option in entities.
      • Prefixing WordPress tables in wp-config.php:
        $table_prefix = 'wp_';
        
  4. Session Incompatibility:

    • WordPress and Symfony may use different session backends. Configure Symfony’s session handler to match WordPress’s (e.g., database or file-based):
      # config.yml
      framework:
          session:
              handler_id: ~ # Use Symfony's default or configure a custom handler
      
  5. Autoloading Issues:

    • If WordPress and Symfony share a vendor/ directory, autoloading conflicts may arise. Use separate composer.json files or vendor directories.
  6. Hook Timing:

    • WordPress hooks (e.g., 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));
      });
      
  7. Performance Overhead:

    • Loading both WordPress and Symfony in the same request can be slow. Optimize by:
      • Lazy-loading WordPress only when needed (e.g., in specific routes).
      • Using Symfony’s HTTP cache for static WordPress content.

Debugging Tips

  1. 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);
    
  2. Symfony + WordPress Logs:

    • Symfony logs: app/logs/dev.log.
    • WordPress logs: wp-content/debug.log.
    • Cross-reference timestamps to correlate issues.
  3. Check Event Dispatching:

    • Verify Symfony events are firing by adding a listener:
      public function onKernelRequest(GetResponseEvent $event)
      {
          error_log('Symfony kernel request event fired');
      }
      
  4. Database Queries:

    • Use Symfony’s profiler (/_profiler) to inspect Doctrine queries.
    • Enable WordPress’s SAVEQUERIES and dump queries in a template:
      global $wpdb;
      error_log(print_r($wpdb->queries, true));
      
  5. Authentication Debugging:

    • Check if the ekino-wordpress-symfony plugin is active in WordPress.
    • Verify Symfony’s security context:
      $token = $this->get('security.context')->getToken();
      error_log('User: ' . print_r($token->getUser(), true));
      

Extension Points

  1. Custom WordPress Services:
    • Extend the Ekino\WordpressBundle\Service\Wordpress class to add custom methods:
      class CustomWordpress extends Word
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui