WordPress.org

Make WordPress Core

Changeset 14886


Ignore:
Timestamp:
05/25/2010 03:32:57 PM (10 years ago)
Author:
ryan
Message:

Fixing adding of custom fields to auto-drafts. Props ocean90. see #13401

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r14869 r14886  
    849849    $c = 0;
    850850    $pid = (int) $_POST['post_id'];
     851    $post = get_post( $pid );
     852
    851853    if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) {
    852854        if ( !current_user_can( 'edit_post', $pid ) )
     
    854856        if ( isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) )
    855857            die('1');
    856         if ( $pid < 0 ) {
     858        if ( $post->post_status == 'auto-draft' ) {
     859            $save_POST = $_POST; // Backup $_POST
     860            $_POST = array(); // Make it empty for edit_post()
     861            $_POST['action'] = 'draft'; // Warning fix
     862            $_POST['post_ID'] = $pid;
     863            $_POST['post_type'] = $post->post_type;
     864            $_POST['post_status'] = 'draft';
    857865            $now = current_time('timestamp', 1);
    858             if ( $pid = wp_insert_post( array(
    859                 'post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now))
    860             ) ) ) {
     866            $_POST['post_title'] = sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now));
     867
     868            if ( $pid = edit_post() ) {
    861869                if ( is_wp_error( $pid ) ) {
    862870                    $x = new WP_Ajax_Response( array(
     
    866874                    $x->send();
    867875                }
     876                $_POST = $save_POST; // Now we can restore original $_POST again
    868877                if ( !$mid = add_meta( $pid ) )
    869878                    die(__('Please provide a custom field value.'));
Note: See TracChangeset for help on using the changeset viewer.