Title: WP_REST_Abilities_V1_Run_Controller::ensure_error_status
Published: August 20, 2026

---

# WP_REST_Abilities_V1_Run_Controller::ensure_error_status( WP_Error $error, int $status ): 󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Ensures a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object carries an HTTP status, adding a default when none is set.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#parameters)󠁿

 `$error`[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
required

Error object to update.

`$status`intrequired

HTTP status code to add if not already present.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#return)󠁿

 [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) The error
object, with a default status when needed.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#source)󠁿

    ```php
    private function ensure_error_status( WP_Error $error, int $status ): WP_Error {
    	$error_data = $error->get_error_data();
    	if ( ! is_array( $error_data ) || ! isset( $error_data['status'] ) ) {
    		$error->add_data( array( 'status' => $status ) );
    	}

    	return $error;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php#L197)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php#L197-L204)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_REST_Abilities_V1_Run_Controller::check_ability_permissions()](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/check_ability_permissions/)`wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php` |

Checks if a given request has permission to execute a specific ability.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/ensure_error_status/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.1.0](https://developer.wordpress.org/reference/since/7.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_abilities_v1_run_controller%2Fensure_error_status%2F)
before being able to contribute a note or feedback.