WP_REST_Abilities_V1_Run_Controller::register_routespublicWP 6.9.0

Registers the routes for ability execution.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$WP_REST_Abilities_V1_Run_Controller = new WP_REST_Abilities_V1_Run_Controller();
$WP_REST_Abilities_V1_Run_Controller->register_routes(): void;

Заметки

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

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

Код WP_REST_Abilities_V1_Run_Controller::register_routes() WP 6.9

public function register_routes(): void {
	register_rest_route(
		$this->namespace,
		'/' . $this->rest_base . '/(?P<name>[a-zA-Z0-9\-\/]+?)/run',
		array(
			'args'   => array(
				'name' => array(
					'description' => __( 'Unique identifier for the ability.' ),
					'type'        => 'string',
					'pattern'     => '^[a-zA-Z0-9\-\/]+$',
				),
			),

			// TODO: We register ALLMETHODS because at route registration time, we don't know which abilities
			// exist or their annotations (`destructive`, `idempotent`, `readonly`). This is due to WordPress
			// load order - routes are registered early, before plugins have registered their abilities.
			// This approach works but could be improved with lazy route registration or a different
			// architecture that allows type-specific routes after abilities are registered.
			// This was the same issue that we ended up seeing with the Feature API.
			array(
				'methods'             => WP_REST_Server::ALLMETHODS,
				'callback'            => array( $this, 'execute_ability' ),
				'permission_callback' => array( $this, 'check_ability_permissions' ),
				'args'                => $this->get_run_args(),
			),
			'schema' => array( $this, 'get_run_schema' ),
		)
	);
}