首页 > 解决方案 > 如何在 Laravel 中的文件夹外使用 Worpress 会话

问题描述

我在从 WordPress 获取 Laravel 中的当前用户登录详细信息时遇到了麻烦

我的目录结构

/public_html/
/public_html/ here is all Laravel files like app, route, resources etc. 
/public_html/shop/ here is the all WordPress Files 

我正在使用服务提供程序来加载 wp-load.php 文件但是当我通过我调用它时出现错误,即 Cannot redeclare __() (previously declared in /public_html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:851)

WordPress服务提供者

<?php
 
namespace App\Providers;
 
use Illuminate\Support\ServiceProvider;
use URL;
 
class WordPressServiceProvider extends ServiceProvider
{
 
    /**
     * Path to our WP installation
     *
     * @var string
     */
    protected $bootstrapFilePath = '..\shop\wp-load.php';   
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        
        
        //echo 'SESSION => '.is_user_logged_in();
        /**
         * Here we can enqueue any extra scripts or styles we may need. 
         * I loaded my frontend specific styles and scripts that were of no use to the WP site
         */
        //wp_enqueue_style('frontend-styles', URL::asset('css/frontend.css'), ['dependencies'], false);
        //wp_enqueue_script('frontend-scripts', URL::asset('js/frontend.js'), ['dependencies'], false, true);
    }
 
    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {   
        if(\File::exists($this->bootstrapFilePath)) {
            //echo 'INSIDE REGISTER';
            require_once($this->bootstrapFilePath);
        }else{
            //echo 'OUTSIDE REGISTER'.$this->bootstrapFilePath;         
        }
    }
}

标签: laravelwordpress

解决方案


推荐阅读