0

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');
  • 3
    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 Sep 19 '14 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 Sep 19 '14 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 Sep 19 '14 at 14:26
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.