Search code examples
phpwordpressrequire-oncelaravel-5.4

Laravel 5.4 and WordPress 4.7 conflict in helper function __()


I am developing a website using Laravel, with a WordPress Blog section running in parallel and independently.
Since Laravel 5.3 everything run smoothly, using a Service Provider I was able to include 'wp-load.php' with a require_once() call and use all WordPress function out of the box and get/update WordPress posts.
Unfortunately, in Laravel 5.4 the helper function __() has been defined and this generates a conflict with the same WP function declared in l10n.php.
I tried using namespaces but with no luck.
This is the code of my Service Provider:

<?php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class WordPressServiceProvider extends ServiceProvider
{

    /**
     * Path to our WP installation
     *
     * @var string
     */
    protected $bootstrapFilePath = '/wp-paths/wp-it-news/wp-load.php';

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        if (\File::exists(public_path() . $this->bootstrapFilePath))
        {
            require_once(public_path() . $this->bootstrapFilePath);
        }
    }

}

Solution

  • I ended up using WordPress API, as Cbroe suggested.

    Docs here

    curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/posts