2

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);
        }
    }

}
Raunak Gupta
  • 10,412
  • 3
  • 58
  • 97
Marco Cazzaro
  • 661
  • 8
  • 13
  • 3
    Well if you try and include code of the one system into the other, I would not call that “running independently”. And there isn’t much you can do about that, except modifying the code of one or the other. I would recommend that you use the WordPress Rest API to have your Laravel communicate with your WP, instead of basically just throwing their code bases together and hope for the best, as you have been doing up to now. – CBroe Feb 09 '17 at 12:19
  • @CBroe Using the WordPress Rest API would generate at least one additional request, right? I wanted to avoid this, and the only other way was accessing the database directly. Am I at a dead end? – Marco Cazzaro Feb 09 '17 at 21:16

2 Answers2

0

You can include wp-load.php before vendor/autoload.php in bootstrap/autoload.php

Dim Zh
  • 1
0

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
Marco Cazzaro
  • 661
  • 8
  • 13