Changeset 31792 for trunk/src/wp-includes/taxonomy.php
- Timestamp:
- 03/16/2015 11:15:34 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r31734 r31792 2904 2904 } 2905 2905 2906 // Terms with duplicate names are not allowed at the same level of a taxonomy hierarchy. 2907 if ( $existing_term = get_term_by( 'name', $name, $taxonomy ) ) { 2908 if ( is_taxonomy_hierarchical( $taxonomy ) ) { 2909 $siblings = get_terms( $taxonomy, array( 'fields' => 'names', 'get' => 'all', 'parent' => $parent ) ); 2910 if ( in_array( $name, $siblings ) ) { 2911 return new WP_Error( 'term_exists', __( 'A term with the name already exists with this parent.' ), $existing_term->term_id ); 2906 /* 2907 * Prevent the creation of terms with duplicate names at the same level of a taxonomy hierarchy, 2908 * unless a unique slug has been explicitly provided. 2909 */ 2910 if ( $name_match = get_term_by( 'name', $name, $taxonomy ) ) { 2911 $slug_match = get_term_by( 'slug', $slug, $taxonomy ); 2912 if ( ! $slug_provided || $name_match->slug === $slug || $slug_match ) { 2913 if ( is_taxonomy_hierarchical( $taxonomy ) ) { 2914 $siblings = get_terms( $taxonomy, array( 'get' => 'all', 'parent' => $parent ) ); 2915 2916 $existing_term = null; 2917 if ( $name_match->slug === $slug && in_array( $name, wp_list_pluck( $siblings, 'name' ) ) ) { 2918 $existing_term = $name_match; 2919 } elseif ( $slug_match && in_array( $slug, wp_list_pluck( $siblings, 'slug' ) ) ) { 2920 $existing_term = $slug_match; 2921 } 2922 2923 if ( $existing_term ) { 2924 return new WP_Error( 'term_exists', __( 'A term with the name already exists with this parent.' ), $existing_term->term_id ); 2925 } 2926 } else { 2927 return new WP_Error( 'term_exists', __( 'A term with the name already exists in this taxonomy.' ), $name_match->term_id ); 2912 2928 } 2913 } else {2914 return new WP_Error( 'term_exists', __( 'A term with the name already exists in this taxonomy.' ), $existing_term->term_id );2915 2929 } 2916 2930 }
Note: See TracChangeset
for help on using the changeset viewer.