Forums

Post From Site
Fatal error: undefined function (7 posts)

  1. eliwagar
    Member
    Posted 1 year ago #

    Hi, when activating the plugin I keep getting this error:

    Fatal error: Call to undefined function wp_get_current_user() in /home1/meincont/public_html/wp-includes/capabilities.php on line 1059

    I am running WP 3.1 with Mulltisites....

    Can somebody provide a fix?

  2. pascoa341
    Member
    Posted 1 year ago #

    Same Error here, only my fatal error is in capabilities.php on line 590. Does anyone know how to fix this?

  3. chrisull
    Member
    Posted 1 year ago #

    Hi there,

    In short, the plugin is trying to look and see what level the logged-in user is. It'll find that information in capabilities.php but it needs to use a function to do that (that function is wp_get_current_user().

    Plugin code fires in WordPress before this function is defined, so, your plugin breaks upon not knowing what wp_get_current_user() is.

    A workaround is to define that function within the plugin. You can do this by including pluggable.php, the file where these kinds of functions are.

    So insert this line near the top of your plugin:

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

  4. ZooFusion
    Member
    Posted 1 year ago #

    Hi Chrisull,

    Thank you for posting this clear explanation and fix! After nearly pulling my hair out for an hour or two, I have finally stumbled across this workaround and am able to get my current project working again.

    Many thanks!

  5. Cristiano
    Member
    Posted 1 year ago #

    What do I need to do if I want to check the user Role instead of the user level?

    Because I´m using custom roles and want to publish content in diferent post types, according to the role the user has...

  6. chrisull
    Member
    Posted 1 year ago #

    Cristiano, I don't think you can get the user role. A better way would probably be to check if the user can perform a certain task according to their role's capabilities.

    Use if current_user_can( 'capability_name' ) and use this list of capabilities:

    http://codex.wordpress.org/Roles_and_Capabilities

  7. jnorion
    Member
    Posted 1 year ago #

    I had this same problem, and the include posted above fixed it for me as well. I'm concerned about future updates breaking it, though. Can this be brought to the developer's attention so it can be fixed in the future? Or is there something unusual about my installation (and those few above) that's causing a problem where there wouldn't otherwise be one?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic