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

git-svn-id: http://svn.automattic.com/wordpress/trunk@14886 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-05-25 15:32:57 +00:00
parent ec8d5fee12
commit b744c38378
1 changed files with 13 additions and 4 deletions

View File

@ -848,16 +848,24 @@ case 'add-meta' :
check_ajax_referer( 'add-meta' );
$c = 0;
$pid = (int) $_POST['post_id'];
$post = get_post( $pid );
if ( isset($_POST['metakeyselect']) || isset($_POST['metakeyinput']) ) {
if ( !current_user_can( 'edit_post', $pid ) )
die('-1');
if ( isset($_POST['metakeyselect']) && '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) )
die('1');
if ( $pid < 0 ) {
if ( $post->post_status == 'auto-draft' ) {
$save_POST = $_POST; // Backup $_POST
$_POST = array(); // Make it empty for edit_post()
$_POST['action'] = 'draft'; // Warning fix
$_POST['post_ID'] = $pid;
$_POST['post_type'] = $post->post_type;
$_POST['post_status'] = 'draft';
$now = current_time('timestamp', 1);
if ( $pid = wp_insert_post( array(
'post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now))
) ) ) {
$_POST['post_title'] = sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now));
if ( $pid = edit_post() ) {
if ( is_wp_error( $pid ) ) {
$x = new WP_Ajax_Response( array(
'what' => 'meta',
@ -865,6 +873,7 @@ case 'add-meta' :
) );
$x->send();
}
$_POST = $save_POST; // Now we can restore original $_POST again
if ( !$mid = add_meta( $pid ) )
die(__('Please provide a custom field value.'));
} else {