diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 4af1775b8..950ec1361 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -730,19 +730,49 @@ case 'sample-permalink': break; case 'inline-save': check_ajax_referer( 'inlineeditnonce', '_inline_edit' ); - - if ( ! isset($_POST['post_ID']) || ! ( $id = (int) $_POST['post_ID'] ) ) + + if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) ) exit; - if ( $last = wp_check_post_lock( $id ) ) { + if ( 'page' == $_POST['post_type'] ) { + if ( ! current_user_can( 'edit_page', $post_ID ) ) + die( __('You are not allowed to edit this page.') ); + } else { + if ( ! current_user_can( 'edit_post', $post_ID ) ) + die( __('You are not allowed to edit this post.') ); + } + + if ( $last = wp_check_post_lock( $post_ID ) ) { $last_user = get_userdata( $last ); $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); - echo '

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

'; + 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 ) ); exit; } - - inline_save_row( $_POST ); - + + $data = &$_POST; + $post = get_post( $post_ID, ARRAY_A ); + $data['content'] = $post['post_content']; + $data['excerpt'] = $post['post_excerpt']; + + // rename + $data['user_ID'] = $GLOBALS['user_ID']; + $data['parent_id'] = $data['post_parent']; + + // status + if ( 'private' == $data['keep_private'] ) + $data['post_status'] = 'private'; + else + $data['post_status'] = $data['_status']; + + if ( empty($data['comment_status']) ) + $data['comment_status'] = 'closed'; + if ( empty($data['ping_status']) ) + $data['ping_status'] = 'closed'; + + // update the post + $_POST = $data; + edit_post(); + $post = array(); if ( 'page' == $_POST['post_type'] ) { $post[] = get_post($_POST['post_ID']); @@ -752,7 +782,61 @@ case 'inline-save': $post[] = get_post($_POST['post_ID']); post_rows($post); } - die(); + + exit; + break; +case 'inline-save-tax': + check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' ); + + if ( ! current_user_can('manage_categories') ) + die( '' . __('Cheatin’ uh?') . '' ); + + if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) ) + exit; + + switch ($_POST['tax_type']) { + case 'cat' : + $data = array(); + $data['cat_ID'] = $id; + $data['cat_name'] = $_POST['name']; + $data['category_nicename'] = $_POST['slug']; + if ( isset($_POST['parent']) && (int) $_POST['parent'] > 0 ) + $data['category_parent'] = $_POST['parent']; + + $updated = wp_update_category($data); + + if ( $updated && !is_wp_error($updated) ) + echo _cat_row( $id, 0 ); + else + die( __('Category not updated.') ); + + break; + case 'link-cat' : + $updated = wp_update_term($id, 'link_category', $_POST); + + if ( $updated && !is_wp_error($updated) ) + echo link_cat_row($id); + else + die( __('Category not updated.') ); + + break; + case 'tag' : + $updated = wp_update_term($id, 'post_tag', $_POST); + + if ( $updated && !is_wp_error($updated) ) { + $tag = get_term( $id, 'post_tag' ); + if ( !$tag || is_wp_error( $tag ) ) + die( __('Tag not updated.') ); + + echo _tag_row($tag); + } else { + die( __('Tag not updated.') ); + } + + break; + } + + exit; break; case 'meta-box-order': check_ajax_referer( 'meta-box-order' ); @@ -803,7 +887,7 @@ case 'find_posts': $stat = __('Unpublished'); break; } - + if ( '0000-00-00 00:00:00' == $post->post_date ) { $time = ''; } else { diff --git a/wp-admin/categories.php b/wp-admin/categories.php index 2322770cd..bb5bef8ac 100644 --- a/wp-admin/categories.php +++ b/wp-admin/categories.php @@ -111,6 +111,8 @@ if ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) { wp_enqueue_script( 'admin-categories' ); wp_enqueue_script('admin-forms'); +if ( current_user_can('manage_categories') ) + wp_enqueue_script('inline-edit-tax'); require_once ('admin-header.php'); @@ -235,6 +237,7 @@ if ( $page_links ) + + diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php index 49e8ff455..3cd056f38 100644 --- a/wp-admin/edit-pages.php +++ b/wp-admin/edit-pages.php @@ -69,7 +69,7 @@ if ( empty($title) ) $title = __('View All Pages'); $parent_file = 'edit.php'; wp_enqueue_script('admin-forms'); -wp_enqueue_script('inline-edit'); +wp_enqueue_script('inline-edit-post'); wp_enqueue_script('pages'); $post_stati = array( // array( adj, noun ) diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php index 20fcd3aa8..4fa886e7e 100644 --- a/wp-admin/edit-tags.php +++ b/wp-admin/edit-tags.php @@ -115,6 +115,8 @@ if ( isset($_GET['_wp_http_referer']) && ! empty($_GET['_wp_http_referer']) ) { wp_enqueue_script( 'admin-tags' ); wp_enqueue_script('admin-forms'); +if ( current_user_can('manage_categories') ) + wp_enqueue_script('inline-edit-tax'); require_once ('admin-header.php'); @@ -187,7 +189,7 @@ if ( $page_links )
- +
@@ -236,6 +238,7 @@ if ( $page_links )
+ diff --git a/wp-admin/edit.php b/wp-admin/edit.php index 0066f54b8..167f19039 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -70,7 +70,7 @@ if ( empty($title) ) $title = __('View All Posts'); $parent_file = 'edit.php'; wp_enqueue_script('admin-forms'); -wp_enqueue_script('inline-edit'); +wp_enqueue_script('inline-edit-post'); wp_enqueue_script('posts'); list($post_stati, $avail_post_stati) = wp_edit_posts_query(); diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index d15616294..7ba76e84b 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -123,6 +123,7 @@ function _cat_row( $category, $level, $name_override = false ) { $edit = "name)) . "'>" . attribute_escape( $name ) . '
'; $actions = array(); $actions['edit'] = '' . __('Edit') . ''; + $actions['inline hide-if-no-js'] = '' . __('Quick Edit') . ''; if ( $default_cat_id != $category->term_id ) $actions['delete'] = "term_id) . "' onclick=\"if ( confirm('" . js_escape(sprintf(__("You are about to delete this category '%s'\n 'Cancel' to stop, 'OK' to delete."), $name )) . "') ) { return true;}return false;\">" . __('Delete') . ""; $action_count = count($actions); @@ -136,11 +137,11 @@ function _cat_row( $category, $level, $name_override = false ) { $edit = $name; } - $class = " class='alternate'" == $class ? '' : " class='alternate'"; + $class = 'alternate' == $class ? '' : 'alternate'; $category->count = number_format_i18n( $category->count ); $posts_count = ( $category->count > 0 ) ? "$category->count" : $category->count; - $output = ""; + $output = ""; $columns = get_column_headers('category'); $hidden = (array) get_user_option( 'manage-category-columns-hidden' ); @@ -164,7 +165,11 @@ function _cat_row( $category, $level, $name_override = false ) { $output .= ''; break; case 'name': - $output .= ""; + $output .= "'; break; case 'description': $output .= ""; @@ -182,6 +187,86 @@ function _cat_row( $category, $level, $name_override = false ) { return apply_filters('cat_row', $output); } +/** + * {@internal Missing Short Description}} + * + * @since 2.7 + * + * Outputs the HTML for the hidden table rows used in Categories, Link Caregories and Tags quick edit. + * + * @param string $type "tag", "category" or "link-category" + * @return + */ +function inline_edit_term_row($type) { + + if ( ! current_user_can( 'manage_categories' ) ) + return; + + $is_tag = $type == 'tag'; + $columns = $is_tag ? get_column_headers('tag') : get_column_headers('category'); + $hidden = (array) get_user_option( "manage-$type-columns-hidden" ); ?> + +
$edit$edit"; + $output .= '$category->description
+ "; + break; + case 'slug': ?> +
title=""> +
+
+ +
+
+ $category->slug"; + break; + case 'posts': + if ( 'category' == $type ) { ?> +
title=""> +
+
+ 0, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('None'))); ?> +
+
+ +
+
+ + + + +
+ +
+name)) . "'>$name
"; $actions = array(); $actions['edit'] = '' . __('Edit') . ''; + $actions['inline hide-if-no-js'] = '' . __('Quick Edit') . ''; if ( $default_cat_id != $category->term_id ) $actions['delete'] = "term_id) . "' onclick=\"if ( confirm('" . js_escape(sprintf(__("You are about to delete this category '%s'\n 'Cancel' to stop, 'OK' to delete."), $name )) . "') ) { return true;}return false;\">" . __('Delete') . ""; $action_count = count($actions); @@ -219,11 +305,11 @@ function link_cat_row( $category, $name_override = false ) { $edit = $name; } - $class = " class='alternate'" == $class ? '' : " class='alternate'"; + $class = 'alternate' == $class ? '' : 'alternate'; $category->count = number_format_i18n( $category->count ); $count = ( $category->count > 0 ) ? "$category->count" : $category->count; - $output = ""; + $output = ""; $columns = get_column_headers('link-category'); $hidden = (array) get_user_option( 'manage-link-category-columns-hidden' ); foreach ( $columns as $column_name => $column_display_name ) { @@ -246,7 +332,11 @@ function link_cat_row( $category, $name_override = false ) { $output .= ""; break; case 'name': - $output .= "$edit"; + $output .= "$edit"; + $output .= ''; break; case 'description': $output .= "$category->description"; @@ -517,6 +607,7 @@ function _tag_row( $tag, $class = '' ) { $out .= '' . $name . '
'; $actions = array(); $actions['edit'] = '' . __('Edit') . ''; + $actions['inline hide-if-no-js'] = '' . __('Quick Edit') . ''; $actions['delete'] = "term_id) . "' onclick=\"if ( confirm('" . js_escape(sprintf(__("You are about to delete this tag '%s'\n 'Cancel' to stop, 'OK' to delete."), $name )) . "') ) { return true;}return false;\">" . __('Delete') . ""; $action_count = count($actions); $i = 0; @@ -525,7 +616,9 @@ function _tag_row( $tag, $class = '' ) { ( $i == $action_count ) ? $sep = '' : $sep = ' | '; $out .= "$link$sep"; } - $out .= ''; + $out .= ''; break; case 'slug': $out .= "$tag->slug"; @@ -573,7 +666,7 @@ function tag_rows( $page = 1, $pagesize = 20, $searchterms = '' ) { $class = ''; $count = 0; foreach( $tags as $tag ) - $out .= _tag_row( $tag, ++$count % 2 ? ' class="alternate"' : '' ); + $out .= _tag_row( $tag, ++$count % 2 ? ' class="iedit alternate"' : ' class="iedit"' ); // filter and send to screen $out = apply_filters('tag_rows', $out); @@ -745,7 +838,7 @@ function get_column_headers($page) { 'posts' => __('Posts') ); return apply_filters('manage_users_columns', $columns); - default : + default : return apply_filters('manage_' . $page . '_columns', $columns); } @@ -799,9 +892,11 @@ function print_column_headers( $type, $id = true ) { /** * {@internal Missing Short Description}} * - * @since unknown + * Outputs the quick edit and bulk edit table rows + * + * @since 2.7 * - * @param unknown_type $type + * @param string $type 'post' or 'page' */ function inline_edit_row( $type ) { global $current_user, $mode; @@ -823,7 +918,7 @@ function inline_edit_row( $type ) { - + $column_display_name) { @@ -968,7 +1063,7 @@ function inline_edit_row( $type ) {
title="">
- $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1); if ( $bulk ) $users_opt['show_option_none'] = __('- No Change -'); wp_dropdown_users( $users_opt ); ?> @@ -1045,40 +1140,6 @@ function inline_edit_row( $type ) { post_type, $post->ID) ) return; - + $title = _draft_or_post_title($post->ID); echo ' @@ -1114,13 +1175,13 @@ function get_inline_data($post) {
' . $post->post_parent . '
' . wp_specialchars(get_post_meta( $post->ID, '_wp_page_template', true ), 1) . '
'; - + if( $post->post_type == 'post' ) echo '
' . wp_specialchars( str_replace( ',', ', ', get_tags_to_edit($post->ID) ), 1) . '
' . (is_sticky($post->ID) ? 'sticky' : '') . '
'; - + echo '
'; } @@ -1231,7 +1292,7 @@ function _post_row($a_post, $pending_comments, $mode) { echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode); else echo '' . apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) . ''; - + echo ''; break; @@ -1476,7 +1537,7 @@ foreach ($posts_columns as $column_name=>$column_display_name) { ( $i == $action_count ) ? $sep = '' : $sep = ' | '; echo "$link$sep"; } - + get_inline_data($post); echo ''; break; @@ -2974,7 +3035,7 @@ function _draft_or_post_title($post_id = 0) { $title = get_the_title($post_id); if ( empty($title) ) - $title = __('(no title)'); + $title = __('(no title)'); return $title; } diff --git a/wp-admin/js/inline-edit.js b/wp-admin/js/inline-edit-post.js similarity index 81% rename from wp-admin/js/inline-edit.js rename to wp-admin/js/inline-edit-post.js index e11fce0c7..386cf5f3f 100644 --- a/wp-admin/js/inline-edit.js +++ b/wp-admin/js/inline-edit-post.js @@ -1,6 +1,6 @@ (function($) { -inlineEdit = { +inlineEditPost = { init : function() { var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit'); @@ -12,20 +12,20 @@ inlineEdit = { t.rows = $('tr.iedit'); // prepare the edit row - qeRow.dblclick(function() { inlineEdit.toggle(this); }) - .keyup(function(e) { if(e.which == 27) return inlineEdit.revert(); }); + qeRow.dblclick(function() { inlineEditPost.toggle(this); }) + .keyup(function(e) { if(e.which == 27) return inlineEditPost.revert(); }); - bulkRow.dblclick(function() { inlineEdit.revert(); }) - .keyup(function(e) { if (e.which == 27) return inlineEdit.revert(); }); + bulkRow.dblclick(function() { inlineEditPost.revert(); }) + .keyup(function(e) { if (e.which == 27) return inlineEditPost.revert(); }); - $('a.cancel', qeRow).click(function() { return inlineEdit.revert(); }); - $('a.save', qeRow).click(function() { return inlineEdit.save(this); }); + $('a.cancel', qeRow).click(function() { return inlineEditPost.revert(); }); + $('a.save', qeRow).click(function() { return inlineEditPost.save(this); }); - $('a.cancel', bulkRow).click(function() { return inlineEdit.revert(); }); - $('a.save', bulkRow).click(function() { return inlineEdit.saveBulk(); }); + $('a.cancel', bulkRow).click(function() { return inlineEditPost.revert(); }); + $('a.save', bulkRow).click(function() { return inlineEditPost.saveBulk(); }); // add events - t.rows.dblclick(function() { inlineEdit.toggle(this); }); + t.rows.dblclick(function() { inlineEditPost.toggle(this); }); t.addEvents(t.rows); $('#bulk-title-div').after( @@ -65,12 +65,12 @@ inlineEdit = { t.revert(); } }); - + $('#post-query-submit').click(function(e){ if ( $('form#posts-filter tr.inline-editor').length > 0 ) t.revert(); }); - + }, toggle : function(el) { @@ -82,7 +82,7 @@ inlineEdit = { addEvents : function(r) { r.each(function() { var row = $(this); - $('a.editinline', row).click(function() { inlineEdit.edit(this); return false; }); + $('a.editinline', row).click(function() { inlineEditPost.edit(this); return false; }); row.attr('title', inlineEditL10n.edit); }); }, @@ -104,7 +104,7 @@ inlineEdit = { $('#bulk-titles').html(te); $('#bulk-titles a').click(function() { - var id = $(this).attr('id').substr(1), r = inlineEdit.type+'-'+id; + var id = $(this).attr('id').substr(1), r = inlineEditPost.type+'-'+id; $('table.widefat input[value="'+id+'"]').attr('checked', ''); $('#ttle'+id).remove(); @@ -186,7 +186,7 @@ inlineEdit = { if( typeof(id) == 'object' ) id = this.getId(id); - $('#edit-'+id+' .check-column').html(''); + $('#edit-'+id+'.quick-edit-save').append(''); var params = { action: 'inline-save', @@ -201,12 +201,17 @@ inlineEdit = { // make ajax request $.post('admin-ajax.php', params, function(r) { - var row = $(inlineEdit.what+id); - $('#edit-'+id).remove(); - row.html($(r).html()).show() - .animate( { backgroundColor: '#CCEEBB' }, 500) - .animate( { backgroundColor: '#eefee7' }, 500); - inlineEdit.addEvents(row); + var row = $(inlineEditPost.what+id); + + if (r) { + $('#edit-'+id).remove(); + row.html($(r).html()).show() + .animate( { backgroundColor: '#CCEEBB' }, 500) + .animate( { backgroundColor: '#eefee7' }, 500); + inlineEditPost.addEvents(row); + } else { + $('#edit-'+id+' .quick-edit-save').append(''+inlineEditL10n.error+''); + } } ); return false; @@ -241,5 +246,5 @@ inlineEdit = { } }; -$(document).ready(function(){inlineEdit.init();}); +$(document).ready(function(){inlineEditPost.init();}); })(jQuery); diff --git a/wp-admin/js/inline-edit-tax.js b/wp-admin/js/inline-edit-tax.js new file mode 100644 index 000000000..129b2fbd4 --- /dev/null +++ b/wp-admin/js/inline-edit-tax.js @@ -0,0 +1,145 @@ + +(function($) { +inlineEditTax = { + + init : function() { + var t = this, row = $('#inline-edit'); + + t.type = $('#the-list').attr('className').substr(5); + t.what = '#'+t.type+'-'; + + // get all editable rows + t.rows = $('tr.iedit'); + + // prepare the edit row + row.dblclick(function() { inlineEditTax.toggle(this); }) + .keyup(function(e) { if(e.which == 27) return inlineEditTax.revert(); }); + + $('a.cancel', row).click(function() { return inlineEditTax.revert(); }); + $('a.save', row).click(function() { return inlineEditTax.save(this); }); + + // add events + t.rows.dblclick(function() { inlineEditTax.toggle(this); }); + t.addEvents(t.rows); + + $('#doaction, #doaction2, #post-query-submit').click(function(e){ + if ( $('form#posts-filter tr.inline-editor').length > 0 ) + t.revert(); + }); + }, + + toggle : function(el) { + var t = this; + + $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el); + }, + + addEvents : function(r) { + r.each(function() { + var row = $(this); + $('a.editinline', row).click(function() { inlineEditTax.edit(this); return false; }); + row.attr('title', inlineEditL10n.edit); + }); + }, + + edit : function(id) { + var t = this; + t.revert(); + + if ( typeof(id) == 'object' ) + id = t.getId(id); + + var editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id); + + if ( $(t.what+id).hasClass('alternate') ) + $(editRow).addClass('alternate'); + + $(t.what+id).hide().after(editRow); + + $(':input[name="name"]', editRow).val( $('.name', rowData).text() ); + $(':input[name="slug"]', editRow).val( $('.slug', rowData).text() ); + + // cat parents + var cat_parent = $('.cat_parent', rowData).text(); + if ( cat_parent != '0' ) + $('select[name="parent"]', editRow).val(cat_parent); + + // remove the current parent and children from the parent dropdown + var pageOpt = $('select[name="parent"] option[value="'+id+'"]', editRow); + if ( pageOpt.length > 0 ) { + var pageLevel = pageOpt[0].className.split('-')[1], nextPage = pageOpt, pageLoop = true; + while ( pageLoop ) { + var nextPage = nextPage.next('option'), nextLevel = nextPage[0].className.split('-')[1]; + if ( nextLevel <= pageLevel ) { + pageLoop = false; + } else { + nextPage.remove(); + nextPage = pageOpt; + } + } + pageOpt.remove(); + } + + $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); + $('.ptitle', editRow).eq(0).focus(); + + return false; + }, + + save : function(id) { + if( typeof(id) == 'object' ) + id = this.getId(id); + + $('#edit-'+id+'.quick-edit-save').append(''); + + var params = { + action: 'inline-save-tax', + tax_type: this.type, + tax_ID: id + }; + + var fields = $('#edit-'+id+' :input').fieldSerialize(); + params = fields + '&' + $.param(params); + + // make ajax request + $.post('admin-ajax.php', params, + function(r) { + var row = $(inlineEditTax.what+id); + + if (r) { + if ( -1 != r.indexOf('name, $category); - $output .= "\t