Changeset 30240 for trunk/src/wp-includes/taxonomy.php
- Timestamp:
- 11/05/2014 01:41:58 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/taxonomy.php
r30239 r30240 2846 2846 } 2847 2847 2848 if ( $term_id = term_exists($slug) ) { 2849 $existing_term = $wpdb->get_row( $wpdb->prepare( "SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id), ARRAY_A ); 2850 // We've got an existing term in the same taxonomy, which matches the name of the new term: 2851 if ( is_taxonomy_hierarchical($taxonomy) && $existing_term['name'] == $name && $exists = term_exists( (int) $term_id, $taxonomy ) ) { 2852 // Hierarchical, and it matches an existing term, Do not allow same "name" in the same level. 2853 $siblings = get_terms($taxonomy, array('fields' => 'names', 'get' => 'all', 'parent' => $parent ) ); 2854 if ( in_array($name, $siblings) ) { 2855 if ( $slug_provided ) { 2856 return new WP_Error( 'term_exists', __( 'A term with the name and slug provided already exists with this parent.' ), $exists['term_id'] ); 2857 } else { 2858 return new WP_Error( 'term_exists', __( 'A term with the name provided already exists with this parent.' ), $exists['term_id'] ); 2848 // Terms with duplicate names are not allowed at the same level of a taxonomy hierarchy. 2849 if ( $exists = term_exists( $slug, $taxonomy ) ) { 2850 $existing_term = get_term( $exists['term_id'], $taxonomy ); 2851 2852 if ( $name === $existing_term->name ) { 2853 2854 if ( is_taxonomy_hierarchical( $taxonomy ) ) { 2855 $siblings = get_terms( $taxonomy, array( 'fields' => 'names', 'get' => 'all', 'parent' => $parent ) ); 2856 if ( in_array( $name, $siblings ) ) { 2857 return new WP_Error( 'term_exists', __( 'A term with the name and slug already exists with this parent.' ), $exists['term_id'] ); 2859 2858 } 2859 2860 2860 } else { 2861 $slug = wp_unique_term_slug($slug, (object) $args); 2862 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) { 2863 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2864 } 2865 $term_id = (int) $wpdb->insert_id; 2861 return new WP_Error( 'term_exists', __( 'A term with the name and slug already exists in this taxonomy.' ), $exists['term_id'] ); 2866 2862 } 2867 } elseif ( $existing_term['name'] != $name ) { 2868 // We've got an existing term, with a different name, Create the new term. 2869 $slug = wp_unique_term_slug($slug, (object) $args); 2870 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) { 2871 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2872 } 2873 $term_id = (int) $wpdb->insert_id; 2874 } elseif ( $exists = term_exists( (int) $term_id, $taxonomy ) ) { 2875 // Same name, same slug. 2876 return new WP_Error( 'term_exists', __( 'A term with the name and slug provided already exists.' ), $exists['term_id'] ); 2877 } 2878 } else { 2879 // This term does not exist at all in the database, Create it. 2880 $slug = wp_unique_term_slug($slug, (object) $args); 2881 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) { 2882 return new WP_Error('db_insert_error', __('Could not insert term into the database'), $wpdb->last_error); 2883 } 2884 $term_id = (int) $wpdb->insert_id; 2885 } 2863 } 2864 } 2865 2866 $slug = wp_unique_term_slug( $slug, (object) $args ); 2867 2868 if ( false === $wpdb->insert( $wpdb->terms, compact( 'name', 'slug', 'term_group' ) ) ) { 2869 return new WP_Error( 'db_insert_error', __( 'Could not insert term into the database' ), $wpdb->last_error ); 2870 } 2871 2872 $term_id = (int) $wpdb->insert_id; 2886 2873 2887 2874 // Seems unreachable, However, Is used in the case that a term name is provided, which sanitizes to an empty string. … … 3230 3217 if ( ! term_exists( $slug ) ) 3231 3218 return $slug; 3219 3220 // As of 4.1, duplicate slugs are allowed as long as they're in different taxonomies. 3221 if ( get_option( 'db_version' ) >= 30133 && ! get_term_by( 'slug', $slug, $term->taxonomy ) ) { 3222 return $slug; 3223 } 3232 3224 3233 3225 // If the taxonomy supports hierarchy and the term has a parent, make the slug unique
Note: See TracChangeset
for help on using the changeset viewer.