#1750 closed defect (bug) (fixed)
Category cleanup
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | 1.6 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Here's a patch that cleans up wp_insert_category()
--- trunk/wp-inst/wp-admin/admin-db.php 2005-10-11 09:08:37 UTC (rev 396)
+++ trunk/wp-inst/wp-admin/admin-db.php 2005-10-11 15:34:15 UTC (rev 397)
@@ -92,16 +92,14 @@
$update = true;
} else {
$update = false;
- $id_result = $wpdb->get_row("SHOW TABLE STATUS LIKE '$wpdb->categories'");
- $cat_ID = $id_result->Auto_increment;
}
$cat_name = wp_specialchars($cat_name);
if (empty ($category_nicename))
- $category_nicename = sanitize_title($cat_name, $cat_ID);
+ $category_nicename = sanitize_title($cat_name);
else
- $category_nicename = sanitize_title($category_nicename, $cat_ID);
+ $category_nicename = sanitize_title($category_nicename);
if (empty ($category_description))
$category_description = '';
@@ -109,18 +107,22 @@
if (empty ($category_parent))
$category_parent = 0;
- if (!$update)
- $query = "INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')";
- else
- $query = "UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' WHERE cat_ID = '$cat_ID'";
+ if (!$update) {
+ $wpdb->query( "INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent')" );
+ $cat_ID = $wpdb->insert_id;
+ } else {
+ $wpdb->query( "UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' WHERE cat_ID = '$cat_ID'" );
+ }
+ if ( $category_nicename == '' ) {
+ $category_nicename = sanitize_title($cat_name, $cat_ID );
+ $wpdb->query( "UPDATE $wpdb->categories SET category_nicename = '$category_nicename' WHERE cat_ID = '$cat_ID'" );
+ }
- $result = $wpdb->query($query);
-
if ($update) {
do_action('edit_category', $cat_ID);
} else {
- do_action('create_category', $rval);
- do_action('add_category', $rval);
+ do_action('create_category', $cat_ID);
+ do_action('add_category', $cat_ID);
}
return $cat_ID;
Attachments (1)
Change History (3)
Note: See
TracTickets for help on using
tickets.

wp_insert_category() cleanup