Title: WP_Ability::validate_input
Published: February 24, 2026
Last modified: August 20, 2026

---

# WP_Ability::validate_input( mixed $input = null ): true|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

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

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

Validates input data against the input schema.

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

 `$input`mixedoptional

The input data to validate.

Default:`null`

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

 true|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) Returns
true if valid or the [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object if validation fails.

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

    ```php
    public function validate_input( $input = null ) {
    	$input_schema = $this->get_input_schema();
    	if ( empty( $input_schema ) ) {
    		if ( null === $input ) {
    			return true;
    		}

    		return new WP_Error(
    			'ability_missing_input_schema',
    			sprintf(
    				/* translators: %s ability name. */
    				__( 'Ability "%s" does not define an input schema required to validate the provided input.' ),
    				$this->name
    			)
    		);
    	}

    	$valid_input = rest_validate_value_from_schema( $input, $input_schema, 'input' );
    	if ( is_wp_error( $valid_input ) ) {
    		$is_valid = new WP_Error(
    			'ability_invalid_input',
    			sprintf(
    				/* translators: %1$s ability name, %2$s error message. */
    				__( 'Ability "%1$s" has invalid input. Reason: %2$s' ),
    				$this->name,
    				$valid_input->get_error_message()
    			)
    		);
    	} else {
    		$is_valid = true;
    	}

    	/**
    	 * Filters the input validation result for an ability.
    	 *
    	 * Allows developers to add custom validation logic on top of the default
    	 * JSON Schema validation. If default validation already failed, the filter
    	 * receives the WP_Error object and can add additional error information or
    	 * override it. If default validation passed, the filter can add additional
    	 * validation checks and return a WP_Error if those checks fail.
    	 *
    	 * @since 7.1.0
    	 *
    	 * @param true|WP_Error $is_valid     The validation result from default validation.
    	 * @param mixed         $input        The input data being validated.
    	 * @param string        $ability_name The name of the ability.
    	 */
    	$validity = apply_filters( 'wp_ability_validate_input', $is_valid, $input, $this->name );
    	if ( false === $validity ) {
    		return new WP_Error( 'ability_invalid_input', __( 'Invalid input.' ) );
    	}
    	if ( is_wp_error( $validity ) && $validity->has_errors() ) {
    		return $validity;
    	}
    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/abilities-api/class-wp-ability.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/abilities-api/class-wp-ability.php#L519)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/abilities-api/class-wp-ability.php#L519-L574)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/WP_Ability/validate_input/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_ability_validate_input’, true|WP_Error $is_valid, mixed $input, string $ability_name )](https://developer.wordpress.org/reference/hooks/wp_ability_validate_input/)

Filters the input validation result for an ability.

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

| Uses | Description | 
| [WP_Ability::get_input_schema()](https://developer.wordpress.org/reference/classes/wp_ability/get_input_schema/)`wp-includes/abilities-api/class-wp-ability.php` |

Retrieves the input schema for the ability.

  | 
| [rest_validate_value_from_schema()](https://developer.wordpress.org/reference/functions/rest_validate_value_from_schema/)`wp-includes/rest-api.php` |

Validate a value based on a schema.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 4 more](https://developer.wordpress.org/reference/classes/WP_Ability/validate_input/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/WP_Ability/validate_input/?output_format=md#)

| Used by | Description | 
| [WP_Ability::execute()](https://developer.wordpress.org/reference/classes/wp_ability/execute/)`wp-includes/abilities-api/class-wp-ability.php` |

Executes the ability after input validation and running a permission check.

  |

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

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

## User Contributed Notes

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