Batch edit: allow removal of selected posts, prevent page parent lock.

git-svn-id: https://develop.svn.wordpress.org/trunk@9036 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2008-09-30 10:30:56 +00:00
parent c5d3cf7e06
commit f32c8bc427
10 changed files with 116 additions and 55 deletions
+33 -14
View File
@@ -177,7 +177,9 @@ function edit_post( $post_data = null ) {
return $post_ID;
}
// updates all bulk edited posts/pages, adding (but not removing) tags and categories. Skips pages when they would be their own parent or child.
function bulk_edit_posts( $post_data = null ) {
global $wpdb;
if ( empty($post_data) )
$post_data = &$_POST;
@@ -192,6 +194,12 @@ function bulk_edit_posts( $post_data = null ) {
$post_IDs = array_map( intval, (array) $post_data['post'] );
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category' );
foreach ( $reset as $field ) {
if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) )
unset($post_data[$field]);
}
if ( isset($post_data['post_category']) ) {
if ( is_array($post_data['post_category']) && ! empty($post_data['post_category']) )
$new_cats = array_map( absint, $post_data['post_category'] );
@@ -200,27 +208,38 @@ function bulk_edit_posts( $post_data = null ) {
}
if ( isset($post_data['tags_input']) ) {
if ( ! empty($post_data['tags_input']) ) {
$new_tags = preg_replace( '/\s*,\s*/', ',', rtrim($post_data['tags_input'], ' ,') );
$new_tags = explode(',', $new_tags);
} else {
unset($post_data['tags_input']);
$new_tags = preg_replace( '/\s*,\s*/', ',', rtrim( trim($post_data['tags_input']), ' ,' ) );
$new_tags = explode(',', $new_tags);
}
if ( isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent']) ) {
$pages = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'");
$children = array();
for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
$children[] = $parent;
foreach ( $pages as $page ) {
if ( $page->ID == $parent ) {
$parent = $page->post_parent;
break;
}
}
}
}
$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private' );
foreach ( $reset as $field ) {
if ( isset($post_data[$field]) && '' == $post_data[$field] )
unset($post_data[$field]);
}
$updated = $skipped = array();
$updated = $skipped = $locked = array();
foreach ( $post_IDs as $post_ID ) {
if ( wp_check_post_lock( $post_ID ) ) {
if ( isset($children) && in_array($post_ID, $children) ) {
$skipped[] = $post_ID;
continue;
}
if ( wp_check_post_lock( $post_ID ) ) {
$locked[] = $post_ID;
continue;
}
if ( isset($new_cats) ) {
$cats = (array) wp_get_post_categories($post_ID);
@@ -236,7 +255,7 @@ function bulk_edit_posts( $post_data = null ) {
$updated[] = wp_update_post( $post_data );
}
return array( 'upd' => $updated, 'skip' => $skipped );
return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked );
}
// Default post information to use when populating the "Write Post" form.
+4 -4
View File
@@ -693,7 +693,7 @@ function inline_edit_row( $type ) {
<div class="in">
<select name="post_parent">
<?php if ( $bulk ) { ?>
<option value=""><?php _e('- No Change -'); ?></option>
<option value="-1"><?php _e('- No Change -'); ?></option>
<?php } ?>
<option value="0"><?php _e('Main Page (no parent)'); ?></option>
<?php parent_dropdown(); ?>
@@ -706,7 +706,7 @@ function inline_edit_row( $type ) {
<div class="in">
<select name="page_template">
<?php if ( $bulk ) { ?>
<option value=""><?php _e('- No Change -'); ?></option>
<option value="-1"><?php _e('- No Change -'); ?></option>
<?php } ?>
<option value="default"><?php _e('Default Template'); ?></option>
<?php page_template_dropdown() ?>
@@ -784,7 +784,7 @@ function inline_edit_row( $type ) {
<div class="title"><?php _e('Author'); ?></div>
<div class="in">
<?php
$users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors');
$users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1);
if ( $bulk ) $users_opt['show_option_none'] = __('- No Change -');
wp_dropdown_users( $users_opt ); ?>
</div>
@@ -809,7 +809,7 @@ function inline_edit_row( $type ) {
<div class="in">
<select name="_status">
<?php if ( $bulk ) { ?>
<option value=""><?php _e('- No Change -'); ?></option>
<option value="-1"><?php _e('- No Change -'); ?></option>
<?php if ( $can_publish ) { ?>
<option value="private"><?php _e('Private') ?></option>
<?php } ?>