Make WordPress Core

Ticket #61761: 61716-2.diff

File 61716-2.diff, 1.5 KB (added by xipasduarte, 17 months ago)

Changes for proposal 2

  • src/wp-includes/taxonomy.php

    diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php
    index 778a6a3947..ac855d7e79 100644
    a b function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    24642464                return new WP_Error( 'invalid_term_name', __( 'Invalid term name.' ) );
    24652465        }
    24662466
    2467         $slug_provided = ! empty( $args['slug'] );
    2468         if ( ! $slug_provided ) {
     2467        $slug = $args['slug'];
     2468
     2469        // If no slug was provided, create one from the term name.
     2470        if ( empty( $args['slug'] ) ) {
    24692471                $slug = sanitize_title( $name );
    2470         } else {
    2471                 $slug = $args['slug'];
    24722472        }
    24732473
    24742474        $term_group = 0;
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    25242524
    25252525        if ( $name_match ) {
    25262526                $slug_match = get_term_by( 'slug', $slug, $taxonomy );
    2527                 if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) {
     2527                if ( $name_match->slug === $slug || $slug_match ) {
    25282528                        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
    25292529                                $siblings = get_terms(
    25302530                                        array(
    function wp_insert_term( $term, $taxonomy, $args = array() ) { 
    25392539                                $sibling_names = wp_list_pluck( $siblings, 'name' );
    25402540                                $sibling_slugs = wp_list_pluck( $siblings, 'slug' );
    25412541
    2542                                 if ( ( ! $slug_provided || $name_match->slug === $slug ) && in_array( $name, $sibling_names, true ) ) {
     2542                                if ( ( $name_match->slug === $slug ) && in_array( $name, $sibling_names, true ) ) {
    25432543                                        $existing_term = $name_match;
    25442544                                } elseif ( $slug_match && in_array( $slug, $sibling_slugs, true ) ) {
    25452545                                        $existing_term = $slug_match;