The MU forums have moved to WordPress.org

pluggable and wp_get_current_user (6 posts)

  1. SteveAtty
    Member
    Posted 12 years ago #

    I'm asking this here because the WP forums just have so much noise in them that things vanish.

    I've got a plugin which has at the top

    require_once(ABSPATH . WPINC . '/pluggable.php');

    Now I've been told that this is "bad" because if anyone has over riden any of the functions define in pluggable I'm trampling over them.

    But if I remove it I get:

    PHP Fatal error: Call to undefined function wp_get_current_user() in /webstuff/canalblogs/wp-includes/capabilities.php

    So what is the fix?

  2. SteveAtty
    Member
    Posted 12 years ago #

    Fixed it!

    I had

    if (current_user_can(WORDBOOKER_MINIMUM_ADMIN_LEVEL)) {
    	add_action('admin_menu', 'wordbook_admin_menu');
    }

    So if I change it to:

    add_action('admin_menu', 'wordbook_admin_menu');

    It all works

  3. DeannaS
    Member
    Posted 12 years ago #

    Fixed, but different functionality there. It's going to add the menu for everyone now....

  4. SteveAtty
    Member
    Posted 12 years ago #

    I know - I dont really mind if it does to be honest.

    But is there any way of getting round it without needing pluggable.php?

  5. DeannaS
    Member
    Posted 12 years ago #

    I think it depends where in your plugin you call it. You might have to do your check in a different place. Typically, it works if you do:

    add_action('admin_menu', 'wordbook_admin_menu');

    And then do

    function wordbook_admin_menu() {
       if (!current_user_can(WORDBOOKER_MINIMUM_ADMIN_LEVEL)) {
         wp_die("Hey, you're not allowed in here.");
       }
    }
  6. SteveAtty
    Member
    Posted 12 years ago #

    Now why didn't I think of that ... Think maybe I need to go out and get some fresh air!

    Thanks

About this Topic

  • Started 12 years ago by SteveAtty
  • Latest reply from SteveAtty