在mu/目录中有一个格式正确的php函数文件。当尝试使用wp_is_mobile()或current_user_can()时,我会得到一个未定义的函数错误。
Fatal error: Call to undefined function wp_is_mobile() in /var/www/dev.example.com/public/wp-content/mu-plugins/multisite-functions.php on line 147某些核心功能是在mu之后定义的吗?我该如何解决或避免这个问题?我可以简单地不使用特定的功能,在mu插件?
谢谢!
发布于 2014-12-09 20:19:13
多亏了StackOverflow的diggy,我知道在WordPress循环中,文件vars.php (包含我需要的函数)是在muplugins_loaded执行后包含的。
包装器函数中包括wp_is_mobile()和current_user_can()解决了我的问题。
function my_epic_function() {
if(current_user_can( 'edit_posts' )) {
if(!wp_is_mobile()) {
//code to be executed
}
}
}
add_action('init', 'my_epic_function');function my_epic_function() {
//code to be executed
}
if(current_user_can( 'edit_posts' )) {
if(!wp_is_mobile()) {
add_action('init', 'my_epic_function');
}
}https://wordpress.stackexchange.com/questions/170741
复制相似问题