Automattic\WooCommerce\Blocks\BlockTypes
AbstractBlock::get_routes_from_namespace
Get routes from a REST API namespace.
Method of the class: AbstractBlock{}
Hooks from the method
Returns
Array
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_routes_from_namespace( $namespace );
- $namespace(string) (required)
- Namespace to retrieve.
AbstractBlock::get_routes_from_namespace() AbstractBlock::get routes from namespace code WC 9.9.4
protected function get_routes_from_namespace( $namespace ) { /** * Gives opportunity to return routes without invoking the compute intensive REST API. * * @since 8.7.0 * @param array $routes Array of routes. * @param string $namespace Namespace for routes. * @param string $context Context, can be edit or view. */ $routes = apply_filters( 'woocommerce_blocks_pre_get_routes_from_namespace', array(), $namespace, 'view' ); if ( ! empty( $routes ) ) { return $routes; } $rest_server = rest_get_server(); $namespace_index = $rest_server->get_namespace_index( [ 'namespace' => $namespace, 'context' => 'view', ] ); if ( is_wp_error( $namespace_index ) ) { return []; } $response_data = $namespace_index->get_data(); return $response_data['routes'] ?? []; }