Automattic\WooCommerce\StoreApi
StoreApi::init
Init and hook in Store API functionality.
Method of the class: StoreApi{}
No Hooks.
Returns
null. Nothing (null).
Usage
$StoreApi = new StoreApi(); $StoreApi->init();
StoreApi::init() StoreApi::init code WC 10.9.4
public function init() {
/**
* Authentication instance.
*
* @var Authentication $authentication
*/
$authentication = self::container()->get( Authentication::class );
add_filter( 'woocommerce_session_handler', array( $authentication, 'maybe_use_store_api_session_handler' ), 0 );
add_action(
'rest_api_init',
function () {
if ( ! wc_rest_should_load_namespace( 'wc/store' ) && ! wc_rest_should_load_namespace( 'wc/private' ) ) {
return;
}
self::container()->get( Legacy::class )->init();
self::container()->get( RoutesController::class )->register_all_routes();
}
);
// Runs on priority 11 after rest_api_default_filters() which is hooked at 10.
add_action(
'rest_api_init',
function () {
if ( ! wc_rest_should_load_namespace( 'wc/store' ) ) {
return;
}
self::container()->get( Authentication::class )->init();
},
11
);
add_action(
'woocommerce_blocks_pre_get_routes_from_namespace',
function ( $routes, $ns ) {
if ( 'wc/store/v1' !== $ns ) {
return $routes;
}
$routes = array_merge(
$routes,
self::container()->get( RoutesController::class )->get_all_routes( 'v1' )
);
return $routes;
},
10,
2
);
}