WordPress action hook · part of WordPress core
rest_api_init
A WordPress core action that 17 plugins also fire themselves, running on 7.1M+ sites between them.
“Fires when preparing to serve an API request.”
How to use rest_api_init
It's an action: your callback runs at that point and receives 1 argument. Nothing needs to be returned.
Add this to your theme's functions.php or a small custom plugin:
add_action( 'rest_api_init', function( $wp_rest_server ) {
// Your code runs here.
}, 10, 1 );Argument names come from WooCommerce's source. Other plugins may pass different values: check the call in the plugin you're targeting below.
This hook is fired by WordPress core too. Official reference on developer.wordpress.org →
17 plugins that fire rest_api_init
Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.
-
WooCommerce7+ million installs
do_action( 'rest_api_init', $wp_rest_server )includes/cli/class-wc-cli-runner.php:59 -
FameTheme Demo Importer30,000+ installs
do_action( 'rest_api_init' )inc/generic/Studio/class-remote-client.php:175 -
WordPress REST API (Version 2)10,000+ installs
do_action( 'rest_api_init', $wp_rest_server )core-integration.php:79 -
LifterLMS10,000+ installs
do_action( 'rest_api_init', $wp_rest_server )libraries/lifterlms-cli/src/Commands/Restful/Runner.php:42 -
Edwiser Bridge4,000+ installs
do_action( 'rest_api_init' )admin/class-eb-settings-ajax-initiater.php:409 -
Assistant4,000+ installs
do_action( 'rest_api_init', rest_get_server() )backend/src/Hooks/Filters/OnHeartbeatReceived.php:18 -
REST API Toolbox1,000+ installs
do_action( 'rest_api_init', $wp_rest_server )includes/class-rest-api-toolbox-common.php:70 -
Atlant Security900+ installs
do_action( 'rest_api_init', rest_get_server() )admin/views/rest-api.php:13 -
Event Espresso500+ installs
do_action( 'rest_api_init', $this->wp_rest_server )core/domain/services/converters/RestApiSpoofer.php:67 -
Starter Templates90+ installs
do_action( 'rest_api_init' )inc/generic/Studio/class-remote-client.php:366 -
GhostGate20+ installs
do_action( 'rest_api_init' )inc/admin-ui.php:31 -
MarketPowerWP10+ installs
do_action( 'rest_api_init', $wp_rest_server )src/LePlugin/Api/ApiCall.php:42 -
GeniousSonu Site CheckupFewer than 10 installs
do_action( 'rest_api_init', $server )includes/class-rest-auditor.php:36 -
Aegis User GuardFewer than 10 installs
do_action( 'rest_api_init', rest_get_server() )class-aegis-user-guard.php:3027 -
RuleFenceFewer than 10 installs
do_action( 'rest_api_init' )src/Verification/RuntimeVerifier.php:1029 -
Ready POS for WooCommerceFewer than 10 installs
do_action( 'rest_api_init' )ready-pos.php:111 -
Фулфилмент от Почты России для маркетплейса DokanFewer than 10 installs
do_action( 'rest_api_init' )russian-post-for-dokan-marketplace.php:100
Need a customisation built on this hook?
Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.