WC_REST_Terms_Controller::prepare_links
Prepare links for the request.
Method of the class: WC_REST_Terms_Controller{}
No Hooks.
Returns
Array. Links for the given term.
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_links( $term, $request );
- $term(object) (required)
- Term object.
- $request(WP_REST_Request) (required)
- Full details about the request.
WC_REST_Terms_Controller::prepare_links() WC REST Terms Controller::prepare links code WC 10.4.3
protected function prepare_links( $term, $request ) {
$base = '/' . $this->namespace . '/' . $this->rest_base;
if ( ! empty( $request['attribute_id'] ) ) {
$base = str_replace( '(?P<attribute_id>[\d]+)', (int) $request['attribute_id'], $base );
}
$links = array(
'self' => array(
'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
),
'collection' => array(
'href' => rest_url( $base ),
),
);
if ( $term->parent ) {
$parent_term = get_term( (int) $term->parent, $term->taxonomy );
if ( $parent_term ) {
$links['up'] = array(
'href' => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
);
}
}
return $links;
}