WPCOM_VIP_Support_User::get_user_email_verification_code PHP 메소드

get_user_email_verification_code() 보호된 메소드

Stored in the same serialised user meta value: * The verification code * The email the verification code was generated against * The last time this method was touched, so we can calculate expiry in the future if we want to
protected get_user_email_verification_code ( integer $user_id ) : string
$user_id integer The ID of the user to get the verification code for
리턴 string A random hex string
    protected function get_user_email_verification_code($user_id)
    {
        $generate_new_code = false;
        $user = get_user_by('id', $user_id);
        $verification_data = get_user_meta($user_id, self::META_VERIFICATION_DATA, true);
        if (!$verification_data) {
            $verification_data = array('touch' => current_time('timestamp', true));
            $generate_new_code = true;
        }
        if ($verification_data['email'] != $user->user_email) {
            $generate_new_code = true;
        }
        if ($generate_new_code) {
            $verification_data['code'] = bin2hex(openssl_random_pseudo_bytes(16));
            $verification_data['touch'] = current_time('timestamp', true);
        }
        // Refresh the email, in case it changed since we created the meta
        // (this can happen if a user changes their email 1+ times)
        $verification_data['email'] = $user->user_email;
        update_user_meta($user_id, self::META_VERIFICATION_DATA, $verification_data);
        return $verification_data['code'];
    }