metabolism / wordpress-bundle

Use Wordpress and Symfony together using a Symfony bundle
MIT License
62 stars 17 forks source link
bundle composer dotenv symfony symfony-bundle wordpress wordpress-bundle wordpress-development yml

Symfony WordPress Bundle

Build enterprise solutions with WordPress.

Latest Stable Version Total Downloads Latest Unstable Version License Buy us a tree Doc - Gitbook

The Symfony WordPress Backoffice Bundle is a powerful library that seamlessly combines the flexibility of Symfony, a robust PHP framework, with the user-friendliness of WordPress, a popular content management system (CMS).

This bundle enables you to harness Symfony's structure to develop highly customized web applications while using WordPress as the backend for content management. It simplifies the integration of WordPress into your Symfony project, allowing you to leverage the best of both worlds.

How does it work ?

When the WordPress bundle is loaded, it selectively includes the essential WordPress Core files required for utilizing WordPress functions and plugins within Symfony.

Example :

// src/Controller/BlogController.php

/**
 * @param Post $post
 * @param PostRepository $postRepository
 * @return Response
 */
public function pageAction(Post $post, PostRepository $postRepository)
{
    $context = [];

    // get current post
    $context['post'] = $post;

    // find 10 "guide" ordered by title
    $context['guides'] = $postRepository->findBy(['post_type'=>'guide'], ['title'=>'ASC'], 10);

    return $this->render('page.html.twig', $context);
}
{# templates/page.html.twig #}

{% extends 'layout.html.twig' %}

{% block body %}
<article id="post-{{ post.ID }}" class="entry {{ post.class }}">

    {% if post.thumbnail %}
        <img src="https://github.com/metabolism/wordpress-bundle/raw/2.3.x/{{ post.thumbnail|resize(800, 600) }}" alt="{{ post.thumbnail.alt }}"/>
    {% endif %}

    <div class="entry-content">

        {{ post.content|raw }}

        {# or #}

        {% for block in post.blocks %}
            {% include 'block/'~block.name~'.html.twig' %}
        {% endfor %}
    </div>

    <small>{{ post.custom_fields.mention }}</small>

    {% for guide in guides %}
        {% include 'guide.html.twig' with {props:guide} %}
    {% endfor %}

</article>
{% endblock body %}

Documentation

Changelog

Please see Changelog for more information on what has changed recently.

Features

Using Composer :

Using Symfony :

Using WordPress Bundle :

Using WP Steroids WordPress plugin :

YML file allows to configure :

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Creating a new project

$ composer create-project metabolism/wordpress-skeleton my_project_directory

Please read the full bundle installation guide to continue

Setting up an existing Symfony project

Define installation path for WordPress core and plugins in composer.json

"extra": {
    "installer-paths": {
        "public/wp-bundle/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
        "public/wp-bundle/plugins/{$name}/": ["type:wordpress-plugin"],
        "public/wp-bundle/themes/{$name}/": ["type:wordpress-theme"],
        "public/edition/": ["type:wordpress-core"]
    }
}

Install the bundle

$ composer require metabolism/wordpress-bundle

For applications that don't use Symfony Flex

Register the bundle

// config/bundles.php

return [
    // ...
    Metabolism\WordPressBundle\WordPressBundle::class => ['all' => true],
];

Please read the full bundle installation guide to continue

Demo

https://github.com/metabolism/wordpress-bundle-demo

This is an implementation of the Twenty Nineteen WordPress theme for wordpress-bundle.

Screenshot from 2021-05-03 10-08-22

Recommended / tested plugins

Roadmap

Drawbacks

WordPress' functions are available in the global namespace.

Some WordPress plugins may not work ( ex : Woocommerce ) or require extra works.

Treeware

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

License

The MIT License (MIT). Please see License File for more information.