答案就在wp_get_current_user()
可插拔功能。我只是更改了函数名get_currentuserinfo()
到wp_get_current_uesr()
然后确保返回值不是布尔值,而是返回$current\\u user。
这似乎工作得很好,包括缓存等。
希望这能帮助其他人。
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;