From 8142df82bcfa9201f0bb48499f89e5d2e957697d Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 15 Aug 2018 19:50:25 +0000 Subject: [PATCH] Introduce `wp_insert_term_duplicate_term_check` filter. This filter allows plugins to intervene in the duplicate-term check that takes place at the time of term creation. See [30238], #22023. Props strategio. Fixes #43271. Built from https://develop.svn.wordpress.org/trunk@43570 git-svn-id: http://core.svn.wordpress.org/trunk@43399 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 21 ++++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 8ec3eaee3e..00c57947be 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2312,7 +2312,26 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { * and term_taxonomy_id of the older term instead. Then return out of the function so that the "create" hooks * are not fired. */ - $duplicate_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, tt.term_taxonomy_id FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON ( tt.term_id = t.term_id ) WHERE t.slug = %s AND tt.parent = %d AND tt.taxonomy = %s AND t.term_id < %d AND tt.term_taxonomy_id != %d", $slug, $parent, $taxonomy, $term_id, $tt_id ) ); + $duplicate_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, t.slug, tt.term_taxonomy_id, tt.taxonomy FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON ( tt.term_id = t.term_id ) WHERE t.slug = %s AND tt.parent = %d AND tt.taxonomy = %s AND t.term_id < %d AND tt.term_taxonomy_id != %d", $slug, $parent, $taxonomy, $term_id, $tt_id ) ); + + /** + * Filters the duplicate term check that takes place during term creation. + * + * Term parent+taxonomy+slug combinations are meant to be unique, and wp_insert_term() + * performs a last-minute confirmation of this uniqueness before allowing a new term + * to be created. Plugins with different uniqueness requirements may use this filter + * to bypass or modify the duplicate-term check. + * + * @since 5.0.0 + * + * @param object $duplicate_term Duplicate term row from terms table, if found. + * @param string $term Term being inserted. + * @param string $taxonomy Taxonomy name. + * @param array $args Term arguments passed to the function. + * @param int $tt_id term_taxonomy_id for the newly created term. + */ + $duplicate_term = apply_filters( 'wp_insert_term_duplicate_term_check', $duplicate_term, $term, $taxonomy, $args, $tt_id ); + if ( $duplicate_term ) { $wpdb->delete( $wpdb->terms, array( 'term_id' => $term_id ) ); $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 1715300b40..88e63f1788 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '5.0-alpha-43569'; +$wp_version = '5.0-alpha-43570'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.