Automattic\WooCommerce\Internal\RestApi\Routes\V4
AbstractController::get_authentication_error_by_method
Returns an authentication error for a given HTTP verb.
Method of the class: AbstractController{}
No Hooks.
Returns
WP_Error|false. WP Error object or false if no error is found.
Usage
// protected - for code of main (parent) or child class $result = $this->get_authentication_error_by_method( $method );
- $method(string) (required)
- HTTP method.
AbstractController::get_authentication_error_by_method() AbstractController::get authentication error by method code WC 10.4.3
protected function get_authentication_error_by_method( string $method ) {
$errors = array(
'GET' => array(
'code' => $this->get_error_prefix() . 'cannot_view',
'message' => __( 'Sorry, you cannot view resources.', 'woocommerce' ),
),
'POST' => array(
'code' => $this->get_error_prefix() . 'cannot_create',
'message' => __( 'Sorry, you cannot create resources.', 'woocommerce' ),
),
'PUT' => array(
'code' => $this->get_error_prefix() . 'cannot_update',
'message' => __( 'Sorry, you cannot update resources.', 'woocommerce' ),
),
'PATCH' => array(
'code' => $this->get_error_prefix() . 'cannot_update',
'message' => __( 'Sorry, you cannot update resources.', 'woocommerce' ),
),
'DELETE' => array(
'code' => $this->get_error_prefix() . 'cannot_delete',
'message' => __( 'Sorry, you cannot delete resources.', 'woocommerce' ),
),
);
if ( ! isset( $errors[ $method ] ) ) {
return false;
}
return new WP_Error(
$errors[ $method ]['code'],
$errors[ $method ]['message'],
array( 'status' => rest_authorization_required_code() )
);
}