LLMS_REST_Posts_Controller::prepare_links( LLMS_Post_Model $object, WP_REST_Request $request )
Prepare links for the request.
Parameters Parameters
- $object
-
(LLMS_Post_Model) (Required) Object data.
- $request
-
(WP_REST_Request) (Required) Request object.
Return Return
(array) Links for the given object.
Source Source
File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-posts-controller.php
}
$object = new $class( 'new', $object_args );
return $object && is_a( $object, $class ) ? $object : llms_rest_not_found_error();
}
/**
* Prepare links for the request.
*
* @since 1.0.0-beta.1
* @since 1.0.0-beta.2 Filter taxonomies by `public` property instead of `show_in_rest`.
* @since 1.0.0-beta.3 Filter taxonomies by `show_in_llms_rest` property instead of `public`.
* @since 1.0.0-beta.7 `self` and `collection` links prepared in the parent class.
* Fix wp:featured_media link, we don't expose any embeddable field.
* @since 1.0.0-beta.8 Return links to those taxonomies which have an accessible rest route.
* @since 1.0.0-beta.14 Added $request parameter.
*
* @param LLMS_Post_Model $object Object data.
* @param WP_REST_Request $request Request object.
* @return array Links for the given object.
*/
protected function prepare_links( $object, $request ) {
$links = parent::prepare_links( $object, $request );
$object_id = $object->get( 'id' );
// Content.
$links['content'] = array(
'href' => rest_url( sprintf( '/%s/%s/%d/%s', $this->namespace, $this->rest_base, $object_id, 'content' ) ),
);
// If we have a featured media, add that.
$featured_media = get_post_thumbnail_id( $object_id );
if ( $featured_media ) {
$image_url = rest_url( 'wp/v2/media/' . $featured_media );
$links['https://api.w.org/featuredmedia'] = array(
'href' => $image_url,
);
}
$taxonomies = get_object_taxonomies( $this->post_type );
if ( ! empty( $taxonomies ) ) {
$links['https://api.w.org/term'] = array();
foreach ( $taxonomies as $tax ) {
$taxonomy_obj = get_taxonomy( $tax );
// Skip taxonomies that are not set to be shown in REST and LLMS REST.
if ( empty( $taxonomy_obj->show_in_rest ) || empty( $taxonomy_obj->show_in_llms_rest ) ) {
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0-beta.8 | Return links to those taxonomies which have an accessible rest route. |
| 1.0.0-beta.7 | self and collection links prepared in the parent class. Fix wp:featured_media link, we don't expose any embeddable field. |
| 1.0.0-beta.3 | Filter taxonomies by show_in_llms_rest property instead of public. |
| 1.0.0-beta.2 | Filter taxonomies by public property instead of show_in_rest. |
| 1.0.0-beta.14 | Added $request parameter. |
| 1.0.0-beta.1 | Introduced. |