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:
parent
24f0b83cae
commit
1d0bf72d2f
|
@ -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 <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 ) )
|
||||
|
|
|
@ -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 = "<a href='link-category.php?action=edit&cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
|
||||
$default_cat_id = (int) get_option( 'default_link_category' );
|
||||
|
||||
if ( $category->term_id != $default_cat_id )
|
||||
$edit .= "<td><a href='" . wp_nonce_url( "link-category.php?action=delete&cat_ID=$category->term_id", 'delete-link-category_' . $category->term_id ) . "' onclick=\"return deleteSomething( 'cat', $category->term_id, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->name, get_term_field( 'name', $default_cat_id, 'link_category' ))) . "' );\" class='delete'>".__( 'Delete' )."</a>";
|
||||
else
|
||||
$edit .= "<td style='text-align:center'>".__( "Default" );
|
||||
} else {
|
||||
$edit = '';
|
||||
}
|
||||
|
||||
$class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
|
||||
|
||||
$category->count = number_format_i18n( $category->count );
|
||||
$count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
|
||||
return "<tr id='cat-$category->term_id'$class>
|
||||
<th scope='row' style='text-align: center'>$category->term_id</th>
|
||||
<td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td>
|
||||
<td>$category->description</td>
|
||||
<td align='center'>$count</td>
|
||||
<td>$edit</td>\n\t</tr>\n";
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if (isset($_GET['message'])) : ?>
|
||||
<div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
@ -61,7 +34,7 @@ function link_cat_row($category) {
|
|||
<th colspan="2" style="text-align: center"><?php _e('Action') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="the-list">
|
||||
<tbody id="the-list" class="list:link-cat">
|
||||
<?php
|
||||
$categories = get_terms( 'link_category', 'hide_empty=0' );
|
||||
if ( $categories ) {
|
||||
|
|
|
@ -9,7 +9,7 @@ if ( ! empty($cat_ID) ) {
|
|||
} else {
|
||||
$heading = __('Add Category');
|
||||
$submit_text = __('Add Category »');
|
||||
$form = '<form name="addcat" id="addcat" method="post" action="link-category.php">';
|
||||
$form = '<form name="addcat" id="addcat" class="add:the-list:" method="post" action="link-category.php">';
|
||||
$action = 'addcat';
|
||||
$nonce_action = 'add-link-category';
|
||||
do_action('add_link_category_form_pre', $category);
|
||||
|
|
|
@ -34,6 +34,8 @@ function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
|
|||
function _cat_row( $category, $level, $name_override = false ) {
|
||||
global $class;
|
||||
|
||||
$category = get_category( $category );
|
||||
|
||||
$pad = str_repeat( '— ', $level );
|
||||
if ( current_user_can( 'manage_categories' ) ) {
|
||||
$edit = "<a href='categories.php?action=edit&cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
|
||||
|
@ -47,7 +49,7 @@ function _cat_row( $category, $level, $name_override = false ) {
|
|||
} else
|
||||
$edit = '';
|
||||
|
||||
$class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
|
||||
$class = " class='alternate'" == $class ? '' : " class='alternate'";
|
||||
|
||||
$category->count = number_format_i18n( $category->count );
|
||||
$posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count;
|
||||
|
@ -61,6 +63,41 @@ function _cat_row( $category, $level, $name_override = false ) {
|
|||
return apply_filters('cat_row', $output);
|
||||
}
|
||||
|
||||
function link_cat_row( $category ) {
|
||||
global $class;
|
||||
|
||||
if ( !$category = get_term( $category, 'link_category' ) )
|
||||
return false;
|
||||
if ( is_wp_error( $category ) )
|
||||
return $category;
|
||||
|
||||
if ( current_user_can( 'manage_categories' ) ) {
|
||||
$edit = "<a href='link-category.php?action=edit&cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
|
||||
$default_cat_id = (int) get_option( 'default_link_category' );
|
||||
|
||||
$delete_url = wp_nonce_url( "link-category.php?action=delete&cat_ID=$category->term_id", "delete-link-category_$category->term_id" );
|
||||
if ( $category->term_id != $default_cat_id )
|
||||
$edit .= "<td><a href='$delete_url' class='delete:the-list:link-cat-$category->term_id delete'>" . __( 'Delete' ) . "</a>";
|
||||
else
|
||||
$edit .= "<td style='text-align:center'>" . __( "Default" );
|
||||
} else {
|
||||
$edit = '';
|
||||
}
|
||||
|
||||
$class = " class='alternate'" == $class ? '' : " class='alternate'";
|
||||
|
||||
$category->count = number_format_i18n( $category->count );
|
||||
$count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
|
||||
$output = "<tr id='link-cat-$category->term_id'$class>
|
||||
<th scope='row' style='text-align: center'>$category->term_id</th>
|
||||
<td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td>
|
||||
<td>$category->description</td>
|
||||
<td align='center'>$count</td>
|
||||
<td>$edit</td>\n\t</tr>\n";
|
||||
|
||||
return apply_filters( 'link_cat_row', $output );
|
||||
}
|
||||
|
||||
function checked( $checked, $current) {
|
||||
if ( $checked == $current)
|
||||
echo ' checked="checked"';
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
jQuery(function($) {
|
||||
var options = document.forms['addcat'].category_parent.options;
|
||||
var options = false
|
||||
if ( document.forms['addcat'].category_parent )
|
||||
options = document.forms['addcat'].category_parent.options;
|
||||
|
||||
var addAfter = function( r, settings ) {
|
||||
var name = $("<span>" + $('name', r).text() + "</span>").html();
|
||||
|
@ -14,5 +16,8 @@ jQuery(function($) {
|
|||
options[o] = null;
|
||||
}
|
||||
|
||||
var a = $('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } );
|
||||
if ( options )
|
||||
$('#the-list').wpList( { addAfter: addAfter, delAfter: delAfter } );
|
||||
else
|
||||
$('#the-list').wpList();
|
||||
});
|
||||
|
|
|
@ -115,7 +115,7 @@ class WP_Scripts {
|
|||
'add' => attribute_escape(__('Add')),
|
||||
'how' => __('Separate multiple categories with commas.')
|
||||
) );
|
||||
$this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20070823' );
|
||||
$this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' );
|
||||
$this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
|
||||
$this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20070822' );
|
||||
$this->add( 'admin-posts', '/wp-admin/js/edit-posts.js', array('wp-lists'), '20071023' );
|
||||
|
|
|
@ -118,34 +118,14 @@ if ( !defined('PLUGINDIR') )
|
|||
|
||||
require (ABSPATH . WPINC . '/compat.php');
|
||||
require (ABSPATH . WPINC . '/functions.php');
|
||||
require (ABSPATH . WPINC . '/classes.php');
|
||||
|
||||
require_wp_db();
|
||||
// $table_prefix is deprecated as of 2.1
|
||||
$wpdb->prefix = $table_prefix;
|
||||
$prefix = $wpdb->set_prefix($table_prefix);
|
||||
|
||||
if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') )
|
||||
if ( is_wp_error($prefix) )
|
||||
wp_die("<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.");
|
||||
|
||||
// Table names
|
||||
$wpdb->posts = $wpdb->prefix . 'posts';
|
||||
$wpdb->users = $wpdb->prefix . 'users';
|
||||
$wpdb->categories = $wpdb->prefix . 'categories';
|
||||
$wpdb->post2cat = $wpdb->prefix . 'post2cat';
|
||||
$wpdb->comments = $wpdb->prefix . 'comments';
|
||||
$wpdb->link2cat = $wpdb->prefix . 'link2cat';
|
||||
$wpdb->links = $wpdb->prefix . 'links';
|
||||
$wpdb->options = $wpdb->prefix . 'options';
|
||||
$wpdb->postmeta = $wpdb->prefix . 'postmeta';
|
||||
$wpdb->usermeta = $wpdb->prefix . 'usermeta';
|
||||
$wpdb->terms = $wpdb->prefix . 'terms';
|
||||
$wpdb->term_taxonomy = $wpdb->prefix . 'term_taxonomy';
|
||||
$wpdb->term_relationships = $wpdb->prefix . 'term_relationships';
|
||||
|
||||
if ( defined('CUSTOM_USER_TABLE') )
|
||||
$wpdb->users = CUSTOM_USER_TABLE;
|
||||
if ( defined('CUSTOM_USER_META_TABLE') )
|
||||
$wpdb->usermeta = CUSTOM_USER_META_TABLE;
|
||||
|
||||
if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
|
||||
require_once (ABSPATH . 'wp-content/object-cache.php');
|
||||
else
|
||||
|
@ -153,7 +133,6 @@ else
|
|||
|
||||
wp_cache_init();
|
||||
|
||||
require (ABSPATH . WPINC . '/classes.php');
|
||||
require (ABSPATH . WPINC . '/plugin.php');
|
||||
require (ABSPATH . WPINC . '/default-filters.php');
|
||||
include_once(ABSPATH . WPINC . '/streams.php');
|
||||
|
|
Loading…
Reference in New Issue