Support » Plugins » Including pluggable.php within a plugin

  • Hi there,

    I’ve been trying to develop a plugin that only initializes its functions if the user is NOT the admin. So to do that I write this:

    if (current_user_can('manage_options')) {
       $is_this_the_admin = true;

    Of course I get the error, “Call to undefined function: wp_get_current_user()” because wp_get_current_user() is not defined yet because it’s a pluggable function. Including pluggable.php is a common workaround that I’ve seen used quite often.

    My question is, is it okay to include the pluggable functions within a plugin, like this?

    include_once(ABSPATH . 'wp-includes/pluggable.php');

    I’ll be using this plugin every day, so I wouldn’t want to create any future problems by including pluggable.php twice.

    Thanks a lot!

Viewing 3 replies - 1 through 3 (of 3 total)
  • if you add it to a hook, like init, then you don’t need to do the include.

    Oddly enough I’ve had users saying that they still get this error from time to time – it seems to happen at random.

    The way a lot of people are fixing it is to add the include into capabilities.php

    Rich, can you explain a bit about using the init hook or share some documentation? Many thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Including pluggable.php within a plugin’ is closed to new replies.