Skip to content

Commit 603dbcd

Browse files
committed
Quick Edit for Tags, Categories and Link Categories, improvements to handling errors in quick and bulk edit.
git-svn-id: https://develop.svn.wordpress.org/trunk@9083 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f151d5e commit 603dbcd

13 files changed

Lines changed: 417 additions & 100 deletions

wp-admin/admin-ajax.php

Lines changed: 93 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -730,19 +730,49 @@
730730
break;
731731
case 'inline-save':
732732
check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
733-
734-
if ( ! isset($_POST['post_ID']) || ! ( $id = (int) $_POST['post_ID'] ) )
733+
734+
if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
735735
exit;
736736

737-
if ( $last = wp_check_post_lock( $id ) ) {
737+
if ( 'page' == $_POST['post_type'] ) {
738+
if ( ! current_user_can( 'edit_page', $post_ID ) )
739+
die( __('You are not allowed to edit this page.') );
740+
} else {
741+
if ( ! current_user_can( 'edit_post', $post_ID ) )
742+
die( __('You are not allowed to edit this post.') );
743+
}
744+
745+
if ( $last = wp_check_post_lock( $post_ID ) ) {
738746
$last_user = get_userdata( $last );
739747
$last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
740-
echo '<tr><td colspan="8"><div class="error"><p>' . sprintf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), wp_specialchars( $last_user_name ) ) . '</p></div></td></tr>';
748+
printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), wp_specialchars( $last_user_name ) );
741749
exit;
742750
}
743-
744-
inline_save_row( $_POST );
745-
751+
752+
$data = &$_POST;
753+
$post = get_post( $post_ID, ARRAY_A );
754+
$data['content'] = $post['post_content'];
755+
$data['excerpt'] = $post['post_excerpt'];
756+
757+
// rename
758+
$data['user_ID'] = $GLOBALS['user_ID'];
759+
$data['parent_id'] = $data['post_parent'];
760+
761+
// status
762+
if ( 'private' == $data['keep_private'] )
763+
$data['post_status'] = 'private';
764+
else
765+
$data['post_status'] = $data['_status'];
766+
767+
if ( empty($data['comment_status']) )
768+
$data['comment_status'] = 'closed';
769+
if ( empty($data['ping_status']) )
770+
$data['ping_status'] = 'closed';
771+
772+
// update the post
773+
$_POST = $data;
774+
edit_post();
775+
746776
$post = array();
747777
if ( 'page' == $_POST['post_type'] ) {
748778
$post[] = get_post($_POST['post_ID']);
@@ -752,7 +782,61 @@
752782
$post[] = get_post($_POST['post_ID']);
753783
post_rows($post);
754784
}
755-
die();
785+
786+
exit;
787+
break;
788+
case 'inline-save-tax':
789+
check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
790+
791+
if ( ! current_user_can('manage_categories') )
792+
die( '<tr colspan="6"><td>' . __('Cheatin&#8217; uh?') . '</td></tr>' );
793+
794+
if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
795+
exit;
796+
797+
switch ($_POST['tax_type']) {
798+
case 'cat' :
799+
$data = array();
800+
$data['cat_ID'] = $id;
801+
$data['cat_name'] = $_POST['name'];
802+
$data['category_nicename'] = $_POST['slug'];
803+
if ( isset($_POST['parent']) && (int) $_POST['parent'] > 0 )
804+
$data['category_parent'] = $_POST['parent'];
805+
806+
$updated = wp_update_category($data);
807+
808+
if ( $updated && !is_wp_error($updated) )
809+
echo _cat_row( $id, 0 );
810+
else
811+
die( __('Category not updated.') );
812+
813+
break;
814+
case 'link-cat' :
815+
$updated = wp_update_term($id, 'link_category', $_POST);
816+
817+
if ( $updated && !is_wp_error($updated) )
818+
echo link_cat_row($id);
819+
else
820+
die( __('Category not updated.') );
821+
822+
break;
823+
case 'tag' :
824+
$updated = wp_update_term($id, 'post_tag', $_POST);
825+
826+
if ( $updated && !is_wp_error($updated) ) {
827+
$tag = get_term( $id, 'post_tag' );
828+
if ( !$tag || is_wp_error( $tag ) )
829+
die( __('Tag not updated.') );
830+
831+
echo _tag_row($tag);
832+
} else {
833+
die( __('Tag not updated.') );
834+
}
835+
836+
break;
837+
}
838+
839+
exit;
756840
break;
757841
case 'meta-box-order':
758842
check_ajax_referer( 'meta-box-order' );
@@ -803,7 +887,7 @@
803887
$stat = __('Unpublished');
804888
break;
805889
}
806-
890+
807891
if ( '0000-00-00 00:00:00' == $post->post_date ) {
808892
$time = '';
809893
} else {

wp-admin/categories.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111

112112
wp_enqueue_script( 'admin-categories' );
113113
wp_enqueue_script('admin-forms');
114+
if ( current_user_can('manage_categories') )
115+
wp_enqueue_script('inline-edit-tax');
114116

115117
require_once ('admin-header.php');
116118

@@ -235,6 +237,7 @@
235237

236238
<?php include('edit-category-form.php'); ?>
237239

240+
<?php inline_edit_term_row('category'); ?>
238241
<?php endif; ?>
239242

240243
<?php

wp-admin/edit-link-categories.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
wp_enqueue_script( 'admin-categories' );
5050
wp_enqueue_script('admin-forms');
51+
if ( current_user_can('manage_categories') )
52+
wp_enqueue_script('inline-edit-tax');
5153

5254
require_once ('admin-header.php');
5355

@@ -183,6 +185,7 @@
183185
</div>
184186

185187
<?php include('edit-link-category-form.php'); ?>
188+
<?php inline_edit_term_row('link-category'); ?>
186189

187190
<?php endif; ?>
188191

wp-admin/edit-pages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
$title = __('View All Pages');
7070
$parent_file = 'edit.php';
7171
wp_enqueue_script('admin-forms');
72-
wp_enqueue_script('inline-edit');
72+
wp_enqueue_script('inline-edit-post');
7373
wp_enqueue_script('pages');
7474

7575
$post_stati = array( // array( adj, noun )

wp-admin/edit-tags.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@
115115

116116
wp_enqueue_script( 'admin-tags' );
117117
wp_enqueue_script('admin-forms');
118+
if ( current_user_can('manage_categories') )
119+
wp_enqueue_script('inline-edit-tax');
118120

119121
require_once ('admin-header.php');
120122

@@ -187,7 +189,7 @@
187189

188190
<div class="clear"></div>
189191

190-
<table class="widefat">
192+
<table class="widefat tag">
191193
<thead>
192194
<tr>
193195
<?php print_column_headers('tag'); ?>
@@ -236,6 +238,7 @@
236238

237239
<br />
238240
<?php include('edit-tag-form.php'); ?>
241+
<?php inline_edit_term_row('tag'); ?>
239242

240243
<?php endif; ?>
241244

wp-admin/edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
$title = __('View All Posts');
7171
$parent_file = 'edit.php';
7272
wp_enqueue_script('admin-forms');
73-
wp_enqueue_script('inline-edit');
73+
wp_enqueue_script('inline-edit-post');
7474
wp_enqueue_script('posts');
7575

7676
list($post_stati, $avail_post_stati) = wp_edit_posts_query();

0 commit comments

Comments
 (0)