WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/26/2019 03:18:40 PM (8 weeks ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r45872 r45893  
    27462746        if ( $parent_suffix ) {
    27472747            $slug .= $parent_suffix;
     2748        }
     2749
     2750        if ( ! empty( $term->term_id ) ) {
     2751            $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id );
    27482752        } else {
    2749             if ( ! empty( $term->term_id ) ) {
    2750                 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id );
    2751             } else {
    2752                 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug );
    2753             }
    2754 
    2755             if ( $wpdb->get_var( $query ) ) {
    2756                 $num = 2;
    2757                 do {
    2758                     $alt_slug = $slug . "-$num";
    2759                     $num++;
    2760                     $slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
    2761                 } while ( $slug_check );
    2762                 $slug = $alt_slug;
    2763             }
     2753            $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug );
     2754        }
     2755
     2756        if ( $wpdb->get_var( $query ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
     2757            $num = 2;
     2758            do {
     2759                $alt_slug = $slug . "-$num";
     2760                $num++;
     2761                $slug_check = $wpdb->get_var( $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug ) );
     2762            } while ( $slug_check );
     2763            $slug = $alt_slug;
    27642764        }
    27652765    }
Note: See TracChangeset for help on using the changeset viewer.