Make WordPress Core

Opened 20 years ago

Closed 19 years ago

#3799 closed enhancement (fixed)

improvements for submitting new categories via wp-admin/categories.php

Reported by: prokurator Owned by: mdawaffe
Priority: normal Milestone: 2.5
Component: Administration Version:
Severity: normal Keywords: category has-patch
Cc: Focuses:

Description

There are 2 things I would like to improve wile submitting new category into WP.

  1. If user by accident chose category name which is already exists in the system
  2. If user by accident hit submit without entering any category name (category name is empty).

In order to fix this problems 3 files need to be updated.

  1. wp-admin/admin-ajax.php

add after line 132 (case 'add-cat')
following code:
##################

$cat = wp_insert_category($_POST);
if ( !$cat ) #= wp_insert_category( $_POST ) )

die('4');

$rr = $cat;
if (is_string($rr) && preg_match('/same/',$rr))

die('5');

# if ( !$cat = wp_insert_category( $_POST ) )
# die('0');
##################

  1. wp-admin/admin-db.php

add in the function wp_insert_category($catarr)
after line 85
following code:
#############

$ccat = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories WHERE cat_name = '$cat_name'");
if ($ccat)

return 'same';

#############

  1. /wp-includes/js/wp-ajax-js.php

add after line 61 (in ParseAjaxResponse)
following code or make adjustment to existing error definition:
else if ( 4 == r ) {

Element.update(this.myResponseElement,"<div class='error'><p><?php _e("Something strange happened. Category field is empty."); ?></p></div>");
return false;

} else if ( 5 == r ) {

Element.update(this.myResponseElement,"<div class='error'><p><?php _e("Something strange happened. The same category name already exists."); ?></p></div>");
return false;

}


Attachments (5)

admin-ajax-line132.patch​ (642 bytes ) - added by Mikiupdown2 20 years ago.
admin-db-returnsame.patch​ (437 bytes ) - added by Mikiupdown2 20 years ago.
wp-ajax-emptyexists.patch​ (884 bytes ) - added by Mikiupdown2 20 years ago.
duplicate-category-protection.diff​ (652 bytes ) - added by westi 19 years ago.
Updated patch for trunk
3799.diff​ (2.3 KB ) - added by mdawaffe 19 years ago.

Download all attachments as: .zip

Change History (16)

#1 @Nazgul
20 years ago

  • Milestone 2.3 → 2.2

#2 @markjaquith
20 years ago

  • Keywords needs-patch added

Patch it up!

But instead of:

"Something strange happened. The same category name already exists."

Do:

"The same category name already exists."

We know what happened... no need to attribute it to mystical forces. :-)

#3 @Mikiupdown2
20 years ago

  • Keywords patched added; needs-patch removed
  • Resolution → worksforme
  • Status new → closed

#4 @foolswisdom
20 years ago

  • Keywords has-patch added; patched removed
  • Resolution worksforme
  • Status closed → reopened

#5 @johnbillion
20 years ago

I think this fixes #3683 too but I'm not in a position to test at the moment.

#6 @foolswisdom
20 years ago

  • Milestone 2.2 → 2.3

#7 @ryan
19 years ago

  • Milestone 2.3 → 2.4

#8 @westi
19 years ago

On trunk you get visual feedback if the box is empty already.

But you can add an identically named category but you don't end up with two.

#9 @westi
19 years ago

  • Owner changed from anonymous to mdawaffe
  • Status reopened → new

Uploading a patch which stops duplicate category creation.

However the current ajax code doesn't seem to display any errors that are returned.

mdawaffe any clues?

@westi
19 years ago

Updated patch for trunk

#10 @mdawaffe
19 years ago

  • Status new → assigned

It's because of a JS error in wp-ajax-response.

Attached fixes the error and tells wp-ajax-response what field to turn red on error.

@mdawaffe
19 years ago

#11 @ryan
19 years ago

  • Resolution → fixed
  • Status assigned → closed

(In [7336]) Don't allow duplicate category creation. Props westi and mdawaffe. fixes #3799

Note: See TracTickets for help on using tickets.