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
|
1 Answer
Reset to default 2Setting 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
php
error display fromini_set('display_errors', '1');
and WordPress error display inwp-config.php
putdefine( 'WP_DEBUG', true );
. Does it yield now? – aifrim Commented Sep 19, 2014 at 14:03if(!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