Add MukadiWordpressBundle

This commit is contained in:
Olivier M. Mukadi
2018-05-11 00:06:34 +01:00
parent 9d77b57350
commit b9738a5bfb
17 changed files with 303 additions and 0 deletions
@@ -0,0 +1,3 @@
mukadi_wordpress:
table_prefix: "%env(WP_PREFIX)%"
wordpress_directory: '%kernel.project_dir%/%env(WP_DIR)%'
@@ -0,0 +1,34 @@
{
"bundles": {
"Mukadi\\WordpressBundle\\MukadiWordpressBundle": ["all"]
},
"copy-from-recipe": {
"config/": "%CONFIG_DIR%/",
"public/": "%PUBLIC_DIR%",
"wp/": "wp/",
"wp-cli.yml": "wp-cli.yml",
"wp-config.php": "wp-config.php",
"sf-wp-bootstrap.php": "sf-wp-bootstrap.php"
},
"env": {
"WP_PREFIX": "wp_",
"WP_THEME": "wp-blank",
"WP_DIR": "public",
"AUTH_KEY": "%generate(secret)%",
"SECURE_AUTH_KEY": "%generate(secret)%",
"LOGGED_IN_KEY": "%generate(secret)%",
"NONCE_KEY": "%generate(secret)%",
"AUTH_SALT": "%generate(secret)%",
"SECURE_AUTH_SALT": "%generate(secret)%",
"LOGGED_IN_SALT": "%generate(secret)%",
"NONCE_SALT": "%generate(secret)%"
},
"gitignore": [
"/public/wp-*/",
"/public/wp-*",
"/public/xmlrpc.php",
"/public/composer.json",
"/public/readme.html",
"/public/license.txt"
]
}
@@ -0,0 +1,7 @@
<bg=blue;fg=white> </>
<bg=blue;fg=white> What's next? </>
<bg=blue;fg=white> </>
* Add the WordpressBundle routing file in your `config/routes.yaml`, after your custom routes to catch all Wordpress routes.
* <fg=blue>Read</> the documentation at <comment>https://github.com/mbo2olivier/mukadi-wordpress-bundle</>
@@ -0,0 +1,22 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
@@ -0,0 +1,49 @@
<?php
use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
require __DIR__.'/../vendor/autoload.php';
function run(){
// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load(__DIR__.'/../.env');
}
$env = $_SERVER['APP_ENV'] ?? 'dev';
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));
if ($debug) {
umask(0000);
Debug::enable();
}
define('WP_DEBUG', $debug);
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts(explode(',', $trustedHosts));
}
$kernel = new Kernel($env, $debug);
# SF container in WP
$GLOBALS['sf'] = function ($id) use (&$kernel) {
return $kernel->getContainer()->get($id);
};
$kernelRequest = Request::createFromGlobals();
$kernelResponse = $kernel->handle($kernelRequest);
$kernelResponse->send();
$kernel->terminate($kernelRequest, $kernelResponse);
}
run();
@@ -0,0 +1,49 @@
<?php
use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
require __DIR__.'/../vendor/autoload.php';
function run(){
// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
if (!class_exists(Dotenv::class)) {
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}
(new Dotenv())->load(__DIR__.'/../.env');
}
$env = $_SERVER['APP_ENV'] ?? 'dev';
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));
if ($debug) {
umask(0000);
Debug::enable();
}
define('WP_DEBUG', $debug);
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts(explode(',', $trustedHosts));
}
$kernel = new Kernel($env, $debug);
# SF container in WP
$GLOBALS['sf'] = function ($id) use (&$kernel) {
return $kernel->getContainer()->get($id);
};
$kernelRequest = Request::createFromGlobals();
$kernelResponse = $kernel->handle($kernelRequest);
$kernelResponse->send();
$kernel->terminate($kernelRequest, $kernelResponse);
}
run();
+1
View File
@@ -0,0 +1 @@
path: public
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
require_once __DIR__.'/vendor/autoload.php';
$config = new \Mukadi\WordpressBundle\Config(
sprintf('%s/%s',realpath(__DIR__),env('WP_DIR', 'public'))
);
// 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');
@@ -0,0 +1,28 @@
<?php
/*
Plugin Name: Symfony Bridge
Plugin URI: http://www.consiidrc.net/
Description: For use symfony service in wordpress, and spread event trought symfony from wp.
Version: 0.0.1
Author: Olivier M. Mukadi
Author URI: http://www.consiidrc.net/
*/
/**
* retreive symfony service
*/
function symfony ($id){
global $sf;
return $sf($id);
}
function symfony_container_ready(){
return isset($GLOBALS['sf']);
}
/**
* dispatch event in symfony
*/
function symfony_dispatch($name, \Mukadi\WordpressBundle\Event\WordpressEvent $event)
{
if (!symfony_container_ready()) return;
return symfony('event_dispatcher')->dispatch($name, $event);
}
@@ -0,0 +1,2 @@
<?php
# nothing
@@ -0,0 +1,2 @@
<?php
# nothing
@@ -0,0 +1,3 @@
<?php wp_footer(); ?>
</body>
</html>
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
// Set theme defaults.
add_action('after_setup_theme', function () {
// Add post thumbnails support.
add_theme_support('post-thumbnails');
// Add title tag theme support.
add_theme_support('title-tag');
// Add HTML5 support.
add_theme_support('html5', [
'caption',
'comment-form',
'comment-list',
'gallery',
'search-form',
'widgets',
]);
register_nav_menu('main', __('Menu Principal','the_theme'));
});
// Enqueue and register scripts the right way.
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style( 'the_theme-style', get_stylesheet_uri(), array());
});
// Remove JPEG compression.
add_filter('jpeg_quality', function () {
return 100;
}, 10, 2);
// Set custom excerpt more.
add_filter('excerpt_more', function () {
return '...';
});
// Set custom excerpt length.
add_filter('excerpt_length', function () {
return 101;
});
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header>
<nav role="navigation">
<?php wp_nav_menu(['theme_location' => 'main']); ?>
</nav>
</header>
@@ -0,0 +1,19 @@
<?php get_header(); ?>
<main role="main">
<?php if (have_posts()): while (have_posts()): the_post(); ?>
<article>
<header>
<h1><?php the_title(); ?></h1>
</header>
<?php the_content(); ?>
</article>
<?php endwhile; else: ?>
<article>
<p>Nothing to see.</p>
</article>
<?php endif; ?>
</main>
<?php get_footer();
Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

@@ -0,0 +1,7 @@
/*
Theme Name: WPBlank
Author: Olivier M. Mukadi
Author URI: www.consiidrc.net
Version: 0.1.0
Description: Default theme, feel free to make or install your own.
*/