AJAX for link category add and delete. Props mdawaffe. fixes #5291

git-svn-id: http://svn.automattic.com/wordpress/trunk@6299 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan
2007-10-31 03:53:32 +00:00
parent 24f0b83cae
commit 1d0bf72d2f
7 changed files with 109 additions and 59 deletions

View File

@@ -52,6 +52,36 @@ case 'delete-cat' :
die('1');
else die('0');
break;
case 'delete-link-cat' :
check_ajax_referer( "delete-link-category_$id" );
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$cat_name = get_term_field('name', $id, 'link_category');
// Don't delete the default cats.
if ( $id == get_option('default_link_category') ) {
$x = new WP_AJAX_Response( array(
'what' => 'link-cat',
'id' => $id,
'data' => new WP_Error( 'default-link-cat', sprintf(__("Can&#8217;t delete the <strong>%s</strong> category: this is the default one"), $cat_name) )
) );
$x->send();
}
$r = wp_delete_term($id, 'link_category');
if ( !$r )
die('0');
if ( is_wp_error($r) ) {
$x = new WP_AJAX_Response( array(
'what' => 'link-cat',
'id' => $id,
'data' => $r
) );
$x->send();
}
die('1');
break;
case 'delete-link' :
check_ajax_referer( "delete-bookmark_$id" );
if ( !current_user_can( 'manage_links' ) )
@@ -181,6 +211,32 @@ case 'add-cat' : // From Manage->Categories
) );
$x->send();
break;
case 'add-link-cat' : // From Blogroll -> Categories
check_ajax_referer( 'add-link-category' );
if ( !current_user_can( 'manage_categories' ) )
die('-1');
$r = wp_insert_term($_POST['name'], 'link_category', $_POST );
if ( is_wp_error( $r ) ) {
$x = new WP_AJAX_Response( array(
'what' => 'link-cat',
'id' => $r
) );
$x->send();
}
extract($r, EXTR_SKIP);
if ( !$link_cat = link_cat_row( $term_id ) )
die('0');
$x = new WP_Ajax_Response( array(
'what' => 'link-cat',
'id' => $term_id,
'data' => $link_cat
) );
$x->send();
break;
case 'add-comment' :
check_ajax_referer( $action );
if ( !current_user_can( 'edit_post', $id ) )