Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
rest_get_route_for_term example
'self' => array
(
'href' =>
rest_url
(
trailingslashit
(
$base
)
.
$location
->name
)
,
)
,
'collection' => array
(
'href' =>
rest_url
(
$base
)
,
)
,
)
;
$locations
=
get_nav_menu_locations
(
)
;
$menu
=
isset
(
$locations
[
$location
->name
]
)
?
$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
;
}
/** * Prepares links for the request. * * @since 4.7.0 * * @param WP_Term $term Term object. * @return array Links for the given term. */
protected
function
prepare_links
(
$term
)
{
$links
= array
(
'self' => array
(
'href' =>
rest_url
(
rest_get_route_for_term
(
$term
)
)
,
)
,
'collection' => array
(
'href' =>
rest_url
(
rest_get_route_for_taxonomy_items
(
$this
->taxonomy
)
)
,
)
,
'about' => array
(
'href' =>
rest_url
(
sprintf
(
'wp/v2/taxonomies/%s',
$this
->taxonomy
)
)
,
)
,
)
;
if
(
$term
->parent
)
{
$parent_term
=
get_term
(
(int)
$term
->parent,
$term
->taxonomy
)
;
if
(
empty
(
$menu_item
->object_id
)
)
{
return
$links
;
}
$path
= '';
$type
= '';
$key
=
$menu_item
->type;
if
(
'post_type' ===
$menu_item
->type
)
{
$path
=
rest_get_route_for_post
(
$menu_item
->object_id
)
;
$type
=
get_post_type
(
$menu_item
->object_id
)
;
}
elseif
(
'taxonomy' ===
$menu_item
->type
)
{
$path
=
rest_get_route_for_term
(
$menu_item
->object_id
)
;
$type
=
get_term_field
(
'taxonomy',
$menu_item
->object_id
)
;
}
if
(
$path
&&
$type
)
{
$links
[
'https://api.w.org/menu-item-object'
]
[
]
= array
(
'href' =>
rest_url
(
$path
)
,
$key
=>
$type
,
'embeddable' => true,
)
;
}
public
function
prepare_item_links
(
$id
)
{
$term
=
get_term
(
$id
)
;
$links
= array
(
)
;
$item_route
=
rest_get_route_for_term
(
$term
)
;
if
(
$item_route
)
{
$links
[
'self'
]
= array
(
'href' =>
rest_url
(
$item_route
)
,
'embeddable' => true,
)
;
}
$links
[
'about'
]
= array
(
'href' =>
rest_url
(
sprintf
(
'wp/v2/taxonomies/%s',
$term
->taxonomy
)
)
,
)
;
/** * Gets the REST route for the currently queried object. * * @since 5.5.0 * * @return string The REST route of the resource, or an empty string if no resource identified. */
function
rest_get_queried_resource_route
(
)
{
if
(
is_singular
(
)
)
{
$route
=
rest_get_route_for_post
(
get_queried_object
(
)
)
;
}
elseif
(
is_category
(
)
||
is_tag
(
)
||
is_tax
(
)
)
{
$route
=
rest_get_route_for_term
(
get_queried_object
(
)
)
;
}
elseif
(
is_author
(
)
)
{
$route
= '/wp/v2/users/' .
get_queried_object_id
(
)
;
}
else
{
$route
= '';
}
/** * Filters the REST route for the currently queried object. * * @since 5.5.0 * * @param string $link The route with a leading slash, or an empty string. */