<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[28469] trunk/src/wp-includes/post.php: Eliminate the use of `extract()` in `wp_insert_post()`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/28469">28469</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-05-17 15:52:11 +0000 (Sat, 17 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Eliminate the use of `extract()` in `wp_insert_post()`.

See <a href="http://core.trac.wordpress.org/ticket/22400">#22400</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/post.php (28468 => 28469)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/post.php   2014-05-17 15:41:40 UTC (rev 28468)
+++ trunk/src/wp-includes/post.php      2014-05-17 15:52:11 UTC (rev 28469)
</span><span class="lines">@@ -2923,30 +2923,39 @@
</span><span class="cx"> 
</span><span class="cx">  $postarr = sanitize_post($postarr, 'db');
</span><span class="cx"> 
</span><del>-       // export array as variables
-       extract($postarr, EXTR_SKIP);
-
</del><span class="cx">   // Are we updating or creating?
</span><span class="cx">  $post_ID = 0;
</span><span class="cx">  $update = false;
</span><del>-       if ( ! empty( $ID ) ) {
</del><ins>+        $guid = $postarr['guid'];
+
+       if ( ! empty( $postarr['ID'] ) ) {
</ins><span class="cx">           $update = true;
</span><span class="cx"> 
</span><span class="cx">          // Get the post ID and GUID
</span><del>-               $post_ID = $ID;
</del><ins>+                $post_ID = $postarr['ID'];
</ins><span class="cx">           $post_before = get_post( $post_ID );
</span><span class="cx">          if ( is_null( $post_before ) ) {
</span><del>-                       if ( $wp_error )
</del><ins>+                        if ( $wp_error ) {
</ins><span class="cx">                           return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
</span><ins>+                       }
</ins><span class="cx">                   return 0;
</span><span class="cx">          }
</span><span class="cx"> 
</span><span class="cx">          $guid = get_post_field( 'guid', $post_ID );
</span><del>-               $previous_status = get_post_field('post_status', $ID);
</del><ins>+                $previous_status = get_post_field('post_status', $post_ID );
</ins><span class="cx">   } else {
</span><span class="cx">          $previous_status = 'new';
</span><span class="cx">  }
</span><span class="cx"> 
</span><ins>+       $post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type'];
+
+       $post_title = $postarr['post_title'];
+       $post_content = $postarr['post_content'];
+       $post_excerpt = $postarr['post_excerpt'];
+       if ( isset( $postarr['post_name'] ) ) {
+               $post_name = $postarr['post_name'];
+       }
+
</ins><span class="cx">   $maybe_empty = ! $post_content && ! $post_title && ! $post_excerpt && post_type_supports( $post_type, 'editor' )
</span><span class="cx">          && post_type_supports( $post_type, 'title' ) && post_type_supports( $post_type, 'excerpt' );
</span><span class="cx"> 
</span><span class="lines">@@ -2967,74 +2976,80 @@
</span><span class="cx">   * @param array $postarr     Array of post data.
</span><span class="cx">   */
</span><span class="cx">  if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
</span><del>-               if ( $wp_error )
</del><ins>+                if ( $wp_error ) {
</ins><span class="cx">                   return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) );
</span><del>-               else
</del><ins>+                } else {
</ins><span class="cx">                   return 0;
</span><ins>+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><del>-       if ( empty($post_type) )
-               $post_type = 'post';
</del><ins>+        $post_status = empty( $postarr['post_status'] ) ? 'draft' : $postarr['post_status'];
</ins><span class="cx"> 
</span><del>-       if ( empty($post_status) )
-               $post_status = 'draft';
</del><ins>+        if ( ! empty( $postarr['post_category'] ) ) {
+               $post_category = array_filter( $postarr['post_category'] ); // Filter out empty terms
+       }
</ins><span class="cx"> 
</span><del>-       if ( !empty($post_category) )
-               $post_category = array_filter($post_category); // Filter out empty terms
-
</del><span class="cx">   // Make sure we set a valid category.
</span><del>-       if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
</del><ins>+        if ( empty( $post_category ) || 0 == count( $post_category ) || ! is_array( $post_category ) ) {
</ins><span class="cx">           // 'post' requires at least one category.
</span><del>-               if ( 'post' == $post_type && 'auto-draft' != $post_status )
</del><ins>+                if ( 'post' == $post_type && 'auto-draft' != $post_status ) {
</ins><span class="cx">                   $post_category = array( get_option('default_category') );
</span><del>-               else
</del><ins>+                } else {
</ins><span class="cx">                   $post_category = array();
</span><ins>+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><del>-       if ( empty($post_author) )
-               $post_author = $user_id;
-
</del><span class="cx">   // Don't allow contributors to set the post slug for pending review posts
</span><del>-       if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) )
</del><ins>+        if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) {
</ins><span class="cx">           $post_name = '';
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  // Create a valid post name. Drafts and pending posts are allowed to have an empty
</span><span class="cx">  // post name.
</span><span class="cx">  if ( empty($post_name) ) {
</span><del>-               if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
</del><ins>+                if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
</ins><span class="cx">                   $post_name = sanitize_title($post_title);
</span><del>-               else
</del><ins>+                } else {
</ins><span class="cx">                   $post_name = '';
</span><ins>+               }
</ins><span class="cx">   } else {
</span><span class="cx">          // On updates, we need to check to see if it's using the old, fixed sanitization context.
</span><span class="cx">          $check_name = sanitize_title( $post_name, '', 'old-save' );
</span><del>-               if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $ID ) == $check_name )
</del><ins>+                if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $post_ID ) == $check_name ) {
</ins><span class="cx">                   $post_name = $check_name;
</span><del>-               else // new post, or slug has changed.
</del><ins>+                } else { // new post, or slug has changed.
</ins><span class="cx">                   $post_name = sanitize_title($post_name);
</span><ins>+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  // If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now
</span><del>-       if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date )
-               $post_date = current_time('mysql');
</del><ins>+        if ( empty( $postarr['post_date'] ) || '0000-00-00 00:00:00' == $postarr['post_date'] ) {
+               $post_date = current_time( 'mysql' );
+       } else {
+               $post_date = $postarr['post_date'];
+       }
</ins><span class="cx"> 
</span><del>-               // validate the date
-               $mm = substr( $post_date, 5, 2 );
-               $jj = substr( $post_date, 8, 2 );
-               $aa = substr( $post_date, 0, 4 );
-               $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
-               if ( !$valid_date ) {
-                       if ( $wp_error )
-                               return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );
-                       else
-                               return 0;
</del><ins>+        // validate the date
+       $mm = substr( $post_date, 5, 2 );
+       $jj = substr( $post_date, 8, 2 );
+       $aa = substr( $post_date, 0, 4 );
+       $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
+       if ( ! $valid_date ) {
+               if ( $wp_error ) {
+                       return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );
+               } else {
+                       return 0;
</ins><span class="cx">           }
</span><ins>+       }
</ins><span class="cx"> 
</span><del>-       if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) {
-               if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
-                       $post_date_gmt = get_gmt_from_date($post_date);
-               else
</del><ins>+        if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {
+               if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
+                       $post_date_gmt = get_gmt_from_date( $post_date );
+               } else {
</ins><span class="cx">                   $post_date_gmt = '0000-00-00 00:00:00';
</span><ins>+               }
+       } else {
+               $post_date_gmt = $postarr['post_date_gmt'];
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  if ( $update || '0000-00-00 00:00:00' == $post_date ) {
</span><span class="lines">@@ -3047,35 +3062,52 @@
</span><span class="cx"> 
</span><span class="cx">  if ( 'publish' == $post_status ) {
</span><span class="cx">          $now = gmdate('Y-m-d H:i:59');
</span><del>-               if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) )
</del><ins>+                if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) {
</ins><span class="cx">                   $post_status = 'future';
</span><ins>+               }
</ins><span class="cx">   } elseif( 'future' == $post_status ) {
</span><span class="cx">          $now = gmdate('Y-m-d H:i:59');
</span><del>-               if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) )
</del><ins>+                if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) {
</ins><span class="cx">                   $post_status = 'publish';
</span><ins>+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><del>-       if ( empty($comment_status) ) {
-               if ( $update )
</del><ins>+        if ( empty( $postarr['comment_status'] ) ) {
+               if ( $update ) {
</ins><span class="cx">                   $comment_status = 'closed';
</span><del>-               else
</del><ins>+                } else {
</ins><span class="cx">                   $comment_status = get_option('default_comment_status');
</span><ins>+               }
+       } else {
+               $comment_status = $postarr['comment_status'];
</ins><span class="cx">   }
</span><del>-       if ( empty($ping_status) )
-               $ping_status = get_option('default_ping_status');
</del><span class="cx"> 
</span><del>-       if ( isset($to_ping) )
-               $to_ping = sanitize_trackback_urls( $to_ping );
-       else
-               $to_ping = '';
</del><ins>+        // these variables are needed by compact() later
+       $post_content_filtered = $postarr['post_content_filtered'];
+       $post_author = empty( $postarr['post_author'] ) ? $user_id : $postarr['post_author'];
+       $ping_status = empty( $postarr['ping_status'] ) ? get_option( 'default_ping_status' ) : $postarr['ping_status'];
+       $to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
+       $pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
+       $import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
</ins><span class="cx"> 
</span><del>-       if ( ! isset($pinged) )
-               $pinged = '';
</del><ins>+        // The 'wp_insert_post_parent' filter expects all variables to be present.
+       // Previously, these variables would have already been extracted
+       if ( isset( $postarr['menu_order'] ) ) {
+               $menu_order = (int) $postarr['menu_order'];
+       } else {
+               $menu_order = 0;
+       }
</ins><span class="cx"> 
</span><del>-       if ( isset($post_parent) )
-               $post_parent = (int) $post_parent;
-       else
</del><ins>+        $post_password = isset( $postarr['post_password'] ) ? $postarr['post_password'] : '';
+       if ( 'private' == $post_status ) {
+               $post_password = '';
+       }
+
+       if ( isset( $postarr['post_parent'] ) ) {
+               $post_parent = (int) $postarr['post_parent'];
+       } else {
</ins><span class="cx">           $post_parent = 0;
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * Filter the post parent -- used to check for and prevent hierarchy loops.
</span><span class="lines">@@ -3089,18 +3121,10 @@
</span><span class="cx">   */
</span><span class="cx">  $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
</span><span class="cx"> 
</span><del>-       if ( isset($menu_order) )
-               $menu_order = (int) $menu_order;
-       else
-               $menu_order = 0;
</del><ins>+        $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent );
</ins><span class="cx"> 
</span><del>-       if ( !isset($post_password) || 'private' == $post_status )
-               $post_password = '';
-
-       $post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);
-
</del><span class="cx">   // expected_slashed (everything!)
</span><del>-       $data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' ) );
</del><ins>+        $data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'guid' );
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * Filter slashed post data just before it is inserted into the database.
</span><span class="lines">@@ -3125,26 +3149,29 @@
</span><span class="cx">           */
</span><span class="cx">          do_action( 'pre_post_update', $post_ID, $data );
</span><span class="cx">          if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
</span><del>-                       if ( $wp_error )
</del><ins>+                        if ( $wp_error ) {
</ins><span class="cx">                           return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error);
</span><del>-                       else
</del><ins>+                        } else {
</ins><span class="cx">                           return 0;
</span><ins>+                       }
</ins><span class="cx">           }
</span><span class="cx">  } else {
</span><del>-               if ( isset($post_mime_type) )
-                       $data['post_mime_type'] = wp_unslash( $post_mime_type ); // This isn't in the update
</del><ins>+                if ( isset( $postarr['post_mime_type'] ) ) {
+                       $data['post_mime_type'] = wp_unslash( $postarr['post_mime_type'] ); // This isn't in the update
+               }
</ins><span class="cx">           // If there is a suggested ID, use it if not already present
</span><del>-               if ( !empty($import_id) ) {
</del><ins>+                if ( ! empty( $import_id ) ) {
</ins><span class="cx">                   $import_id = (int) $import_id;
</span><span class="cx">                  if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) {
</span><span class="cx">                          $data['ID'] = $import_id;
</span><span class="cx">                  }
</span><span class="cx">          }
</span><span class="cx">          if ( false === $wpdb->insert( $wpdb->posts, $data ) ) {
</span><del>-                       if ( $wp_error )
</del><ins>+                        if ( $wp_error ) {
</ins><span class="cx">                           return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);
</span><del>-                       else
</del><ins>+                        } else {
</ins><span class="cx">                           return 0;
</span><ins>+                       }
</ins><span class="cx">           }
</span><span class="cx">          $post_ID = (int) $wpdb->insert_id;
</span><span class="cx"> 
</span><span class="lines">@@ -3157,43 +3184,48 @@
</span><span class="cx">          $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       if ( is_object_in_taxonomy($post_type, 'category') )
</del><ins>+        if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
</ins><span class="cx">           wp_set_post_categories( $post_ID, $post_category );
</span><ins>+       }
</ins><span class="cx"> 
</span><del>-       if ( isset( $tags_input ) && is_object_in_taxonomy($post_type, 'post_tag') )
-               wp_set_post_tags( $post_ID, $tags_input );
</del><ins>+        if ( isset( $postarr['tags_input'] ) && is_object_in_taxonomy( $post_type, 'post_tag' ) ) {
+               wp_set_post_tags( $post_ID, $postarr['tags_input'] );
+       }
</ins><span class="cx"> 
</span><span class="cx">  // new-style support for all custom taxonomies
</span><del>-       if ( !empty($tax_input) ) {
-               foreach ( $tax_input as $taxonomy => $tags ) {
</del><ins>+        if ( ! empty( $postarr['tax_input'] ) ) {
+               foreach ( $postarr['tax_input'] as $taxonomy => $tags ) {
</ins><span class="cx">                   $taxonomy_obj = get_taxonomy($taxonomy);
</span><del>-                       if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
</del><ins>+                        if ( is_array( $tags ) ) { // array = hierarchical, string = non-hierarchical.
</ins><span class="cx">                           $tags = array_filter($tags);
</span><del>-                       if ( current_user_can($taxonomy_obj->cap->assign_terms) )
</del><ins>+                        }
+                       if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
</ins><span class="cx">                           wp_set_post_terms( $post_ID, $tags, $taxonomy );
</span><ins>+                       }
</ins><span class="cx">           }
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  $current_guid = get_post_field( 'guid', $post_ID );
</span><span class="cx"> 
</span><span class="cx">  // Set GUID
</span><del>-       if ( !$update && '' == $current_guid )
</del><ins>+        if ( ! $update && '' == $current_guid ) {
</ins><span class="cx">           $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where );
</span><del>-
</del><ins>+        }
</ins><span class="cx">   clean_post_cache( $post_ID );
</span><span class="cx"> 
</span><del>-       $post = get_post($post_ID);
</del><ins>+        $post = get_post( $post_ID );
</ins><span class="cx"> 
</span><del>-       if ( !empty($page_template) && 'page' == $data['post_type'] ) {
-               $post->page_template = $page_template;
</del><ins>+        if ( ! empty( $postarr['page_template'] ) && 'page' == $data['post_type'] ) {
+               $post->page_template = $postarr['page_template'];
</ins><span class="cx">           $page_templates = wp_get_theme()->get_page_templates( $post );
</span><del>-               if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) {
-                       if ( $wp_error )
</del><ins>+                if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
+                       if ( $wp_error ) {
</ins><span class="cx">                           return new WP_Error('invalid_page_template', __('The page template is invalid.'));
</span><del>-                       else
</del><ins>+                        } else {
</ins><span class="cx">                           return 0;
</span><ins>+                       }
</ins><span class="cx">           }
</span><del>-               update_post_meta($post_ID, '_wp_page_template',  $page_template);
</del><ins>+                update_post_meta( $post_ID, '_wp_page_template', $postarr['page_template'] );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  wp_transition_post_status($data['post_status'], $previous_status, $post);
</span></span></pre>
</div>
</div>

</body>
</html>