WordPress.org

Ready to get started?Download WordPress

Forums

Including pluggable.php within a plugin (4 posts)

  1. chrisull
    Member
    Posted 3 years ago #

    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!

  2. elfin
    Moderator
    Posted 3 years ago #

    if you add it to a hook, like init, then you don't need to do the include.

  3. Steve
    Member
    Posted 3 years ago #

    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

  4. chrisull
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.