Opened 6 years ago
Closed 5 years ago
#3799 closed enhancement (fixed)
improvements for submitting new categories via wp-admin/categories.php
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.5 |
| Component: | Administration | Version: | |
| Severity: | normal | Keywords: | category has-patch |
| Cc: |
Description
There are 2 things I would like to improve wile submitting new category into WP.
- If user by accident chose category name which is already exists in the system
- 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.
- 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');
##################
- 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';
#############
- /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)
Change History (16)
comment:2
markjaquith — 6 years ago
- Keywords needs-patch added
Mikiupdown2 — 6 years ago
Mikiupdown2 — 6 years ago
Mikiupdown2 — 6 years ago
comment:3
Mikiupdown2 — 6 years ago
- Keywords patched added; needs-patch removed
- Resolution set to worksforme
- Status changed from new to closed
comment:4
foolswisdom — 6 years ago
- Keywords has-patch added; patched removed
- Resolution worksforme deleted
- Status changed from closed to reopened
comment:5
johnbillion — 6 years ago
I think this fixes #3683 too but I'm not in a position to test at the moment.
comment:6
foolswisdom — 6 years ago
- Milestone changed from 2.2 to 2.3
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.
- 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?
comment:10
mdawaffe — 5 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.
comment:11
ryan — 5 years ago
- Resolution set to fixed
- Status changed from assigned to closed

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. :-)