• narendrans

    (@narendrans)


    I am developing a plugin, the code is like below,

    if (!current_user_can('administrator')){
    function hide_post_page_options() {
    //global $post;
    // Set the display css property to none for add category and add tag functions
    $hide_post_options = "<style type=\"text/css\"> .jaxtag { display: none; } #category-adder { display: none; } </style>";
    print($hide_post_options);
    }
    add_action( 'admin_head', 'hide_post_page_options'  );
    }

    But I get Fatal error: Call to undefined function wp_get_current_user(). I saw in a post that including pluggable.php in capabilities.php will and it did solve. But I don’t want to edit core files as it may cause concerns later on. Is there any way to do this without modifying core files?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Yes, never alter core files to get a plugin to work. When your plugin loads, WP is not fully loaded yet. This sort of code needs to be called from an action such as ‘init’ that fires once WP has fully loaded.

    Also, passing user roles to current_user_can() is poor practice. Even if it works now, it may soon lead to unpredictable behavior. Instead, pass an actual capability that’s related to the task at hand. Perhaps ‘edit_posts’ or ‘publish_posts’ will work for this?

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