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. Built from https://develop.svn.wordpress.org/trunk@47037 git-svn-id: http://core.svn.wordpress.org/trunk@46837 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7660fcda61
commit
08f53ef906
@ -2243,6 +2243,21 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||||||
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
|
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
|
||||||
foreach ( $taxonomies as $taxonomy ) {
|
foreach ( $taxonomies as $taxonomy ) {
|
||||||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||||
|
|
||||||
|
if ( array_key_exists( $base, $schema['properties'] ) ) {
|
||||||
|
$taxonomy_field_name_with_conflict = ! empty( $taxonomy->rest_base ) ? 'rest_base' : 'name';
|
||||||
|
_doing_it_wrong(
|
||||||
|
'register_taxonomy',
|
||||||
|
sprintf(
|
||||||
|
/* translators: 1. The taxonomy name, 2. The property name, either rest_base or name. */
|
||||||
|
__( '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.' ),
|
||||||
|
$base,
|
||||||
|
$taxonomy_field_name_with_conflict
|
||||||
|
),
|
||||||
|
'5.4.0'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$schema['properties'][ $base ] = array(
|
$schema['properties'][ $base ] = array(
|
||||||
/* translators: %s: Taxonomy name. */
|
/* translators: %s: Taxonomy name. */
|
||||||
'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ),
|
'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ),
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.4-alpha-47036';
|
$wp_version = '5.4-alpha-47037';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user