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
This commit is contained in:
azaozz 2011-09-29 21:47:52 +00:00
parent 44029b1ef1
commit 75432d53b0
4 changed files with 13 additions and 55 deletions

View File

@ -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 : '';

View File

@ -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);

View File

@ -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
*/

View File

@ -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 );