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.


Top ↑

Return Return

(array) Links for the given object.


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-posts-controller.php

1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
    }
 
    $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 ) ) {


Top ↑

Changelog 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.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.