W3cubDocs

/WordPress

WP_REST_Global_Styles_Controller::prepare_links( integer $id ): array

Prepares links for the request.

Parameters

$idintegerrequired
ID.

Return

array Links for the given post.

Source

protected function prepare_links( $id ) {
	$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );

	$links = array(
		'self'  => array(
			'href' => rest_url( trailingslashit( $base ) . $id ),
		),
		'about' => array(
			'href' => rest_url( 'wp/v2/types/' . $this->post_type ),
		),
	);

	if ( post_type_supports( $this->post_type, 'revisions' ) ) {
		$revisions                = wp_get_latest_revision_id_and_total_count( $id );
		$revisions_count          = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
		$revisions_base           = sprintf( '/%s/%d/revisions', $base, $id );
		$links['version-history'] = array(
			'href'  => rest_url( $revisions_base ),
			'count' => $revisions_count,
		);
	}

	return $links;
}

Changelog

Version Description
6.3.0 Adds revisions count and rest URL href to version-history.
5.9.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_global_styles_controller/prepare_links