﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
3799,improvements for submitting new categories via wp-admin/categories.php,prokurator,mdawaffe,"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');
##################

2. 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';
#############

3. /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;
        }

     
",enhancement,closed,normal,2.5,Administration,,normal,fixed,category has-patch,
