BP_REST_Messages_Endpoint::prepare_links( BP_Messages_Thread $thread )

Prepare links for the request.

Description

Parameters

$thread

(Required) Thread object.

Return

(array) Links for the given thread.

Source

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

1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
protected function prepare_links( $thread ) {
    $base = sprintf( '/%s/%s/', $this->namespace, $this->rest_base );
 
    // Entity meta.
    $links = array(
        'self'       => array(
            'href' => rest_url( $base . $thread->thread_id ),
        ),
        'collection' => array(
            'href' => rest_url( $base ),
        ),
    );
 
    // Add star links for each message of the thread.
    if ( bp_is_active( 'messages', 'star' ) ) {
        $starred_base = $base . bp_get_messages_starred_slug() . '/';
 
        foreach ( $thread->messages as $message ) {
            $links[ $message->id ] = array(
                'href' => rest_url( $starred_base . $message->id ),
            );
        }
    }
 
    /**
     * Filter links prepared for the REST response.
     *
     * @param array              $links  The prepared links of the REST response.
     * @param BP_Messages_Thread $thread Thread object.
     *
     * @since 0.1.0
     */
    return apply_filters( 'bp_rest_messages_prepare_links', $links, $thread );
}

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.