Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.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
Wordpress-functions.php中的当前用户_Php_Wordpress - Fatal编程技术网

Wordpress-functions.php中的当前用户

Wordpress-functions.php中的当前用户,php,wordpress,Php,Wordpress,因此,我试图在wp-functions.php文件中运行一个简单的if语句,并使用current\u user\u can。然而,我得到了PHP错误,比如:“致命错误:调用未定义的函数current\u user\u can() 如果有人能看看我的代码,那将是非常感激的 我使用的代码如下: global $current_user_can; if ( current_user_can( 'manage_options' ) ) { /* A

因此,我试图在wp-functions.php文件中运行一个简单的if语句,并使用
current\u user\u can
。然而,我得到了PHP错误,比如:“致命错误:调用未定义的函数current\u user\u can()

如果有人能看看我的代码,那将是非常感激的

我使用的代码如下:

        global $current_user_can;
        if ( current_user_can( 'manage_options' ) ) {
            /* Admin User */

        } else {
            /* Member */
            echo "<p>something</p>"; 
}  
global$current\u user\u can;
如果(当前用户可以(“管理选项”)){
/*管理员用户*/
}否则{
/*成员*/
回声“某物””;
}  

如果要直接检查成员的角色,可以使用以下代码:

global $current_user;
get_currentuserinfo();

if( !in_array( 'administrator', $current_user->roles ) ) {
 //Do something
} else {
 //Do something else
}

这通常是因为pluggable.php由于某种原因没有加载。尝试在函数之前添加此项

if(!function_exists('wp_get_current_user')) { include(ABSPATH . "wp-includes/pluggable.php"); }

它只是检查是否加载了pluggable,如果没有加载,它就会包含它。

如果要创建插件,必须包含like

如果(!function_exists('wp_get_current_user')){include(ABSPATH.wp includes/pluggable.php);}//无需为主题函数添加
全局$current\u user\u can;
如果(!当前用户可以('管理选项')){
//你的东西在这里

}
谢谢您的回答,但我想设置一个函数,以便在用户是管理员时运行脚本,而不是在用户是其他人时运行脚本。如果有多个管理员,上面的代码会这样做吗?只需添加get_currentuserinfo();我得到了另一个错误:调用未定义函数get_currentuserinfo()。使用上述所有代码,我得到:调用未定义函数get_currentuserinfo()。我是否需要包含其他php文件?尝试将此添加到函数的顶部。php:
require\u('/wp包括/pluggable functions.php');