wppaste
WordPress

WP_Ability::normalize_input( mixed $input = null ): mixed

Since
6.9.0, 7.1.0
Source
wp-includes/abilities-api/class-wp-ability.php:483
Normalizes the input for the ability, applying the default value from the input schema when needed.

Description

When no input is provided and the input schema is defined with a top-level default key, this method returns the value of that key. If the input schema does not define a default, or if the input schema is empty, this method returns null. If input is provided, it is returned as-is.

The 'wp_ability_normalize_input' filter fires after the built-in default-value handling, allowing plugins to transform the result.

Compatibility

WordPress
since 7.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 3 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$inputmixedoptional
The raw input provided for the ability. Default null.Default: null

Return value

mixed
The normalized input, or a WP_Error if a filter returned one.

Performance profile

How much work a call to WP_Ability::normalize_input() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
13–19

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 19.

Plugin surface
1 hook

Third-party callbacks on 'wp_ability_normalize_input' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Ability::normalize_input() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$input !== null13apply_filters()
$input === null18–19->get_input_schema(), apply_filters()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 19 instructions, 13–19 executed per call, 2 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Ability::normalize_input() runs, in this order:

  1. apply_filters( wp_ability_normalize_input )filterline 508 (+25 into the body)

    Filters the normalized input for an ability.

Uses · 2

Used by · 1

Source code

	public function normalize_input( $input = null ) {		if ( null === $input ) {			$input_schema = $this->get_input_schema();			if ( array_key_exists( 'default', $input_schema ) ) {				$input = $input_schema['default'];			}		} 		/**		 * Filters the normalized input for an ability.		 *		 * Fires after `normalize_input()` has applied any default value declared in the input schema,		 * giving plugins a chance to adjust the input before it is consumed downstream. Common uses		 * include defaulting beyond what JSON Schema can express, prompt enrichment, and injecting		 * caller metadata.		 *		 * Returning a `WP_Error` causes callers that propagate it (such as `execute()`) to halt		 * before validation, permission checks, and the registered execute callback.		 *		 * @since 7.1.0		 *		 * @param mixed      $input        The normalized input data.		 * @param string     $ability_name The name of the ability.		 * @param WP_Ability $ability      The ability instance.		 */		return apply_filters( 'wp_ability_normalize_input', $input, $this->name, $this );	}

Changelog

Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

Signature, return type and hooks compared across 3 parsed releases.

7.1.0
Added the wp_ability_normalize_input filter.from the docblock
6.9.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/abilities-api/class-wp-ability.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.