Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将Wordpress功能作为服务提供商集成到Laravel中_Php_Wordpress_Laravel_Service Provider - Fatal编程技术网

Php 将Wordpress功能作为服务提供商集成到Laravel中

Php 将Wordpress功能作为服务提供商集成到Laravel中,php,wordpress,laravel,service-provider,Php,Wordpress,Laravel,Service Provider,我计划使用Laravel作为我的Wordpress插件的api。结构如下: - main-directory - Laravel-dir - WordPress-dir use File; use Illuminate\Support\ServiceProvider; class WordpressServiceProvider extends ServiceProvider { protected $bootstrapFilePath = '../../wp/wp-loa

我计划使用Laravel作为我的Wordpress插件的api。结构如下:

- main-directory
  - Laravel-dir
  - WordPress-dir
use File;
use Illuminate\Support\ServiceProvider;

class WordpressServiceProvider extends ServiceProvider
{

    protected $bootstrapFilePath = '../../wp/wp-load.php';

    public function boot()
    {
        wp_enqueue_style('app', '/app/public/app.css');
    }

    public function register()
    {
        if(File::exists($this->bootstrapFilePath)) {
            require_once $this->bootstrapFilePath;
        } else throw new \RuntimeException('Wordpress Bootstrap File Not Found');
    }
}
我已经为Laravel创建了Wordpress服务提供商,如下所示:

- main-directory
  - Laravel-dir
  - WordPress-dir
use File;
use Illuminate\Support\ServiceProvider;

class WordpressServiceProvider extends ServiceProvider
{

    protected $bootstrapFilePath = '../../wp/wp-load.php';

    public function boot()
    {
        wp_enqueue_style('app', '/app/public/app.css');
    }

    public function register()
    {
        if(File::exists($this->bootstrapFilePath)) {
            require_once $this->bootstrapFilePath;
        } else throw new \RuntimeException('Wordpress Bootstrap File Not Found');
    }
}
我还将其作为一个provider=>添加到了Laravel dir/config/app.php下:

现在,当有人访问其中一个Laravel页面时,我需要检查WordPress管理员用户是否已登录

跳到下面的“编辑”:我已尝试使用is_admin检查管理员用户。调用函数works并没有什么问题,所以我假设我的服务提供商可以工作,但尽管我以wp admin的身份登录,is_admin函数始终返回false

编辑:我意识到是_管理员检查页面是否是管理员页面。相反,我必须使用wp\u获取当前用户


我尝试在我的Wordpress插件中使用wp_get_current_user,它会返回所有管理员信息。但是,如果我在Laravel中使用它,它将返回空数组集。

is\u admin用于确定您是否在管理员页面上,而不是您是否是管理员用户


我自己也遇到过类似的问题。这个问题是由我的系统结构引起的

我让laravel在子域上运行,而wordpress在根域上运行。在这种情况下,您无法访问子域中的根域Cookie。为了解决这个问题,我将laravel安装移动到webroot的一个子目录中,wordpress安装在该目录中,并为nginx创建了一个重写规则,以便从www.yourdomain.com/laravel为laravel安装提供服务

您需要编辑/etc/nginx/sites available/yourdomain.com并添加,以便nginx从yourdomain.com/laravel为laravel安装服务:

location ^~ /laravel {
    alias /pat/to/laravel/public;
    try_files $uri $uri/ @laravel;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

location @laravel {
    rewrite /laravel/(.*)$ /laravel/index.php?/$1 last;
}

如果您正在使用apache,请查看

您是对的;我不得不使用wp_get_current_user而不是is_admin。但是,当我在Wordpress插件中使用wp_get_current_user时,它会返回信息,但是,如果我尝试在我的Laravel应用程序中使用wp_get_current_user,它返回空数组集,即使WP的函数变得可识别,并且不会崩溃或抱怨函数不存在。我也想实现这一点,我遇到了与senty相同的问题。它可能与wordpress/laravel structute或访问laravel的路径/url有关吗?“但是,如果我在laravel中使用它,它将返回空数组集”—可能是cookie问题?检查WP会话cookie设置的路径,以及它是否覆盖了您称为Laravel对象的URL路径。