All Projects → mbo2olivier → mukadi-wordpress-bundle

mbo2olivier / mukadi-wordpress-bundle

Licence: other
Integrate wordpress and symfony in the same application

Programming Languages

PHP
23972 projects - #3 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to mukadi-wordpress-bundle

Sonata Doctrine Extensions
Doctrine2 behavioral extensions
Stars: ✭ 239 (+895.83%)
Mutual labels:  doctrine
rector-doctrine
Rector upgrades rules for Doctrine
Stars: ✭ 37 (+54.17%)
Mutual labels:  doctrine
Lumen-Doctrine-DDD-Example
Domain Driven Design Application Example, built with Lumen 5.3 and Doctrine.
Stars: ✭ 72 (+200%)
Mutual labels:  doctrine
auditor
auditor, the missing audit log library
Stars: ✭ 105 (+337.5%)
Mutual labels:  doctrine
DoctrineBehaviors
[DEPRECATED]
Stars: ✭ 11 (-54.17%)
Mutual labels:  doctrine
petstore
A simple skeleton to build api's based on the chubbyphp-framework, mezzio (former zend-expressive) or slim.
Stars: ✭ 34 (+41.67%)
Mutual labels:  doctrine
Datagrid
💪 DataGrid for Nette Framework: filtering, sorting, pagination, tree view, table view, translator, etc
Stars: ✭ 224 (+833.33%)
Mutual labels:  doctrine
dbal-rds-data
A driver to use the aws aurora serverless rds data api in the doctrine database abstraction layer
Stars: ✭ 24 (+0%)
Mutual labels:  doctrine
doctrine-extensions
Doctrine2 behavioral extension Transformable
Stars: ✭ 14 (-41.67%)
Mutual labels:  doctrine
domain
A dependency-free package to help building a business domain layer
Stars: ✭ 33 (+37.5%)
Mutual labels:  doctrine
railt.org
A website
Stars: ✭ 23 (-4.17%)
Mutual labels:  doctrine
doctrine-phpstorm-meta
PhpStorm meta data for expected arguments completion.
Stars: ✭ 35 (+45.83%)
Mutual labels:  doctrine
slim-doctrine
Slim-Doctrine managers integration
Stars: ✭ 16 (-33.33%)
Mutual labels:  doctrine
Core
🧿 Bolt 4 core
Stars: ✭ 243 (+912.5%)
Mutual labels:  doctrine
php-orm-benchmark
The benchmark to compare performance of PHP ORM solutions.
Stars: ✭ 82 (+241.67%)
Mutual labels:  doctrine
Doctrine Bridge
Provides integration for Doctrine with various Symfony components.
Stars: ✭ 2,800 (+11566.67%)
Mutual labels:  doctrine
nette-oauth2-server-doctrine
Integration of The League of Extraordinary Packages' OAuth 2.0 Server into Nette Framework- Kdyby/Doctrine storage implementation
Stars: ✭ 13 (-45.83%)
Mutual labels:  doctrine
ErrorHeroModule
💎 A Hero for your Zend Framework/Laminas, and Expressive/Mezzio application to log ( DB and Mail ) and handle php errors & exceptions during Mvc process/between request and response
Stars: ✭ 47 (+95.83%)
Mutual labels:  doctrine
DoctrineTranslated
Translated strings for Doctrine
Stars: ✭ 12 (-50%)
Mutual labels:  doctrine
wp-router
Enables developers to easily create custom routes with matching templates accordingly.
Stars: ✭ 22 (-8.33%)
Mutual labels:  wordpress-routes

MukadiWordpressBundle

This is a fork of EkinoWordpressbundle, this bundle adapt EkinoWordpressBundle to symfony >= 4 new architecture and features. Some features has been removed (such as automatic symfony authentication when authenticated in Wordpress...) and will be reintegrated as separated bundle to install if needed.

Here are some retained features:

  • Use custom Symfony services into Wordpress (note: only public services),
  • Use Symfony to manipulate Wordpress database,
  • Create custom Symfony routes out of Wordpress,
  • Dispatch Event from Wordpress into Symfony *(require mukadi-symfony-bridge Wordpress plugin)

Installation

Before install the bundle, edit your composer.json file and specify the following options:

