BP_REST_Activity_Endpoint::prepare_links( BP_Activity_Activity $activity )

Prepare links for the request.

Description

Parameters

$activity

(Required) Activity object.

Return

(array)

Source

File: bp-activity/classes/class-bp-rest-activity-endpoint.php

1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
protected function prepare_links( $activity ) {
    $base = sprintf( '/%s/%s/', $this->namespace, $this->rest_base );
    $url  = $base . $activity->id;
 
    // Entity meta.
    $links = array(
        'self'       => array(
            'href' => rest_url( $url ),
        ),
        'collection' => array(
            'href' => rest_url( $base ),
        ),
        'user'       => array(
            'href'       => rest_url( bp_rest_get_user_url( $activity->user_id ) ),
            'embeddable' => true,
        ),
    );
 
    if ( 'activity_comment' === $activity->type ) {
        $links['up'] = array(
            'href' => rest_url( $url ),
        );
    }
 
    if ( bp_activity_can_favorite() ) {
        $links['favorite'] = array(
            'href' => rest_url( $url . '/favorite' ),
        );
    }
 
    if ( bp_is_active( 'groups' ) && 'groups' === $activity->component && ! empty( $activity->item_id ) ) {
        $group = groups_get_group( $activity->item_id );
 
        $links['group'] = array(
            'href'       => bp_get_group_permalink( $group ),
            'embeddable' => true,
        );
    }
 
    /**
     * Filter links prepared for the REST response.
     *
     * @param array                $links    The prepared links of the REST response.
     * @param BP_Activity_Activity $activity Activity object.
     *
     * @since 0.1.0
     */
    return apply_filters( 'bp_rest_activity_prepare_links', $links, $activity );
}

Changelog

Changelog
Version Description
0.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.