Filter hook 'rest_authentication_errors'

in WP Core File wp-includes/rest-api/class-wp-rest-server.php at line 197

View Source

rest_authentication_errors

Filter Hook
Description
Filters REST API authentication errors. This is used to pass a WP_Error from an authentication method back to the API. Authentication methods should check first if they're being used, as multiple authentication methods can be enabled on a site (cookies, HTTP basic auth, OAuth). If the authentication method hooked in is not actually being attempted, null should be returned to indicate another authentication method should check instead. Similarly, callbacks should ensure the value is `null` before checking for errors. A WP_Error instance can be returned if an error occurs, and this should match the format used by API methods internally (that is, the `status` data should be used). A callback can return `true` to indicate that the authentication method was used, and it succeeded.

Hook Information

File Location wp-includes/rest-api/class-wp-rest-server.php View on GitHub
Hook Type Filter
Line Number 197

Hook Parameters

Type Name Description
WP_Error|null|true $errors WP_Error if authentication error, null if authentication method wasn't used, true if authentication succeeded.

Usage Examples

Basic Usage
<?php
// Hook into rest_authentication_errors
add_filter('rest_authentication_errors', 'my_custom_filter', 10, 1);

function my_custom_filter($errors) {
    // Your custom filtering logic here
    return $errors;
}

Source Code Context

wp-includes/rest-api/class-wp-rest-server.php:197 - How this hook is used in WordPress core
<?php
 192  		 * @since 4.4.0
 193  		 *
 194  		 * @param WP_Error|null|true $errors WP_Error if authentication error, null if authentication
 195  		 *                                   method wasn't used, true if authentication succeeded.
 196  		 */
 197  		return apply_filters( 'rest_authentication_errors', null );
 198  	}
 199  
 200  	/**
 201  	 * Converts an error to a response object.
 202  	 *

PHP Documentation

<?php
/**
		 * Filters REST API authentication errors.
		 *
		 * This is used to pass a WP_Error from an authentication method back to
		 * the API.
		 *
		 * Authentication methods should check first if they're being used, as
		 * multiple authentication methods can be enabled on a site (cookies,
		 * HTTP basic auth, OAuth). If the authentication method hooked in is
		 * not actually being attempted, null should be returned to indicate
		 * another authentication method should check instead. Similarly,
		 * callbacks should ensure the value is `null` before checking for
		 * errors.
		 *
		 * A WP_Error instance can be returned if an error occurs, and this should
		 * match the format used by API methods internally (that is, the `status`
		 * data should be used). A callback can return `true` to indicate that
		 * the authentication method was used, and it succeeded.
		 *
		 * @since 4.4.0
		 *
		 * @param WP_Error|null|true $errors WP_Error if authentication error, null if authentication
		 *                                   method wasn't used, true if authentication succeeded.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/rest-api/class-wp-rest-server.php
Related Hooks

Related hooks will be displayed here in future updates.