WC_REST_Terms_Controller::prepare_links()protectedWC 1.0

Prepare links for the request.

Метод класса: WC_REST_Terms_Controller{}

Хуков нет.

Возвращает

Массив. Links for the given term.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->prepare_links( $term, $request );
$term(объект) (обязательный)
Term object.
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код WC_REST_Terms_Controller::prepare_links() WC 8.7.0

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;
}