rest_api_init
Fires when preparing to serve a REST API request.
Endpoint objects should be created and register their hooks on this action rather than another action to ensure they're only loaded when needed.
Usage
add_action( 'rest_api_init', 'wp_kama_rest_api_init_action' ); /** * Function for `rest_api_init` action-hook. * * @param WP_REST_Server $wp_rest_server Server object. * * @return void */ function wp_kama_rest_api_init_action( $wp_rest_server ){ // action... }
- $wp_rest_server(WP_REST_Server)
- Server object.
Changelog
Since 4.4.0 | Introduced. |
Where the hook is called
rest_api_init
wp-includes/rest-api.php 589
do_action( 'rest_api_init', $wp_rest_server );
Where the hook is used in WordPress
wp-includes/blocks/site-logo.php 103
add_action( 'rest_api_init', 'register_block_core_site_icon_setting', 10 );
wp-includes/blocks/site-logo.php 83
add_action( 'rest_api_init', 'register_block_core_site_logo_setting', 10 );
wp-includes/default-filters.php 512
add_action( 'rest_api_init', 'rest_api_default_filters', 10, 1 );
wp-includes/default-filters.php 513
add_action( 'rest_api_init', 'register_initial_settings', 10 );
wp-includes/default-filters.php 514
add_action( 'rest_api_init', 'create_initial_rest_routes', 99 );
wp-includes/default-filters.php 675
add_action( 'rest_api_init', 'wp_oembed_register_route' );