WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#1750 closed defect (bug) (fixed)

Category cleanup

Reported by: donncha Owned by: ryan
Milestone: Priority: normal
Severity: normal Version: 1.6
Component: Administration Keywords:
Focuses: 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)

diff.txt (2.1 KB) - added by donncha 9 years ago.
wp_insert_category() cleanup

Download all attachments as: .zip

Change History (3)

donncha9 years ago

wp_insert_category() cleanup

comment:1 ryan9 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [2946]) Category insert cleanup from donncha. fixes #1750

comment:2 ryan9 years ago

  • Resolution set to fixed

(In [2947]) Oops. Patch didn't apply cleanly. fixes #1750

Note: See TracTickets for help on using tickets.