Don't allow duplicate category creation. Props westi and mdawaffe. fixes #3799

git-svn-id: http://svn.automattic.com/wordpress/trunk@7336 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-03-16 20:37:02 +00:00
parent c41402325f
commit 4f60026851
3 changed files with 13 additions and 2 deletions

View File

@ -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) ) {

View File

@ -50,8 +50,11 @@ wpAjax = jQuery.extend( {
else if ( 0 === x ) { return !re.html('<div class="error"><p>' + this.broken + '</p></div>'); }
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.' } );

View File

@ -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.'