WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As of about 10 days ago, WordPress 4.5 developers deprecated get_currentuserinfo() as a pluggable function. Unfortunately my plugin uses it's own get_currentuserinfo() to login users from an external database.

This is going to require a rewrite of that area of the plugin for WP 4.5 compatibility.

Since I'm not the only one with a bridge using this function, what direction should bridge developers take?

share|improve this question
    
what kind of bridge, what is it that you do in that function? – Mark Kaplun Jan 25 at 5:48
    
It's the login function. It is resolved now by using wp_get_current_user() and will post the solution. – LPH Jan 25 at 6:20
up vote 6 down vote accepted

The answer lies within the wp_get_current_user() pluggable function. I simply changed the function name get_currentuserinfo() to wp_get_current_uesr() then made sure the returns were not boolean but return $current_user.

This seems to be working well, including caching, etc.

Hopefully this helps others.

if ( ! function_exists( 'wp_get_current_user' ) ) :

/**
 * This replacement function will no longer work after WordPress 4.5
 * The pluggable function was deprecated in WP 4.5
 *
 * @return void|boolean
 *
 * @since 2.5.1.03
 *        Added apply_filter to match WP get_currentuserinfo()
 *
 * @since 3.0.2.01
 *        wp_get_current_user instead of get_currentuserinfo()
 */

function wp_get_current_user() {
    global $current_user;

    if ( ! empty( $current_user ) ) {
        if ( $current_user instanceof WP_User ) {
            return $current_user;
        }

        // Upgrade stdClass to WP_User
        if ( is_object( $current_user ) && isset( $current_user->ID ) ) {
            $cur_id       = $current_user->ID;
            $current_user = null;
            wp_set_current_user( $cur_id );
            return $current_user;
        }

        // $current_user has a junk value. Force to WP_User with ID 0.
        $current_user = null;
        wp_set_current_user( 0 );
        return $current_user;
    }

    if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
        wp_set_current_user( 0 );
        return $current_user;
    }

    $visitor = XenWord::getVisitor();

    $user_id = $visitor['user_id'];

    // Conditional for no XenForo user is logged in
    if ( $user_id == 0 ) {
        $current_user = null;
        wp_set_current_user( 0 );
        return $current_user;
    }

    /**
     * Filter the current user.
     *
     * The default filters use this to determine the current user from the
     * request's cookies, if available.
     *
     * Returning a value of false will effectively short-circuit setting
     * the current user.
     *
     * @since 3.9.0
     *
     * @param int|bool $user_id User ID if one has been determined, false otherwise.
     */
    $user_id = apply_filters( 'determine_current_user', false );
    if ( ! $user_id ) {
        wp_set_current_user( 0 );
        return $current_user;
    }

    $current_user = get_userdata( $user_id );

    wp_set_current_user( $user_id );

    wp_validate_auth_cookie($cookie = '', $scheme = '');

    // Check to determine if adding XF users to WP database
    XenWord_XF_Users::check_options();

    return $current_user;
}

endif;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.