rest_api_init
Action HookDescription
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.Hook Information
File Location |
wp-includes/rest-api.php
View on GitHub
|
Hook Type | Action |
Line Number | 628 |
Hook Parameters
Type | Name | Description |
---|---|---|
WP_REST_Server
|
$wp_rest_server
|
Server object. |
Usage Examples
Basic Usage
<?php
// Hook into rest_api_init
add_action('rest_api_init', 'my_custom_function', 10, 1);
function my_custom_function($wp_rest_server) {
// Your custom code here
}
Source Code Context
wp-includes/rest-api.php:628
- How this hook is used in WordPress core
<?php
623 *
624 * @since 4.4.0
625 *
626 * @param WP_REST_Server $wp_rest_server Server object.
627 */
628 do_action( 'rest_api_init', $wp_rest_server );
629 }
630
631 return $wp_rest_server;
632 }
633
PHP Documentation
<?php
/**
* 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.
*
* @since 4.4.0
*
* @param WP_REST_Server $wp_rest_server Server object.
*/
Quick Info
- Hook Type: Action
- Parameters: 1
- File: wp-includes/rest-api.php
Related Hooks
Related hooks will be displayed here in future updates.