diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 64c9b06bda..a124d084ad 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -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’t delete the %s 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 ) ) diff --git a/wp-admin/edit-link-categories.php b/wp-admin/edit-link-categories.php index 3e05f5a88c..a036fa6aae 100644 --- a/wp-admin/edit-link-categories.php +++ b/wp-admin/edit-link-categories.php @@ -4,7 +4,7 @@ require_once('admin.php'); $title = __('Categories'); $parent_file = 'link-manager.php'; -//wp_enqueue_script( 'admin-categories' ); TODO: Fix AJAX +wp_enqueue_script( 'admin-categories' ); require_once ('admin-header.php'); $messages[1] = __('Category added.'); @@ -13,35 +13,8 @@ $messages[3] = __('Category updated.'); $messages[4] = __('Category not added.'); $messages[5] = __('Category not updated.'); -function link_cat_row($category) { - global $class; +if (isset($_GET['message'])) : ?> - if ( current_user_can( 'manage_categories' ) ) { - $edit = "".__( 'Edit' ).""; - $default_cat_id = (int) get_option( 'default_link_category' ); - - if ( $category->term_id != $default_cat_id ) - $edit .= "