themes - current_user_can('manage_options') causes white screen of death?

The condition if(current_user_can('manage_options')) causes white screen of death, and for obvious reason I ca

The condition if(current_user_can('manage_options')) causes white screen of death, and for obvious reason I cannot track the error, and debugging didn't yield anything. I am pretty sure the condition is causing this behavior (when having if(true) everything works just fine). So where do I start to fix this?

If this might be helpful, I will post a plugin that contains the code (is fairly simple, used for changing a theme depending on privileges):

function change_theme($theme) {
    if ( current_user_can('manage_options') ) {
        $theme = 'theme1';
    } else {
        $theme = 'theme2';
    }

    return $theme;
}
add_filter('template', 'change_theme');
add_filter('option_template', 'change_theme');
add_filter('option_stylesheet', 'change_theme');

The condition if(current_user_can('manage_options')) causes white screen of death, and for obvious reason I cannot track the error, and debugging didn't yield anything. I am pretty sure the condition is causing this behavior (when having if(true) everything works just fine). So where do I start to fix this?

If this might be helpful, I will post a plugin that contains the code (is fairly simple, used for changing a theme depending on privileges):

function change_theme($theme) {
    if ( current_user_can('manage_options') ) {
        $theme = 'theme1';
    } else {
        $theme = 'theme2';
    }

    return $theme;
}
add_filter('template', 'change_theme');
add_filter('option_template', 'change_theme');
add_filter('option_stylesheet', 'change_theme');
Share Improve this question asked Sep 19, 2014 at 13:42 nakajuicenakajuice 1236 bronze badges 3
  • 4 You should activate the php error display from ini_set('display_errors', '1'); and WordPress error display in wp-config.php put define( 'WP_DEBUG', true );. Does it yield now? – aifrim Commented Sep 19, 2014 at 14:03
  • Thank you, setting display_errors to 1 has let me determine that for some reason wp-includes/pluggable.php was not included while running the plugin, so wp_get_current_user() function was missing. Although I didn't find the reason of malfunction, thanks to answer to this question I hardcoded plugin by setting if(!function_exists('wp_get_current_user')) { include(ABSPATH . "wp-includes/pluggable.php"); }, and now everything works fine. – nakajuice Commented Sep 19, 2014 at 14:24
  • Glad to be of service. Include that in your question so that people know you've solved it and answer it (there is a button below) – aifrim Commented Sep 19, 2014 at 14:26
Add a comment  | 

1 Answer 1

Reset to default 2

Setting display_errors to 1 has let me determine that for some reason wp-includes/pluggable.php was not included while running the plugin, so wp_get_current_user() function was missing. Although I didn't find the reason of malfunction, thanks to answer to this question I hardcoded plugin by setting following at the beginning:

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

Now everything works fine.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745134781a4613148.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信