WP_REST_Global_Styles_Controller::prepare_links()
Prepares links for the request.
Method of the class: WP_REST_Global_Styles_Controller{}
No Hooks.
Return
Array
. Links for the given post.
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_links( $id );
- $id(int) (required)
- ID.
Changelog
Since 5.9.0 | Introduced. |
Since 6.3.0 | Adds revisions count and rest URL href to version-history. |
WP_REST_Global_Styles_Controller::prepare_links() WP REST Global Styles Controller::prepare links code WP 6.3
protected function prepare_links( $id ) { $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); $links = array( 'self' => array( 'href' => rest_url( trailingslashit( $base ) . $id ), ), ); 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; }