WP_REST_Menu_Locations_Controller::prepare_links
Prepares links for the request.
Метод класса: WP_REST_Menu_Locations_Controller{}
Хуков нет.
Возвращает
Массив. Links for the given menu location.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->prepare_links( $location );
- $location(stdClass) (обязательный)
- Menu location.
Список изменений
| С версии 5.9.0 | Введена. |
Код WP_REST_Menu_Locations_Controller::prepare_links() WP REST Menu Locations Controller::prepare links WP 7.0
protected function prepare_links( $location ) {
$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
// Entity meta.
$links = array(
'self' => array(
'href' => rest_url( trailingslashit( $base ) . $location->name ),
),
'collection' => array(
'href' => rest_url( $base ),
),
);
$locations = get_nav_menu_locations();
$menu = $locations[ $location->name ] ?? 0;
if ( $menu ) {
$path = rest_get_route_for_term( $menu );
if ( $path ) {
$url = rest_url( $path );
$links['https://api.w.org/menu'][] = array(
'href' => $url,
'embeddable' => true,
);
}
}
return $links;
}