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
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-05 20:33:00

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: