From 75432d53b00287138a26406f0738eafd7656a53c Mon Sep 17 00:00:00 2001 From: azaozz Date: Thu, 29 Sep 2011 21:47:52 +0000 Subject: [PATCH] Clean up remnants from having negative Post_IDs, props markjaquith, fixes #18235 git-svn-id: http://svn.automattic.com/wordpress/trunk@18823 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-advanced.php | 1 - wp-admin/includes/media.php | 6 ++-- wp-admin/includes/post.php | 58 +++++---------------------------- wp-includes/post.php | 3 -- 4 files changed, 13 insertions(+), 55 deletions(-) diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 5449626cf..a9a63478f 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -23,7 +23,6 @@ if ( post_type_supports($post_type, 'editor') || post_type_supports($post_type, * @var int */ $post_ID = isset($post_ID) ? (int) $post_ID : 0; -$temp_ID = isset($temp_ID) ? (int) $temp_ID : 0; $user_ID = isset($user_ID) ? (int) $user_ID : 0; $action = isset($action) ? $action : ''; diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index 944af3d36..c5edf6edb 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -401,12 +401,14 @@ function _media_button($title, $icon, $type, $id) { } function get_upload_iframe_src($type) { - global $post_ID, $temp_ID; - $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); + global $post_ID; + + $uploading_iframe_ID = (int) $post_ID; $upload_iframe_src = add_query_arg( 'post_id', $uploading_iframe_ID, admin_url('media-upload.php') ); if ( 'media' != $type ) $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); + $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); return add_query_arg('TB_iframe', true, $upload_iframe_src); diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 735716c01..cfcb2a33f 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -229,12 +229,6 @@ function edit_post( $post_data = null ) { wp_update_post( $post_data ); - // Reunite any orphaned attachments with their parent - if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) - $draft_ids = array(); - if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) ) - _relocate_children( $draft_temp_id, $post_ID ); - // Now that we have an ID we can fix any attachment anchor hrefs _fix_attachment_links( $post_ID ); @@ -538,7 +532,6 @@ function post_exists($title, $content = '', $date = '') { function wp_write_post() { global $user_ID; - if ( isset($_POST['post_type']) ) $ptype = get_post_type_object($_POST['post_type']); else @@ -556,33 +549,9 @@ function wp_write_post() { // Clear out any data in internal vars. unset( $_POST['filter'] ); - // Check for autosave collisions - // Does this need to be updated? ~ Mark - $temp_id = false; - if ( isset($_POST['temp_ID']) ) { - $temp_id = (int) $_POST['temp_ID']; - if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) - $draft_ids = array(); - foreach ( $draft_ids as $temp => $real ) - if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then ) - unset($draft_ids[$temp]); - - if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write - $_POST['post_ID'] = $draft_ids[$temp_id]; - unset($_POST['temp_ID']); - update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); - return edit_post(); - } - } - // Edit don't write if we have a post id. - if ( isset( $_POST['ID'] ) ) { - $_POST['post_ID'] = $_POST['ID']; - unset ( $_POST['ID'] ); - } - if ( isset( $_POST['post_ID'] ) ) { + if ( isset( $_POST['post_ID'] ) ) return edit_post(); - } $translated = _wp_translate_postdata( false ); if ( is_wp_error($translated) ) @@ -616,21 +585,6 @@ function wp_write_post() { add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID ); - // Reunite any orphaned attachments with their parent - // Does this need to be updated? ~ Mark - if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) - $draft_ids = array(); - if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) ) - _relocate_children( $draft_temp_id, $post_ID ); - if ( $temp_id && $temp_id != $draft_temp_id ) - _relocate_children( $temp_id, $post_ID ); - - // Update autosave collision detection - if ( $temp_id ) { - $draft_ids[$temp_id] = $post_ID; - update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); - } - // Now that we have an ID we can fix any attachment anchor hrefs _fix_attachment_links( $post_ID ); @@ -643,7 +597,10 @@ function wp_write_post() { * Calls wp_write_post() and handles the errors. * * @since 2.0.0 - * + + * @uses wp_write_post() + * @uses is_wp_error() + * @uses wp_die() * @return unknown */ function write_post() { @@ -1322,11 +1279,14 @@ function wp_create_post_autosave( $post_id ) { * @package WordPress * @since 2.7.0 * - * @uses wp_write_post() + * @uses get_post_status() * @uses edit_post() * @uses get_post() * @uses current_user_can() + * @uses wp_die() * @uses wp_create_post_autosave() + * @uses add_query_arg() + * @uses wp_create_nonce() * * @return str URL to redirect to show the preview */ diff --git a/wp-includes/post.php b/wp-includes/post.php index 091ebaccb..76fdd6507 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3728,9 +3728,6 @@ function wp_insert_attachment($object, $file = false, $parent = 0) { clean_post_cache($post_ID); - if ( isset($post_parent) && $post_parent < 0 ) - add_post_meta($post_ID, '_wp_attachment_temp_parent', $post_parent, true); - if ( ! empty( $context ) ) add_post_meta( $post_ID, '_wp_attachment_context', $context, true );