diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 5964218a7e..2fd92eeb38 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -246,6 +246,14 @@ case 'add-cat' : // From Manage->Categories $x->send(); } + if ( category_exists( trim( $_POST['cat_name'] ) ) ) { + $x = new WP_Ajax_Response( array( + 'what' => 'cat', + 'id' => new WP_Error( 'cat_exists', __('The category you are trying to create already exists.'), array( 'form-field' => 'cat_name' ) ), + ) ); + $x->send(); + } + $cat = wp_insert_category( $_POST, true ); if ( is_wp_error($cat) ) { diff --git a/wp-includes/js/wp-ajax-response.js b/wp-includes/js/wp-ajax-response.js index 419777371b..292e9e950a 100644 --- a/wp-includes/js/wp-ajax-response.js +++ b/wp-includes/js/wp-ajax-response.js @@ -50,8 +50,11 @@ wpAjax = jQuery.extend( { else if ( 0 === x ) { return !re.html('

' + this.broken + '

'); } return true; }, + invalidateForm: function ( selector ) { + return jQuery( selector ).addClass( 'form-invalid' ).change( function() { jQuery(this).removeClass( 'form-invalid' ); } ); + }, validateForm: function( selector ) { selector = jQuery( selector ); - return !selector.find('.form-required').andSelf().filter('.form-required:has(:input[value=""]), .form-required:input[value=""]').addClass( 'form-invalid' ).change( function() { jQuery(this).removeClass( 'form-invalid' ); } ).size(); + return !wpAjax.invalidateForm( selector.find('.form-required').andSelf().filter('.form-required:has(:input[value=""]), .form-required:input[value=""]') ).size(); } }, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'AJAX is teh b0rked.' } ); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 7181226ac5..ea2ba9fd60 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -41,7 +41,7 @@ class WP_Scripts { $this->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6'); - $this->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080312' ); + $this->add( 'wp-ajax-response', '/wp-includes/js/wp-ajax-response.js', array('jquery'), '20080316' ); $this->localize( 'wp-ajax-response', 'wpAjax', array( 'noPerm' => 'You do not have permission to do that.', 'broken' => 'AJAX is teh b0rked.'