WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Call to undefined function wp_get_current_user()

[Resolved] Call to undefined function wp_get_current_user()

  • After updating to the latest BPS, on a multisite WP installation v. 3.5.1, admin pages immediately became unavailable, due to the following error:

    PHP Fatal error: Call to undefined function wp_get_current_user() in /home/apache/wordpress/wp-includes/capabilities.php on line 1451

    According to:
    https://wordpress.org/support/topic/plugin-post-from-site-fatal-error-undefined-function

    when this happens it is because wp-includes/pluggable.php contains this function, but this file is not getting loaded until after the plugins are loaded.

    I was able to fix the problem by adding:
    require_once(ABSPATH . ‘wp-includes/pluggable.php’);

    to /wp-content/plugins/bulletproof-security/bulletproof-security.php

    as soon as I added that line admin pages became accessible again and the error is no longer triggered.

    http://wordpress.org/extend/plugins/bulletproof-security/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author AITpro

    @aitpro

    Wierd. BPS does not use the wp_get_current_user() function. BPS does use the WordPress current_user_can() function to check user capabilities.

    Try commenting out the line you added below with 2 forward slashes and let me know if the error occurs again. It may have just been a coincidence or maybe there is some other factor that is not obvious going on.
    // require_once(ABSPATH . ‘wp-includes/pluggable.php’);

    Plugin Author AITpro

    @aitpro

    Did you Network Activate BPS on your Network/Multisite installation? BPS should not be Network Activated and should only be activated on the Primary site for Network/Multisite.

    Plugin Author AITpro

    @aitpro

    Oops yeah wp_get_current_user() is in capabilities and not BPS. Spaced out for a sec. LOL. Apparently this is some odd random occurrence that happens only on Mulitsite and I do not see that anyone has ever figured out what actually causes it. I will add this as it would not hurt anything, but I will need to research it fully before adding it. Thanks.

    Plugin Author AITpro

    @aitpro

    This has been researched and tested and everything works perfectly. Thank you for pointing this out. Very much appreciated.

    It was my pleasure, and many thanks for being so responsive, and for your work on this excellent plugin 🙂

    Look forward to the fix appearing soon, but if it doesn’t, no big deal, I have my ugly kludge patch. Here it is in case it helps any multisite people until the real fix is merged:

    --- a/wp-content/plugins/bulletproof-security/bulletproof-security.php  2013-04-17 23:11:09.640004664 +0100
    +++ b/wp-content/plugins/bulletproof-security/bulletproof-security.php  2013-04-17 23:10:30.610004665 +0100
    @@ -46,6 +46,7 @@
    
     // If in WP Admin Dashboard
     if ( is_admin() ) {
    +    require_once(ABSPATH . 'wp-includes/pluggable.php');
         require_once( WP_PLUGIN_DIR . '/bulletproof-security/admin/includes/admin.php' );
            register_activation_hook(__FILE__, 'bulletproof_security_install');
            register_deactivation_hook(__FILE__, 'bulletproof_security_deactivation');
    Plugin Author AITpro

    @aitpro

    adding just…

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

    …causes some problems for other plugins so this code will be changed to include this additional conditional check below…

    if ( is_admin() ) {
        require_once( WP_PLUGIN_DIR . '/bulletproof-security/admin/includes/admin.php' );
    	if ( wp_script_is( 'bps-js', $list = 'queue' ) ) {
    		require_once(ABSPATH . 'wp-includes/pluggable.php');
    	}

    Please test this code on your site and let me know if it works. Thanks.

    Plugin Author AITpro

    @aitpro

    Wow dumb one. Went down the rabbit hole looking in the wrong place. This is the correct solution to the problem.
    http://wordpress.org/support/topic/36-beta-issue?replies=3

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Call to undefined function wp_get_current_user()’ is closed to new replies.