Changeset 6157
- Timestamp:
- 09/22/2007 06:01:08 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/taxonomy.php
r6026 r6157 74 74 $parent = $category_parent; 75 75 76 $name = apply_filters('pre_category_name', $name);77 78 if ( empty ($slug) )79 $slug = sanitize_title($name);80 else81 $slug = sanitize_title($slug);82 $slug = apply_filters('pre_category_nicename', $slug);83 84 if ( empty ($description) )85 $description = '';86 $description = apply_filters('pre_category_description', $description);87 88 76 $parent = (int) $parent; 89 77 if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) ) … … 97 85 $cat_ID = wp_insert_term($cat_name, 'category', $args); 98 86 87 if ( is_wp_error($cat_ID) ) 88 return 0; 89 99 90 return $cat_ID['term_id']; 100 91 } … … 105 96 $cat_ID = (int) $catarr['cat_ID']; 106 97 107 if ( $cat_ID == $catarr['category_parent'] )98 if ( $cat_ID == $catarr['category_parent'] ) 108 99 return false; 109 100 -
trunk/wp-includes/taxonomy.php
r6125 r6157 708 708 $value = apply_filters("pre_term_$field", $value, $taxonomy); 709 709 $value = apply_filters("pre_${taxonomy}_$field", $value); 710 // Back compat filters 711 if ( 'slug' == $field ) 712 $value = apply_filters('pre_category_nicename', $value); 713 710 714 } else if ( 'rss' == $context ) { 711 715 $value = apply_filters("term_${field}_rss", $value, $taxonomy); … … 915 919 $args = wp_parse_args($args, $defaults); 916 920 $args['name'] = $term; 921 $args['taxonomy'] = $taxonomy; 917 922 $args = sanitize_term($args, $taxonomy, 'db'); 918 923 extract($args, EXTR_SKIP); … … 937 942 $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$name', '$slug', '$term_group')"); 938 943 $term_id = (int) $wpdb->insert_id; 944 } else if ( is_taxonomy_hierarchical($taxonomy) && !empty($parent) ) { 945 // If the taxonomy supports hierarchy and the term has a parent, make the slug unique 946 // by incorporating parent slugs. 947 $slug = wp_unique_term_slug($slug, (object) $args); 948 $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$name', '$slug', '$term_group')"); 949 $term_id = (int) $wpdb->insert_id; 939 950 } 940 951 … … 1020 1031 } 1021 1032 1033 function wp_unique_term_slug($slug, $term) { 1034 global $wpdb; 1035 1036 // If the taxonomy supports hierarchy and the term has a parent, make the slug unique 1037 // by incorporating parent slugs. 1038 if ( is_taxonomy_hierarchical($term->taxonomy) && !empty($term->parent) ) { 1039 $the_parent = $term->parent; 1040 while ( ! empty($the_parent) ) { 1041 $parent_term = get_term($the_parent, $term->taxonomy); 1042 if ( is_wp_error($parent_term) || empty($parent_term) ) 1043 break; 1044 $slug .= '-' . $parent_term->slug; 1045 if ( empty($parent_term->parent) ) 1046 break; 1047 $the_parent = $parent_term->parent; 1048 } 1049 } 1050 1051 // If we didn't get a unique slug, try appending a number to make it unique. 1052 if ( $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE slug = '$slug'") ) { 1053 $num = 2; 1054 do { 1055 $alt_slug = $slug . "-$num"; 1056 $num++; 1057 $slug_check = $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE slug = '$alt_slug'"); 1058 } while ( $slug_check ); 1059 $slug = $alt_slug; 1060 } 1061 1062 return $slug; 1063 } 1064 1022 1065 function wp_update_term( $term, $taxonomy, $args = array() ) { 1023 1066 global $wpdb; … … 1042 1085 extract($args, EXTR_SKIP); 1043 1086 1044 if ( empty($slug) ) 1087 $empty_slug = false; 1088 if ( empty($slug) ) { 1089 $empty_slug = true; 1045 1090 $slug = sanitize_title($name); 1091 } 1046 1092 1047 1093 if ( $alias_of ) { … … 1057 1103 } 1058 1104 1105 // Check for duplicate slug 1106 $id = $wpdb->get_var("SELECT term_id FROM $wpdb->terms WHERE slug = '$slug'"); 1107 if ( $id && ($id != $term_id) ) { 1108 // If an empty slug was passed, reset the slug to something unique. 1109 // Otherwise, bail. 1110 if ( $empty_slug ) 1111 $slug = wp_unique_term_slug($slug, (object) $args); 1112 else 1113 return new WP_Error('duplicate_term_slug', sprintf(__('The slug "%s" is already in use by another term'), $slug)); 1114 } 1115 1059 1116 $wpdb->query("UPDATE $wpdb->terms SET name = '$name', slug = '$slug', term_group = '$term_group' WHERE term_id = '$term_id'"); 1060 1117
Note: See TracChangeset
for help on using the changeset viewer.