diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 12132f482d..3b071a8e19 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -175,25 +175,23 @@ function edit_post() { $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss"); } + // Meta Stuff + if ($_POST['meta']) { + foreach ($_POST['meta'] as $key => $value) + update_meta($key, $value['key'], $value['value']); + } + + if ($_POST['deletemeta']) { + foreach ($_POST['deletemeta'] as $key => $value) + delete_meta($key); + } + + add_meta($post_ID); + wp_update_post($_POST); // Now that we have an ID we can fix any attachment anchor hrefs - fix_attachment_links($_POST['ID']); - - // 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); + fix_attachment_links($post_ID); return $post_ID; } diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index 517f735ae6..bb04280547 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -184,11 +184,9 @@ function wp_insert_post($postarr = array()) { } else if ($post_status == 'static') { generate_page_rewrite_rules(); - if ( empty($page_template) ) - $page_template = 'Default Template'; - - if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template)) - add_post_meta($post_ID, '_wp_page_template', $page_template, true); + if ( !empty($page_template) ) + if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template)) + add_post_meta($post_ID, '_wp_page_template', $page_template, true); } do_action('wp_insert_post', $post_ID); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index c0a5b31a98..961ad2bb80 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -510,15 +510,17 @@ function update_post_meta($post_id, $key, $value, $prev_value = '') { $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id'"); $cache_key = $post_meta_cache['$post_id'][$key]; - foreach ($cache_key as $index => $data) - $post_meta_cache['$post_id'][$key][$index] = $original_value; + if ( !empty($cache_key) ) + foreach ($cache_key as $index => $data) + $post_meta_cache['$post_id'][$key][$index] = $original_value; } else { $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$value' WHERE meta_key = '$key' AND post_id = '$post_id' AND meta_value = '$prev_value'"); $cache_key = $post_meta_cache['$post_id'][$key]; - foreach ($cache_key as $index => $data) - if ( $data == $original_prev ) - $post_meta_cache['$post_id'][$key][$index] = $original_value; + if ( !empty($cache_key) ) + foreach ($cache_key as $index => $data) + if ( $data == $original_prev ) + $post_meta_cache['$post_id'][$key][$index] = $original_value; } return true;