<!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>[28471] trunk/src/wp-includes/post.php: Eliminate the use of `extract()` in `get_pages()`.</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/28471">28471</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-05-17 17:11:23 +0000 (Sat, 17 May 2014)</dd>
</dl>

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

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 (28470 => 28471)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/post.php   2014-05-17 16:53:44 UTC (rev 28470)
+++ trunk/src/wp-includes/post.php      2014-05-17 17:11:23 UTC (rev 28471)
</span><span class="lines">@@ -4157,8 +4157,6 @@
</span><span class="cx"> function get_pages( $args = array() ) {
</span><span class="cx">  global $wpdb;
</span><span class="cx"> 
</span><del>-       $pages = false;
-
</del><span class="cx">   $defaults = array(
</span><span class="cx">          'child_of' => 0, 'sort_order' => 'ASC',
</span><span class="cx">          'sort_column' => 'post_title', 'hierarchical' => 1,
</span><span class="lines">@@ -4170,26 +4168,37 @@
</span><span class="cx">  );
</span><span class="cx"> 
</span><span class="cx">  $r = wp_parse_args( $args, $defaults );
</span><del>-       extract( $r, EXTR_SKIP );
-       $number = (int) $number;
-       $offset = (int) $offset;
</del><span class="cx"> 
</span><ins>+       $number = (int) $r['number'];
+       $offset = (int) $r['offset'];
+       $child_of = (int) $r['child_of'];
+       $hierarchical = $r['hierarchical'];
+       $exclude = $r['exclude'];
+       $meta_key = $r['meta_key'];
+       $meta_value = $r['meta_value'];
+       $parent = $r['parent'];
+       $post_status = $r['post_status'];
+
</ins><span class="cx">   // Make sure the post type is hierarchical
</span><span class="cx">  $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
</span><del>-       if ( !in_array( $post_type, $hierarchical_post_types ) )
-               return $pages;
</del><ins>+        if ( ! in_array( $r['post_type'], $hierarchical_post_types ) ) {
+               return false;
+       }
</ins><span class="cx"> 
</span><del>-       if ( $parent > 0 && ! $child_of )
</del><ins>+        if ( $parent > 0 && ! $child_of ) {
</ins><span class="cx">           $hierarchical = false;
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  // Make sure we have a valid post status
</span><del>-       if ( !is_array( $post_status ) )
</del><ins>+        if ( ! is_array( $post_status ) ) {
</ins><span class="cx">           $post_status = explode( ',', $post_status );
</span><del>-       if ( array_diff( $post_status, get_post_stati() ) )
-               return $pages;
</del><ins>+        }
+       if ( array_diff( $post_status, get_post_stati() ) ) {
+               return false;
+       }
</ins><span class="cx"> 
</span><span class="cx">  // $args can be whatever, only use the args defined in defaults to compute the key
</span><del>-       $key = md5( serialize( compact(array_keys($defaults)) ) );
</del><ins>+        $key = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) );
</ins><span class="cx">   $last_changed = wp_cache_get( 'last_changed', 'posts' );
</span><span class="cx">  if ( ! $last_changed ) {
</span><span class="cx">          $last_changed = microtime();
</span><span class="lines">@@ -4206,48 +4215,54 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  $inclusions = '';
</span><del>-       if ( ! empty( $include ) ) {
</del><ins>+        if ( ! empty( $r['include'] ) ) {
</ins><span class="cx">           $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
</span><span class="cx">          $parent = -1;
</span><span class="cx">          $exclude = '';
</span><span class="cx">          $meta_key = '';
</span><span class="cx">          $meta_value = '';
</span><span class="cx">          $hierarchical = false;
</span><del>-               $incpages = wp_parse_id_list( $include );
-               if ( ! empty( $incpages ) )
</del><ins>+                $incpages = wp_parse_id_list( $r['include'] );
+               if ( ! empty( $incpages ) ) {
</ins><span class="cx">                   $inclusions = ' AND ID IN (' . implode( ',', $incpages ) .  ')';
</span><ins>+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  $exclusions = '';
</span><span class="cx">  if ( ! empty( $exclude ) ) {
</span><span class="cx">          $expages = wp_parse_id_list( $exclude );
</span><del>-               if ( ! empty( $expages ) )
</del><ins>+                if ( ! empty( $expages ) ) {
</ins><span class="cx">                   $exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) .  ')';
</span><ins>+               }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  $author_query = '';
</span><del>-       if (!empty($authors)) {
-               $post_authors = preg_split('/[\s,]+/',$authors);
</del><ins>+        if ( ! empty( $r['authors'] ) ) {
+               $post_authors = preg_split( '/[\s,]+/', $r['authors'] );
</ins><span class="cx"> 
</span><span class="cx">          if ( ! empty( $post_authors ) ) {
</span><span class="cx">                  foreach ( $post_authors as $post_author ) {
</span><span class="cx">                          //Do we have an author id or an author login?
</span><span class="cx">                          if ( 0 == intval($post_author) ) {
</span><span class="cx">                                  $post_author = get_user_by('login', $post_author);
</span><del>-                                       if ( empty($post_author) )
</del><ins>+                                        if ( empty( $post_author ) ) {
</ins><span class="cx">                                           continue;
</span><del>-                                       if ( empty($post_author->ID) )
</del><ins>+                                        }
+                                       if ( empty( $post_author->ID ) ) {
</ins><span class="cx">                                           continue;
</span><ins>+                                       }
</ins><span class="cx">                                   $post_author = $post_author->ID;
</span><span class="cx">                          }
</span><span class="cx"> 
</span><del>-                               if ( '' == $author_query )
</del><ins>+                                if ( '' == $author_query ) {
</ins><span class="cx">                                   $author_query = $wpdb->prepare(' post_author = %d ', $post_author);
</span><del>-                               else
</del><ins>+                                } else {
</ins><span class="cx">                                   $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
</span><ins>+                               }
</ins><span class="cx">                   }
</span><del>-                       if ( '' != $author_query )
</del><ins>+                        if ( '' != $author_query ) {
</ins><span class="cx">                           $author_query = " AND ($author_query)";
</span><ins>+                       }
</ins><span class="cx">           }
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="lines">@@ -4259,36 +4274,41 @@
</span><span class="cx">          // meta_key and meta_value might be slashed
</span><span class="cx">          $meta_key = wp_unslash($meta_key);
</span><span class="cx">          $meta_value = wp_unslash($meta_value);
</span><del>-               if ( '' !== $meta_key )
</del><ins>+                if ( '' !== $meta_key ) {
</ins><span class="cx">                   $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
</span><del>-               if ( '' !== $meta_value )
</del><ins>+                }
+               if ( '' !== $meta_value ) {
</ins><span class="cx">                   $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
</span><ins>+               }
</ins><span class="cx"> 
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  if ( is_array( $parent ) ) {
</span><span class="cx">          $post_parent__in = implode( ',', array_map( 'absint', (array) $parent ) );
</span><del>-               if ( ! empty( $post_parent__in ) )
</del><ins>+                if ( ! empty( $post_parent__in ) ) {
</ins><span class="cx">                   $where .= " AND post_parent IN ($post_parent__in)";
</span><ins>+               }
</ins><span class="cx">   } elseif ( $parent >= 0 ) {
</span><span class="cx">          $where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  if ( 1 == count( $post_status ) ) {
</span><del>-               $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $post_type, array_shift( $post_status ) );
</del><ins>+                $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], array_shift( $post_status ) );
</ins><span class="cx">   } else {
</span><span class="cx">          $post_status = implode( "', '", $post_status );
</span><del>-               $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $post_type );
</del><ins>+                $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] );
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">  $orderby_array = array();
</span><del>-       $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
-                                                 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
-                                                 'ID', 'rand', 'comment_count');
-       foreach ( explode( ',', $sort_column ) as $orderby ) {
</del><ins>+        $allowed_keys = array( 'author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
+               'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
+               'ID', 'rand', 'comment_count' );
+
+       foreach ( explode( ',', $r['sort_column'] ) as $orderby ) {
</ins><span class="cx">           $orderby = trim( $orderby );
</span><del>-               if ( !in_array( $orderby, $allowed_keys ) )
</del><ins>+                if ( ! in_array( $orderby, $allowed_keys ) ) {
</ins><span class="cx">                   continue;
</span><ins>+               }
</ins><span class="cx"> 
</span><span class="cx">          switch ( $orderby ) {
</span><span class="cx">                  case 'menu_order':
</span><span class="lines">@@ -4303,10 +4323,11 @@
</span><span class="cx">                          $orderby = "$wpdb->posts.comment_count";
</span><span class="cx">                          break;
</span><span class="cx">                  default:
</span><del>-                               if ( 0 === strpos( $orderby, 'post_' ) )
</del><ins>+                                if ( 0 === strpos( $orderby, 'post_' ) ) {
</ins><span class="cx">                                   $orderby = "$wpdb->posts." . $orderby;
</span><del>-                               else
</del><ins>+                                } else {
</ins><span class="cx">                                   $orderby = "$wpdb->posts.post_" . $orderby;
</span><ins>+                               }
</ins><span class="cx">           }
</span><span class="cx"> 
</span><span class="cx">          $orderby_array[] = $orderby;
</span><span class="lines">@@ -4314,16 +4335,18 @@
</span><span class="cx">  }
</span><span class="cx">  $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title";
</span><span class="cx"> 
</span><del>-       $sort_order = strtoupper( $sort_order );
-       if ( '' !== $sort_order && !in_array( $sort_order, array( 'ASC', 'DESC' ) ) )
</del><ins>+        $sort_order = strtoupper( $r['sort_order'] );
+       if ( '' !== $sort_order && ! in_array( $sort_order, array( 'ASC', 'DESC' ) ) ) {
</ins><span class="cx">           $sort_order = 'ASC';
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
</span><span class="cx">  $query .= $author_query;
</span><span class="cx">  $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
</span><span class="cx"> 
</span><del>-       if ( !empty($number) )
</del><ins>+        if ( ! empty( $number ) ) {
</ins><span class="cx">           $query .= ' LIMIT ' . $offset . ',' . $number;
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  $pages = $wpdb->get_results($query);
</span><span class="cx"> 
</span><span class="lines">@@ -4342,11 +4365,12 @@
</span><span class="cx">  // Update cache.
</span><span class="cx">  update_post_cache( $pages );
</span><span class="cx"> 
</span><del>-       if ( $child_of || $hierarchical )
</del><ins>+        if ( $child_of || $hierarchical ) {
</ins><span class="cx">           $pages = get_page_children($child_of, $pages);
</span><ins>+       }
</ins><span class="cx"> 
</span><del>-       if ( ! empty( $exclude_tree ) ) {
-               $exclude = wp_parse_id_list( $exclude_tree );
</del><ins>+        if ( ! empty( $r['exclude_tree'] ) ) {
+               $exclude = wp_parse_id_list( $r['exclude_tree'] );
</ins><span class="cx">           foreach( $exclude as $id ) {
</span><span class="cx">                  $children = get_page_children( $id, $pages );
</span><span class="cx">                  foreach ( $children as $child ) {
</span><span class="lines">@@ -4363,8 +4387,9 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  $page_structure = array();
</span><del>-       foreach ( $pages as $page )
</del><ins>+        foreach ( $pages as $page ) {
</ins><span class="cx">           $page_structure[] = $page->ID;
</span><ins>+       }
</ins><span class="cx"> 
</span><span class="cx">  wp_cache_set( $cache_key, $page_structure, 'posts' );
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>