Make WordPress Core

Opened 17 years ago

Closed 16 years ago

#3799 closed enhancement (fixed)

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

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

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 17 years ago.
admin-db-returnsame.patch (437 bytes) - added by Mikiupdown2 17 years ago.
wp-ajax-emptyexists.patch (884 bytes) - added by Mikiupdown2 17 years ago.
duplicate-category-protection.diff (652 bytes) - added by westi 16 years ago.
Updated patch for trunk
3799.diff (2.3 KB) - added by mdawaffe 16 years ago.

Download all attachments as: .zip

Change History (16)

#1 @Nazgul
17 years ago

  • Milestone changed from 2.3 to 2.2

#2 @markjaquith
17 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
17 years ago

  • Keywords patched added; needs-patch removed
  • Resolution set to worksforme
  • Status changed from new to closed

#4 @foolswisdom
17 years ago

  • Keywords has-patch added; patched removed
  • Resolution worksforme deleted
  • Status changed from closed to reopened

#5 @johnbillion
17 years ago

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

#6 @foolswisdom
17 years ago

  • Milestone changed from 2.2 to 2.3

#7 @ryan
16 years ago

  • Milestone changed from 2.3 to 2.4

#8 @westi
16 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
16 years ago

  • Owner changed from anonymous to mdawaffe
  • Status changed from reopened to 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
16 years ago

Updated patch for trunk

#10 @mdawaffe
16 years ago

  • Status changed from new to 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
16 years ago

#11 @ryan
16 years ago

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

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

Note: See TracTickets for help on using tickets.