wp_is_authorize_application_password_request_valid

函式
wp_is_authorize_application_password_request_valid ( $request, $user )
引數
  • (array) $request { The array of request data. All arguments are optional and may be empty. @type string $app_name The suggested name of the application. @type string $app_id A UUID provided by the application to uniquely identify it. @type string $success_url The URL the user will be redirected to after approving the application. @type string $reject_url The URL the user will be redirected to after rejecting the application. }
    Required:
  • (WP_User) $user The user authorizing the application.
    Required:
返回值
  • (true|WP_Error) True if the request is valid, a WP_Error object contains errors if not.
定義位置
相關方法
wp_is_application_passwords_availablewp_authenticate_application_passwordwp_is_application_passwords_supportedwp_validate_application_passwordwp_is_application_passwords_available_for_user
引入
5.6.0
棄用
-

wp_is_authorize_application_password_request_valid: 該函式用於檢查當前授權應用密碼的請求是否有效。它檢查請求是否有必要的引數,以及使用者是否被認證。

檢查授權應用密碼請求是否有效。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_is_authorize_application_password_request_valid( $request, $user ) {
$error = new WP_Error();
if ( ! empty( $request['success_url'] ) ) {
$scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME );
if ( 'http' === $scheme ) {
$error->add(
'invalid_redirect_scheme',
__( 'The success URL must be served over a secure connection.' )
);
}
}
if ( ! empty( $request['reject_url'] ) ) {
$scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME );
if ( 'http' === $scheme ) {
$error->add(
'invalid_redirect_scheme',
__( 'The rejection URL must be served over a secure connection.' )
);
}
}
if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
$error->add(
'invalid_app_id',
__( 'The application ID must be a UUID.' )
);
}
/**
* Fires before application password errors are returned.
*
* @since 5.6.0
*
* @param WP_Error $error The error object.
* @param array $request The array of request data.
* @param WP_User $user The user authorizing the application.
*/
do_action( 'wp_authorize_application_password_request_errors', $error, $request, $user );
if ( $error->has_errors() ) {
return $error;
}
return true;
}
function wp_is_authorize_application_password_request_valid( $request, $user ) { $error = new WP_Error(); if ( ! empty( $request['success_url'] ) ) { $scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME ); if ( 'http' === $scheme ) { $error->add( 'invalid_redirect_scheme', __( 'The success URL must be served over a secure connection.' ) ); } } if ( ! empty( $request['reject_url'] ) ) { $scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME ); if ( 'http' === $scheme ) { $error->add( 'invalid_redirect_scheme', __( 'The rejection URL must be served over a secure connection.' ) ); } } if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) { $error->add( 'invalid_app_id', __( 'The application ID must be a UUID.' ) ); } /** * Fires before application password errors are returned. * * @since 5.6.0 * * @param WP_Error $error The error object. * @param array $request The array of request data. * @param WP_User $user The user authorizing the application. */ do_action( 'wp_authorize_application_password_request_errors', $error, $request, $user ); if ( $error->has_errors() ) { return $error; } return true; }
function wp_is_authorize_application_password_request_valid( $request, $user ) {
	$error = new WP_Error();

	if ( ! empty( $request['success_url'] ) ) {
		$scheme = wp_parse_url( $request['success_url'], PHP_URL_SCHEME );

		if ( 'http' === $scheme ) {
			$error->add(
				'invalid_redirect_scheme',
				__( 'The success URL must be served over a secure connection.' )
			);
		}
	}

	if ( ! empty( $request['reject_url'] ) ) {
		$scheme = wp_parse_url( $request['reject_url'], PHP_URL_SCHEME );

		if ( 'http' === $scheme ) {
			$error->add(
				'invalid_redirect_scheme',
				__( 'The rejection URL must be served over a secure connection.' )
			);
		}
	}

	if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
		$error->add(
			'invalid_app_id',
			__( 'The application ID must be a UUID.' )
		);
	}

	/**
	 * Fires before application password errors are returned.
	 *
	 * @since 5.6.0
	 *
	 * @param WP_Error $error   The error object.
	 * @param array    $request The array of request data.
	 * @param WP_User  $user    The user authorizing the application.
	 */
	do_action( 'wp_authorize_application_password_request_errors', $error, $request, $user );

	if ( $error->has_errors() ) {
		return $error;
	}

	return true;
}

常見問題

FAQs
檢視更多 >