wp_validate_application_password

函式
wp_validate_application_password ( $input_user )
引數
  • (int|false) $input_user User ID if one has been determined, false otherwise.
    Required:
返回值
  • (int|false) The authenticated user ID if successful, false otherwise.
定義位置
相關方法
wp_authenticate_application_passwordwp_is_application_passwords_availablewp_is_application_passwords_supportedwp_is_authorize_application_password_request_validwp_authenticate_email_password
引入
5.6.0
棄用
-

wp_validate_application_password是一個WordPress函式,用於驗證使用者的應用密碼: 這個函式與WordPress REST API一起使用,用來驗證訪問API的使用者: 這個函式把一個使用者ID和一個應用密碼作為它的輸入,如果密碼有效則返回真,如果無效則返回假。

驗證通過基本認證傳遞的應用程式密碼憑證。

function wp_validate_application_password( $input_user ) {
	// Don't authenticate twice.
	if ( ! empty( $input_user ) ) {
		return $input_user;
	}

	if ( ! wp_is_application_passwords_available() ) {
		return $input_user;
	}

	// Both $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] must be set in order to attempt authentication.
	if ( ! isset( $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] ) ) {
		return $input_user;
	}

	$authenticated = wp_authenticate_application_password( null, $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] );

	if ( $authenticated instanceof WP_User ) {
		return $authenticated->ID;
	}

	// If it wasn't a user what got returned, just pass on what we had received originally.
	return $input_user;
}

常見問題

FAQs
檢視更多 >