WP_Ability::invoke_callbackprotectedWP 6.9.0

Invokes a callable, ensuring the input is passed through only if the input schema is defined.

Метод класса: WP_Ability{}

Хуков нет.

Возвращает

mixed. The result of the callable execution, or a WP_Error if the callback threw.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->invoke_callback( $callback, $input );
$callback(callable) (обязательный)
The callable to invoke.
$input(разное)
The input data for the ability.
По умолчанию: null

Список изменений

С версии 6.9.0 Введена.

Код WP_Ability::invoke_callback() WP 7.1

protected function invoke_callback( callable $callback, $input = null ) {
	$args = array();
	if ( ! empty( $this->get_input_schema() ) ) {
		$args[] = $input;
	}

	try {
		return $callback( ...$args );
	} catch ( Throwable $e ) {
		return new WP_Error(
			'ability_callback_exception',
			sprintf(
				/* translators: 1: Ability name, 2: Exception message. */
				__( 'Ability "%1$s" callback threw an exception: %2$s' ),
				$this->name,
				esc_html( $e->getMessage() )
			)
		);
	}
}