Title: WP_AI_Client_Ability_Function_Resolver::execute_ability
Published: May 20, 2026

---

# WP_AI_Client_Ability_Function_Resolver::execute_ability( WordPressAiClientToolsDTOFunctionCall $call ): WordPressAiClientToolsDTOFunctionResponse

## In this article

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

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

Executes a WordPress ability from a function call.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/execute_ability/?output_format=md#description)󠁿

Only abilities that were specified in the constructor are allowed to be executed.
If the ability is not in the allowed list, an error response with code `ability_not_allowed`
is returned.

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

 `$call`WordPressAiClientToolsDTOFunctionCallrequired

The function call to execute.

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

 WordPressAiClientToolsDTOFunctionResponse The response from executing the ability.

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

    ```php
    public function execute_ability( FunctionCall $call ): FunctionResponse {
    	$function_name = $call->getName() ?? 'unknown';
    	$function_id   = $call->getId() ?? 'unknown';

    	if ( ! $this->is_ability_call( $call ) ) {
    		return new FunctionResponse(
    			$function_id,
    			$function_name,
    			array(
    				'error' => __( 'Not an ability function call' ),
    				'code'  => 'invalid_ability_call',
    			)
    		);
    	}

    	$ability_name = self::function_name_to_ability_name( $function_name );

    	if ( ! isset( $this->allowed_abilities[ $ability_name ] ) ) {
    		return new FunctionResponse(
    			$function_id,
    			$function_name,
    			array(
    				/* translators: %s: ability name */
    				'error' => sprintf( __( 'Ability "%s" was not specified in the allowed abilities list.' ), $ability_name ),
    				'code'  => 'ability_not_allowed',
    			)
    		);
    	}

    	$ability = wp_get_ability( $ability_name );

    	if ( ! $ability instanceof WP_Ability ) {
    		return new FunctionResponse(
    			$function_id,
    			$function_name,
    			array(
    				/* translators: %s: ability name */
    				'error' => sprintf( __( 'Ability "%s" not found' ), $ability_name ),
    				'code'  => 'ability_not_found',
    			)
    		);
    	}

    	$args   = $call->getArgs();
    	$result = $ability->execute( ! empty( $args ) ? $args : null );

    	if ( is_wp_error( $result ) ) {
    		return new FunctionResponse(
    			$function_id,
    			$function_name,
    			array(
    				'error' => $result->get_error_message(),
    				'code'  => $result->get_error_code(),
    				'data'  => $result->get_error_data(),
    			)
    		);
    	}

    	return new FunctionResponse(
    		$function_id,
    		$function_name,
    		$result
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php#L93)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php#L93-L156)

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

| Uses | Description | 
| [FunctionResponse::__construct()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-tools-dto-functionresponse/__construct/)`wp-includes/php-ai-client/src/Tools/DTO/FunctionResponse.php` |

Constructor.

  | 
| [WP_AI_Client_Ability_Function_Resolver::function_name_to_ability_name()](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/function_name_to_ability_name/)`wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php` |

Converts a function name to an ability name.

  | 
| [WP_AI_Client_Ability_Function_Resolver::is_ability_call()](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/is_ability_call/)`wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php` |

Checks if a function call is an ability call.

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

Retrieves a registered ability.

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

Retrieves the translation of $text.

  | 
| [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.

  |

[Show 2 more](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/execute_ability/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/execute_ability/?output_format=md#)

| Used by | Description | 
| [WP_AI_Client_Ability_Function_Resolver::execute_abilities()](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/execute_abilities/)`wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php` |

Executes all ability function calls in a message.

  |

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

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

## User Contributed Notes

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