Fatal error: Call to undefined function wp_get_current_user()

wp_get_current_user() is a pluggable function and not yet available when your plugin is included. You have to wait for the action plugins_loaded:

Example:

add_action( 'plugins_loaded', 'wpse_92517_init' );

function wpse_92517_init()
{
    if(!is_super_admin())
        add_action('widgets_init','my_unregister_widget');
}

function my_unregister_widgets() {
    unregister_widget( 'WP_Widget_Pages' );
    unregister_widget( 'WP_Widget_Calendar' );
}

Or move the check into the widget function:

add_action( 'widgets_init', 'my_unregister_widget' );

function my_unregister_widgets() 
{
    if ( is_super_admin() )
        return;

    // not super admin
    unregister_widget( 'WP_Widget_Pages' );
    unregister_widget( 'WP_Widget_Calendar' );
}

Leave a Comment