From cded42aa941ec7c6497e86e7ab1ba64f80d9e414 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 28 Jul 2020 15:40:35 +0000 Subject: [PATCH] Taxonomy: Rename the `default_taxonomy_$taxonomy` option key to `default_term_$taxonomy`. This better reflects the purpose of the option. Follow-up to [48356], [48480]. See #43517. git-svn-id: https://develop.svn.wordpress.org/trunk@48665 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/capabilities.php | 2 +- src/wp-includes/post.php | 2 +- src/wp-includes/taxonomy.php | 8 ++++---- tests/phpunit/tests/taxonomy.php | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php index 6b6182a030..881075f1e2 100644 --- a/src/wp-includes/capabilities.php +++ b/src/wp-includes/capabilities.php @@ -541,7 +541,7 @@ function map_meta_cap( $cap, $user_id, ...$args ) { if ( 'delete_term' === $cap && ( get_option( 'default_' . $term->taxonomy ) == $term->term_id - || get_option( 'default_taxonomy_' . $term->taxonomy ) == $term->term_id ) + || get_option( 'default_term_' . $term->taxonomy ) == $term->term_id ) ) { $caps[] = 'do_not_allow'; break; diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index dfaec48149..8702d3e796 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4061,7 +4061,7 @@ function wp_insert_post( $postarr, $wp_error = false ) { } if ( empty( $postarr['tax_input'][ $taxonomy ] ) ) { - $default_term_id = get_option( 'default_taxonomy_' . $taxonomy ); + $default_term_id = get_option( 'default_term_' . $taxonomy ); if ( ! empty( $default_term_id ) ) { $postarr['tax_input'][ $taxonomy ] = array( (int) $default_term_id ); } diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index d7179fa31b..03eae33660 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -444,7 +444,7 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { if ( ! empty( $taxonomy_object->default_term ) ) { $term = term_exists( $taxonomy_object->default_term['name'], $taxonomy ); if ( $term ) { - update_option( 'default_taxonomy_' . $taxonomy_object->name, $term['term_id'] ); + update_option( 'default_term_' . $taxonomy_object->name, $term['term_id'] ); } else { $term = wp_insert_term( $taxonomy_object->default_term['name'], @@ -457,7 +457,7 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { // Update `term_id` in options. if ( ! is_wp_error( $term ) ) { - update_option( 'default_taxonomy_' . $taxonomy_object->name, $term['term_id'] ); + update_option( 'default_term_' . $taxonomy_object->name, $term['term_id'] ); } } } @@ -508,7 +508,7 @@ function unregister_taxonomy( $taxonomy ) { // Remove custom taxonomy default term option. if ( ! empty( $taxonomy_object->default_term ) ) { - delete_option( 'default_taxonomy_' . $taxonomy_object->name ); + delete_option( 'default_term_' . $taxonomy_object->name ); } // Remove the taxonomy. @@ -1834,7 +1834,7 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { // Don't delete the default custom taxonomy term. $taxonomy_object = get_taxonomy( $taxonomy ); if ( ! empty( $taxonomy_object->default_term ) ) { - $defaults['default'] = (int) get_option( 'default_taxonomy_' . $taxonomy ); + $defaults['default'] = (int) get_option( 'default_term_' . $taxonomy ); if ( $defaults['default'] === $term ) { return 0; } diff --git a/tests/phpunit/tests/taxonomy.php b/tests/phpunit/tests/taxonomy.php index cd87415b65..e8fcffc8d9 100644 --- a/tests/phpunit/tests/taxonomy.php +++ b/tests/phpunit/tests/taxonomy.php @@ -1001,7 +1001,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { // Test default category. $term = wp_get_post_terms( $post_id, $tax ); - $this->assertSame( get_option( 'default_taxonomy_' . $tax ), $term[0]->term_id ); + $this->assertSame( get_option( 'default_term_' . $tax ), $term[0]->term_id ); // Test default term deletion. $this->assertSame( wp_delete_term( $term[0]->term_id, $tax ), 0 ); @@ -1020,7 +1020,7 @@ class Tests_Taxonomy extends WP_UnitTestCase { ) ); $term = wp_get_post_terms( $post_id, $tax ); - $this->assertSame( get_option( 'default_taxonomy_' . $tax ), $term[0]->term_id ); + $this->assertSame( get_option( 'default_term_' . $tax ), $term[0]->term_id ); // wp_set_object_terms shouldn't assign default category. wp_set_object_terms( $post_id, array(), $tax ); @@ -1028,6 +1028,6 @@ class Tests_Taxonomy extends WP_UnitTestCase { $this->assertSame( array(), $term ); unregister_taxonomy( $tax ); - $this->assertSame( get_option( 'default_taxonomy_' . $tax ), false ); + $this->assertSame( get_option( 'default_term_' . $tax ), false ); } }