Make WordPress Core


Ignore:
Timestamp:
07/19/2022 02:47:45 PM (2 years ago)
Author:
spacedmonkey
Message:

REST API: Add prepare_links method to WP_REST_Post_Types_Controller class.

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

Props Spacedmonkey, timothyblynjacobs, dlh.
Fixes #56019.

File:
1 edited

Legend:

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

    r52831 r53721  
    245245        $response = rest_ensure_response( $data );
    246246
    247         $response->add_links(
    248             array(
    249                 'collection'              => array(
    250                     'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
    251                 ),
    252                 'https://api.w.org/items' => array(
    253                     'href' => rest_url( rest_get_route_for_post_type_items( $post_type->name ) ),
    254                 ),
    255             )
    256         );
     247        $response->add_links( $this->prepare_links( $post_type ) );
    257248
    258249        /**
     
    395386    }
    396387
     388    /**
     389     * Prepares links for the request.
     390     *
     391     * @since 6.1.0
     392     *
     393     * @param WP_Post_Type $post_type The post type.
     394     * @return array Links for the given post type.
     395     */
     396    protected function prepare_links( $post_type ) {
     397        return array(
     398            'collection'              => array(
     399                'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
     400            ),
     401            'https://api.w.org/items' => array(
     402                'href' => rest_url( rest_get_route_for_post_type_items( $post_type->name ) ),
     403            ),
     404        );
     405    }
    397406}
Note: See TracChangeset for help on using the changeset viewer.