WP_Ability::do_execute( mixed $input = null ): mixed|WP_Error

Executes the ability callback.

Description

The ‘wp_ability_execute_result’ filter fires before this method returns, allowing plugins to transform the result produced by the registered execute_callback.

Parameters

$inputmixedoptional
The input data for the ability.

Default:null

Return

mixed|WP_Error The result of the ability execution, or WP_Error on failure.

Source

protected function do_execute( $input = null ) {
	if ( ! is_callable( $this->execute_callback ) ) {
		$result = new WP_Error(
			'ability_invalid_execute_callback',
			/* translators: %s ability name. */
			sprintf( __( 'Ability "%s" does not have a valid execute callback.' ), $this->name )
		);
	} else {
		$result = $this->invoke_callback( $this->execute_callback, $input );
	}

	/**
	 * Filters the result returned by an ability's execute callback.
	 *
	 * Fires after the registered execute callback runs. Plugins can use this to transform the
	 * result — response formatting, stripping internal metadata, content safety filtering,
	 * response enrichment, or recovering from a failure by returning a successful value.
	 *
	 * The filter receives whatever the registered callback produced, including a `WP_Error`
	 * if execution failed. Filters may pass the `WP_Error` through unchanged, override it with
	 * a recovered result, or convert a successful result into a `WP_Error`.
	 *
	 * @since 7.1.0
	 *
	 * @param mixed      $result       The result returned by the registered `execute_callback`,
	 *                                 or a `WP_Error` if execution failed.
	 * @param string     $ability_name The name of the ability.
	 * @param mixed      $input        The normalized input data.
	 * @param WP_Ability $ability      The ability instance.
	 */
	return apply_filters( 'wp_ability_execute_result', $result, $this->name, $input, $this );
}

Hooks

apply_filters( ‘wp_ability_execute_result’, mixed $result, string $ability_name, mixed $input, WP_Ability $ability )

Filters the result returned by an ability’s execute callback.

Changelog

VersionDescription
7.1.0Added the wp_ability_execute_result filter.
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.