Taxonomy: Fix unique-slug check for terms with parents.
`wp_unique_term_slug()` appends numeric suffixes when the requested slug is already in use by a sibling term. Changes introduced in [32837] inadvertently caused this suffixing to be skipped in cases where the requested slug is suffixed with the parent slug, so that it became possible to have two terms `childslug-parentslug` underneath to the same `parentslug`. We fix this regression by ensuring that the numeric-suffix routine runs in all cases. Props yashar_hv, saskak, dlh. Fixes #46431. Built from https://develop.svn.wordpress.org/trunk@45893 git-svn-id: http://core.svn.wordpress.org/trunk@45704 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c5fed47367
commit
e0c83d76d1
|
@ -2745,22 +2745,22 @@ function wp_unique_term_slug( $slug, $term ) {
|
|||
if ( apply_filters( 'wp_unique_term_slug_is_bad_slug', $needs_suffix, $slug, $term ) ) {
|
||||
if ( $parent_suffix ) {
|
||||
$slug .= $parent_suffix;
|
||||
} else {
|
||||
if ( ! empty( $term->term_id ) ) {
|
||||
$query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id );
|
||||
} else {
|
||||
$query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $wpdb->get_var( $query ) ) {
|
||||
$num = 2;
|
||||
do {
|
||||
$alt_slug = $slug . "-$num";
|
||||
$num++;
|
||||
$slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
|
||||
} while ( $slug_check );
|
||||
$slug = $alt_slug;
|
||||
}
|
||||
if ( ! empty( $term->term_id ) ) {
|
||||
$query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id );
|
||||
} else {
|
||||
$query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug );
|
||||
}
|
||||
|
||||
if ( $wpdb->get_var( $query ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
||||
$num = 2;
|
||||
do {
|
||||
$alt_slug = $slug . "-$num";
|
||||
$num++;
|
||||
$slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
|
||||
} while ( $slug_check );
|
||||
$slug = $alt_slug;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.3-alpha-45892';
|
||||
$wp_version = '5.3-alpha-45893';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue