undefined function wp_get_current_user

Home Forums Legacy Support Support queries How-to & Troubleshooting undefined function wp_get_current_user

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1445
    thexlearner
    Spectator
    Hello, When I try to remove some dashboard widgets for instructor using this code :
    
    // Create the function to use in the action hook
    function example_remove_dashboard_widget() {
    remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
    remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');//since 3.8
    remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
    }
    
    // Hook into the 'wp_dashboard_setup' action to register our function
    if (!current_user_can('manage_options')) {
    add_action('wp_dashboard_setup', 'example_remove_dashboard_widget' );
    }
    
    I get that :
    
    Fatal error: Call to undefined function wp_get_current_user() in /home/site/www/wplms/wp-includes/capabilities.php on line 1441
    
    #1538
    Anshuman Sahu
    Keymaster
    Please try your code like this : add_action('init','run_my_custom_function',99); function run_my_custom_function(){   //your code snippet here .   if (!current_user_can('manage_options')) { add_action('wp_dashboard_setup', 'example_remove_dashboard_widget' ); } } // Create the function to use in the action hook function example_remove_dashboard_widget() { remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');//since 3.8 remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );   }
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘undefined function wp_get_current_user’ is closed to new replies.