woocommerce_rest_api_get_rest_namespaces filter-hookWC 4.5.0

Filter the list of REST API controllers to load.

Usage

add_filter( 'woocommerce_rest_api_get_rest_namespaces', 'wp_kama_woocommerce_rest_api_get_namespaces_filter' );

/**
 * Function for `woocommerce_rest_api_get_rest_namespaces` filter-hook.
 * 
 * @param array $controllers List of $namespace => $controllers to load.
 *
 * @return array
 */
function wp_kama_woocommerce_rest_api_get_namespaces_filter( $controllers ){

	// filter...
	return $controllers;
}
$controllers(array)
List of $namespace => $controllers to load.

Changelog

Since 4.5.0 Introduced.

Where the hook is called

Server::get_rest_namespaces()
woocommerce_rest_api_get_rest_namespaces
woocommerce/includes/rest-api/Server.php 66-74
return apply_filters(
	'woocommerce_rest_api_get_rest_namespaces',
	array(
		'wc/v1'        => wc_rest_should_load_namespace( 'wc/v1' ) ? $this->get_v1_controllers() : array(),
		'wc/v2'        => wc_rest_should_load_namespace( 'wc/v2' ) ? $this->get_v2_controllers() : array(),
		'wc/v3'        => wc_rest_should_load_namespace( 'wc/v3' ) ? $this->get_v3_controllers() : array(),
		'wc-telemetry' => wc_rest_should_load_namespace( 'wc-telemetry' ) ? $this->get_telemetry_controllers() : array(),
	)
);

Where the hook is used in WooCommerce

woocommerce/includes/wccom-site/class-wc-wccom-site.php 33
add_action( 'woocommerce_rest_api_get_rest_namespaces', array( __CLASS__, 'register_rest_namespace' ) );
woocommerce/src/Internal/RestApiControllerBase.php 95
static::add_filter( 'woocommerce_rest_api_get_rest_namespaces', array( $this, 'handle_woocommerce_rest_api_get_rest_namespaces' ) );