Automattic\WooCommerce\Blocks\BlockTypes
AbstractBlock::get_routes_from_namespace
Get routes from a REST API namespace.
Метод класса: AbstractBlock{}
Хуки из метода
Возвращает
Массив.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_routes_from_namespace( $namespace );
- $namespace(строка) (обязательный)
- Namespace to retrieve.
Код AbstractBlock::get_routes_from_namespace() AbstractBlock::get routes from namespace WC 10.3.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'] ?? [];
}