• Hey all,

    Got an odd error going on at the moment –

    I have a plugin that uses the following code –

    if(current_user_can('manage_options')){
    	add_action('admin_menu', 'add_dd_options_menu');
    	add_action('admin_head', 'dd_options_header');
    }

    But this plugin generates this error –

    Fatal error: Call to undefined function wp_get_current_user() in C:\wamp\www\website\test\wp-includes\capabilities.php on line 1059

    Changing it to the below so that I am not checking capabilities works fine –

    //if(current_user_can('manage_options')){
    	add_action('admin_menu', 'add_dd_options_menu');
    	add_action('admin_head', 'dd_options_header');
    //}

    But the strangest thing is that this statement in a different file works fine, even when checking capabilities –

    if(current_user_can('manage_options')){
    	require_once('dd_includes/dashboard_widgets.php');
    	add_action('admin_menu', 'remove_rubbish_dashboard_boxes');
    }

    Does anybody know if I am missing anything, or if i have made a very silly mistake with the code?

    Any help apprciated.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’ve ran into similar problems in the past. I think that this happens because (in the first instance) you are using current_user_can() before all appropriate files have been loaded. I’m guessing that the “code in another file” is hooked into WordPress at a later time in script execution. I try to hook everything at wp_loaded or later if possible.

    Try by adding require_once(‘pluggable.php’);

    Thread Starter David Gard

    (@duck_boy)

    Thanks Gisha, that does work, supporting Michaels suggestion that not all the files have been called when that plugin is being loaded. Not sure why though, as I have another pluging that is based on the same template (obv calls different functions) and that works just fine.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Fatal error: Call to undefined function wp_get_current_user’ is closed to new replies.