"extra": {
    ...
    "symfony": {
        ...
        "allow-contrib": "true" # allow symfony flex to install recipe (if your are using symfony flex)
    }
    ...
    # set installation path for wordpress themes and plugins
    "installer-paths": {
        "public/mu-plugins/{$name}": ["type:wordpress-muplugin"],
        "public/plugins/{$name}": ["type:wordpress-plugin"],
        "public/themes/{$name}": ["type:wordpress-theme"]
    },
    # install wordpress in a public sub-directory
    "wordpress-install-dir": "public/wp"
},

Run php composer.phar require mukadi/wordpress-bundle and let Symfony Flex configure the bundle.

Bundle configuration

If your are not using symfony flex, you have to configure manually your bundle, here is the minimal bundle configuration:

mukadi_wordpress:
    table_prefix: "%env(WP_PREFIX)%"
    wordpress_directory: '%kernel.project_dir%/public/%env(WP_DIR)%'

Add a public/wp-config.php file

Put the following content in your public/wp-config.php file :

declare(strict_types=1);

require_once __DIR__.'/../vendor/autoload.php';

$config = new \Mukadi\WordpressBundle\Config(
    realpath(__DIR__)
);

// define('WP_ALLOW_MULTISITE', env('WP_ALLOW_MULTISITE', true));

$table_prefix = env('WP_PREFIX', 'wp_');

/* That's all, stop editing! Happy blogging. */
$config->apply();
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Update the public/index.php file

If you don't make modifications in your public/index.php file you can just copy the content of the generated 'sf-wp-bootstrap.php' (see the code below) into your index.php file, otherwise update your index.php accordingly to that file.

Here's what your index.php file should look like:

use App\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__).'/config/bootstrap.php';

function run(){
    if ($_SERVER['APP_DEBUG']) {
        umask(0000);

        Debug::enable();
    }

    # setup WP_DEBUG
    $env = $_SERVER['APP_ENV'] ?? 'dev';
    $debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));
    define('WP_DEBUG', $debug);
    if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
        Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
    }

    if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
        Request::setTrustedHosts([$trustedHosts]);
    }

    $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
    # inject SF container in WP
    $GLOBALS['sf'] = function ($id) use (&$kernel) {
        return $kernel->getContainer()->get($id);
    };
    $request = Request::createFromGlobals();
    $response = $kernel->handle($request);
    $response->send();
    $kernel->terminate($request, $response);
}
run();

Add Wordpress routing into symfony

Add the WordpressBundle routing file in your config/routes.yaml, after your custom routes to catch all Wordpress routes:

...
mukadi_wordpress:
    resource: "@MukadiWordpressBundle/Resources/config/routing.xml"

Install Wordpress Plugins via Composer

Edit your composer.json file to add a custom repository:

...
"repositories": [
    {
        "type": "composer",
        "url": "https://wpackagist.org"
    }
]

Now you can install wordpress plugins, just run php composer.phar require wpackagist-plugin/<the-plugin-name>.

Avoid Doctrine remove custom Wordpress tables

When you install plugins in Wordpress, plugin can create custom tables to store specific data. By default such tables will be removed by the doctrine:migrations:diff command. You must configure doctrine/dbal to ignore those tables, just have to add the following configuration option to your doctrine configuration:

...
doctrine:
    dbal:
        schema_filter: '~^(?!%env(WP_PREFIX)%)~'

Manipulate Wordpress database in Symfony

You can call Wordpress table managers in Symfony by calling the following services:

Service identifier Type
mukadi_wordpress.manager.comment Wordpress comment manager
mukadi_wordpress.manager.comment_meta Wordpress comment metas manager
mukadi_wordpress.manager.link Wordpress link manager
mukadi_wordpress.manager.option Wordpress option manager
mukadi_wordpress.manager.post Wordpress post manager
mukadi_wordpress.manager.post_meta Wordpress post metas manager
mukadi_wordpress.manager.term Wordpress term manager
mukadi_wordpress.manager.term_relationships Wordpress term relationships manager
mukadi_wordpress.manager.term_taxonomy Wordpress taxonomy manager
mukadi_wordpress.manager.user Wordpress user manager
mukadi_wordpress.manager.user_meta Wordpress user metas manager

All of this services extends the Mukadi\Doctrine\CRUD\CRUD class, so see the documentation to know how to deal with it.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].