BP_REST_Topics_Endpoint::prepare_links( WP_Post $post )

Prepare links for the request.

Description

Parameters

$post

(Required) Post object.

Return

(array)

Source

File: bp-forums/classes/class-bp-rest-topics-endpoint.php

2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
protected function prepare_links( $post ) {
    $base = sprintf( '/%s/%s/', $this->namespace, $this->rest_base );
 
    // Entity meta.
    $links = array(
        'self'       => array(
            'href' => rest_url( $base . $post->ID ),
        ),
        'collection' => array(
            'href' => rest_url( $base ),
        ),
        'user'       => array(
            'href'       => rest_url( bp_rest_get_user_url( $post->post_author ) ),
            'embeddable' => true,
        ),
    );
 
    $form_id = (int) bbp_get_topic_forum_id( $post->ID );
 
    if ( ! empty( $form_id ) ) {
        $form_base      = sprintf( '/%s/%s/', $this->forum_endpoint->namespace, $this->forum_endpoint->rest_base );
        $links['forum'] = array(
            'href'       => rest_url( $form_base . $form_id ),
            'embeddable' => true,
        );
    }
 
    /**
     * Filter links prepared for the REST response.
     *
     * @param array   $links The prepared links of the REST response.
     * @param WP_Post $post  Post object.
     *
     * @since 0.1.0
     */
    return apply_filters( 'bp_rest_topic_prepare_links', $links, $post );
}

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.