Make WordPress Core

Changeset 53722


Ignore:
Timestamp:
07/19/2022 02:52:12 PM (19 months ago)
Author:
spacedmonkey
Message:

REST API: Add prepare_links method to WP_REST_Taxonomies_Controller class.

Move logic to from prepare_item_for_response to prepare_links method to bring WP_REST_Taxonomies_Controller class inline with other REST API controllers.

Props Spacedmonkey, timothyblynjacobs, dlh.
Fixes #56020.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php

    r51965 r53722  
    273273        $response = rest_ensure_response( $data );
    274274
    275         $response->add_links(
    276             array(
    277                 'collection'              => array(
    278                     'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
    279                 ),
    280                 'https://api.w.org/items' => array(
    281                     'href' => rest_url( rest_get_route_for_taxonomy_items( $taxonomy->name ) ),
    282                 ),
    283             )
    284         );
     275        $response->add_links( $this->prepare_links( $taxonomy ) );
    285276
    286277        /**
     
    438429    }
    439430
     431    /**
     432     * Prepares links for the request.
     433     *
     434     * @since 6.1.0
     435     *
     436     * @param @param WP_Taxonomy $taxonomy The taxonomy.
     437     * @return array Links for the given taxonomy.
     438     */
     439    protected function prepare_links( $taxonomy ) {
     440        return array(
     441            'collection'              => array(
     442                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
     443            ),
     444            'https://api.w.org/items' => array(
     445                'href' => rest_url( rest_get_route_for_taxonomy_items( $taxonomy->name ) ),
     446            ),
     447        );
     448    }
     449
    440450}
Note: See TracChangeset for help on using the changeset viewer.