WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/03/2020 07:22:32 PM (9 months ago)
Author:
kadamwhite
Message:

REST API: Issue doing_it_wrong if a taxonomy's specified rest_base is already in use by a different resource.

Props fgiannar, TimothyBlynJacobs, kingkool68, SergeyBiryukov.
Fixes #48401.

File:
1 edited

Legend:

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

    r46893 r47037  
    22432243        $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
    22442244        foreach ( $taxonomies as $taxonomy ) {
    2245             $base                          = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
     2245            $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
     2246
     2247            if ( array_key_exists( $base, $schema['properties'] ) ) {
     2248                $taxonomy_field_name_with_conflict = ! empty( $taxonomy->rest_base ) ? 'rest_base' : 'name';
     2249                _doing_it_wrong(
     2250                    'register_taxonomy',
     2251                    sprintf(
     2252                        /* translators: 1. The taxonomy name, 2. The property name, either rest_base or name. */
     2253                        __( 'The "%1$s" taxonomy "%2$s" conflicts with an existing property on the REST API Posts Controller. Specify a custom "rest_base" when registering the taxonomy to avoid this error.' ),
     2254                        $base,
     2255                        $taxonomy_field_name_with_conflict
     2256                    ),
     2257                    '5.4.0'
     2258                );
     2259            }
     2260
    22462261            $schema['properties'][ $base ] = array(
    22472262                /* translators: %s: Taxonomy name. */
Note: See TracChangeset for help on using the changeset viewer.