WordPress 4.5 không dùng nữa get_cienuserinfo ()


7

Kể từ khoảng 10 ngày trước, các nhà phát triển WordPress 4.5 không chấp nhận get_cienuserinfo () là một chức năng có thể cắm được. Thật không may, plugin của tôi sử dụng get_civerseuserinfo () của riêng nó để đăng nhập người dùng từ cơ sở dữ liệu bên ngoài.

Điều này sẽ yêu cầu viết lại khu vực đó của plugin để tương thích với WP 4.5.

Vì tôi không phải là người duy nhất có cây cầu sử dụng chức năng này, nên các nhà phát triển cầu nên đi theo hướng nào?


Loại cầu nào, bạn làm gì trong chức năng đó?
Đánh dấu Kaplun

Đó là chức năng đăng nhập. Nó được giải quyết ngay bây giờ bằng cách sử dụng wp_get_current_user()và sẽ đăng giải pháp.
LPH

Câu trả lời:


6

Câu trả lời nằm trong wp_get_current_user()chức năng cắm được. Tôi chỉ đơn giản là thay đổi tên hàm get_currentuserinfo()để wp_get_current_uesr()sau đó đảm bảo trả về không phải là boolean mà trả về $ current_user.

Điều này dường như đang hoạt động tốt, bao gồm cả bộ nhớ đệm, vv

Hy vọng điều này sẽ giúp những người khác.

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;
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.