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:

functions.php
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.

  1. WooCommerce icon WooCommerce7+ million installs do_action( 'rest_api_init', $wp_rest_server ) includes/cli/class-wc-cli-runner.php:59
  2. FameTheme Demo Importer icon FameTheme Demo Importer30,000+ installs do_action( 'rest_api_init' ) inc/generic/Studio/class-remote-client.php:175
  3. WordPress REST API (Version 2) icon WordPress REST API (Version 2)10,000+ installs do_action( 'rest_api_init', $wp_rest_server ) core-integration.php:79
  4. LifterLMS icon LifterLMS10,000+ installs do_action( 'rest_api_init', $wp_rest_server ) libraries/lifterlms-cli/src/Commands/Restful/Runner.php:42
  5. Edwiser Bridge icon Edwiser Bridge4,000+ installs do_action( 'rest_api_init' ) admin/class-eb-settings-ajax-initiater.php:409
  6. Assistant icon Assistant4,000+ installs do_action( 'rest_api_init', rest_get_server() ) backend/src/Hooks/Filters/OnHeartbeatReceived.php:18
  7. REST API Toolbox icon REST API Toolbox1,000+ installs do_action( 'rest_api_init', $wp_rest_server ) includes/class-rest-api-toolbox-common.php:70
  8. Atlant Security icon Atlant Security900+ installs do_action( 'rest_api_init', rest_get_server() ) admin/views/rest-api.php:13
  9. Event Espresso icon Event Espresso500+ installs do_action( 'rest_api_init', $this->wp_rest_server ) core/domain/services/converters/RestApiSpoofer.php:67
  10. Starter Templates icon Starter Templates90+ installs do_action( 'rest_api_init' ) inc/generic/Studio/class-remote-client.php:366
  11. GhostGate icon GhostGate20+ installs do_action( 'rest_api_init' ) inc/admin-ui.php:31
  12. MarketPowerWP icon MarketPowerWP10+ installs do_action( 'rest_api_init', $wp_rest_server ) src/LePlugin/Api/ApiCall.php:42
  13. GeniousSonu Site Checkup icon GeniousSonu Site CheckupFewer than 10 installs do_action( 'rest_api_init', $server ) includes/class-rest-auditor.php:36
  14. Aegis User Guard icon Aegis User GuardFewer than 10 installs do_action( 'rest_api_init', rest_get_server() ) class-aegis-user-guard.php:3027
  15. RuleFence icon RuleFenceFewer than 10 installs do_action( 'rest_api_init' ) src/Verification/RuntimeVerifier.php:1029
  16. Ready POS for WooCommerce icon Ready POS for WooCommerceFewer than 10 installs do_action( 'rest_api_init' ) ready-pos.php:111
  17. Фулфилмент от Почты России для маркетплейса Dokan icon Фулфилмент от Почты России для маркетплейса 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.