mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Consolidate post update code.
git-svn-id: https://develop.svn.wordpress.org/trunk@2650 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
+1
-163
@@ -117,117 +117,7 @@ case 'edit':
|
||||
break;
|
||||
|
||||
case 'editpost':
|
||||
// die(var_dump('<pre>', $_POST));
|
||||
if (!isset($blog_ID)) {
|
||||
$blog_ID = 1;
|
||||
}
|
||||
$post_ID = $_POST['post_ID'];
|
||||
|
||||
if (!user_can_edit_post($user_ID, $post_ID, $blog_ID))
|
||||
die( __('You are not allowed to edit this post.') );
|
||||
|
||||
$post_categories = $_POST['post_category'];
|
||||
if (!$post_categories) $post_categories[] = 1;
|
||||
$content = apply_filters('content_save_pre', $_POST['content']);
|
||||
$excerpt = apply_filters('excerpt_save_pre', $_POST['excerpt']);
|
||||
$post_title = $_POST['post_title'];
|
||||
$prev_status = $_POST['prev_status'];
|
||||
$post_status = $_POST['post_status'];
|
||||
$menu_order = (int) $_POST['menu_order'];
|
||||
if (! empty($_POST['post_author_override'])) {
|
||||
$post_author = (int) $_POST['post_author_override'];
|
||||
} else if (! empty($_POST['post_author'])) {
|
||||
$post_author = (int) $_POST['post_author'];
|
||||
} else {
|
||||
$post_author = (int) $_POST['user_ID'];
|
||||
}
|
||||
if ( !user_can_edit_user($user_ID, $post_author) )
|
||||
die( __('You cannot post as this user.') );
|
||||
|
||||
$comment_status = $_POST['comment_status'];
|
||||
if (empty($comment_status)) $comment_status = 'closed';
|
||||
//if (!$_POST['comment_status']) $comment_status = get_settings('default_comment_status');
|
||||
|
||||
$ping_status = $_POST['ping_status'];
|
||||
if (empty($ping_status)) $ping_status = 'closed';
|
||||
//if (!$_POST['ping_status']) $ping_status = get_settings('default_ping_status');
|
||||
$post_password = $_POST['post_password'];
|
||||
$post_name = $_POST['post_name'];
|
||||
|
||||
$post_parent = 0;
|
||||
if (isset($_POST['parent_id'])) {
|
||||
$post_parent = $_POST['parent_id'];
|
||||
}
|
||||
|
||||
$trackback = $_POST['trackback_url'];
|
||||
// Format trackbacks
|
||||
$trackback = preg_replace('|\s+|', '\n', $trackback);
|
||||
|
||||
if (isset($_POST['publish'])) $post_status = 'publish';
|
||||
// Double-check
|
||||
if ( 'publish' == $post_status && (!user_can_create_post($user_ID)) )
|
||||
$post_status = 'draft';
|
||||
|
||||
if ( empty($post_name) ) {
|
||||
if ( 'draft' != $post_status )
|
||||
$post_name = sanitize_title($post_title, $post_ID);
|
||||
} else {
|
||||
$post_name = sanitize_title($post_name, $post_ID);
|
||||
}
|
||||
|
||||
if ('publish' == $post_status) {
|
||||
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
|
||||
if ($post_name_check) {
|
||||
$suffix = 2;
|
||||
while ($post_name_check) {
|
||||
$alt_post_name = $post_name . "-$suffix";
|
||||
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1");
|
||||
$suffix++;
|
||||
}
|
||||
$post_name = $alt_post_name;
|
||||
}
|
||||
}
|
||||
|
||||
if (user_can_edit_post_date($user_ID, $post_ID) && (!empty($_POST['edit_date']))) {
|
||||
$aa = $_POST['aa'];
|
||||
$mm = $_POST['mm'];
|
||||
$jj = $_POST['jj'];
|
||||
$hh = $_POST['hh'];
|
||||
$mn = $_POST['mn'];
|
||||
$ss = $_POST['ss'];
|
||||
$jj = ($jj > 31) ? 31 : $jj;
|
||||
$hh = ($hh > 23) ? $hh - 24 : $hh;
|
||||
$mn = ($mn > 59) ? $mn - 60 : $mn;
|
||||
$ss = ($ss > 59) ? $ss - 60 : $ss;
|
||||
$datemodif = ", post_date = '$aa-$mm-$jj $hh:$mn:$ss'";
|
||||
$datemodif_gmt = ", post_date_gmt = '".get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss")."'";
|
||||
} else {
|
||||
$datemodif = '';
|
||||
$datemodif_gmt = '';
|
||||
}
|
||||
|
||||
$now = current_time('mysql');
|
||||
$now_gmt = current_time('mysql', 1);
|
||||
|
||||
$result = $wpdb->query("
|
||||
UPDATE $wpdb->posts SET
|
||||
post_content = '$content',
|
||||
post_excerpt = '$excerpt',
|
||||
post_title = '$post_title'"
|
||||
.$datemodif_gmt
|
||||
.$datemodif.",
|
||||
post_status = '$post_status',
|
||||
comment_status = '$comment_status',
|
||||
ping_status = '$ping_status',
|
||||
post_author = '$post_author',
|
||||
post_password = '$post_password',
|
||||
post_name = '$post_name',
|
||||
to_ping = '$trackback',
|
||||
post_modified = '$now',
|
||||
post_modified_gmt = '$now_gmt',
|
||||
menu_order = '$menu_order',
|
||||
post_parent = '$post_parent'
|
||||
WHERE ID = $post_ID ");
|
||||
edit_post();
|
||||
|
||||
if ($_POST['save']) {
|
||||
$location = $_SERVER['HTTP_REFERER'];
|
||||
@@ -244,58 +134,6 @@ case 'editpost':
|
||||
}
|
||||
header ('Location: ' . $location); // Send user on their way while we keep working
|
||||
|
||||
// Meta Stuff
|
||||
if ($_POST['meta']) :
|
||||
foreach ($_POST['meta'] as $key => $value) :
|
||||
update_meta($key, $value['key'], $value['value']);
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
if ($_POST['deletemeta']) :
|
||||
foreach ($_POST['deletemeta'] as $key => $value) :
|
||||
delete_meta($key);
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
add_meta($post_ID);
|
||||
|
||||
// Now it's category time!
|
||||
// First the old categories
|
||||
$old_categories = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = $post_ID");
|
||||
|
||||
// Delete any?
|
||||
foreach ($old_categories as $old_cat) {
|
||||
if (!in_array($old_cat, $post_categories)) // If a category was there before but isn't now
|
||||
$wpdb->query("DELETE FROM $wpdb->post2cat WHERE category_id = $old_cat AND post_id = $post_ID LIMIT 1");
|
||||
}
|
||||
|
||||
// Add any?
|
||||
foreach ($post_categories as $new_cat) {
|
||||
if (!in_array($new_cat, $old_categories))
|
||||
$wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_ID, $new_cat)");
|
||||
}
|
||||
|
||||
if ($prev_status != 'publish' && $post_status == 'publish')
|
||||
do_action('private_to_published', $post_ID);
|
||||
|
||||
do_action('edit_post', $post_ID);
|
||||
|
||||
if ($post_status == 'publish') {
|
||||
do_action('publish_post', $post_ID);
|
||||
do_trackbacks($post_ID);
|
||||
do_enclose( $content, $post_ID );
|
||||
if ( get_option('default_pingback_flag') )
|
||||
pingback($content, $post_ID);
|
||||
}
|
||||
|
||||
if ($post_status == 'static') {
|
||||
generate_page_rewrite_rules();
|
||||
|
||||
if ( ! update_post_meta($post_ID, '_wp_page_template', $_POST['page_template'])) {
|
||||
add_post_meta($post_ID, '_wp_page_template', $_POST['page_template'], true);
|
||||
}
|
||||
}
|
||||
|
||||
exit();
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user