<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[13758] trunk/wp-includes/query.php: Make use of apply_filters_ref_array()
  when running the query.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13758">13758</a></dd>
<dt>Author</dt> <dd>westi</dd>
<dt>Date</dt> <dd>2010-03-18 21:55:25 +0000 (Thu, 18 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Make use of apply_filters_ref_array() when running the query. Fixes <a href="http://trac.wordpress.org/ticket/9886">#9886</a> props scribu.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesqueryphp">trunk/wp-includes/query.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesqueryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/query.php (13757 => 13758)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/query.php        2010-03-18 21:45:08 UTC (rev 13757)
+++ trunk/wp-includes/query.php        2010-03-18 21:55:25 UTC (rev 13758)
</span><span class="lines">@@ -1806,7 +1806,7 @@
</span><span class="cx">                                         $search .= &quot; AND ($wpdb-&gt;posts.post_password = '') &quot;;
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-                $search = apply_filters('posts_search', $search, $this);
</del><ins>+                $search = apply_filters_ref_array('posts_search', array( $search, &amp;$this ) );
</ins><span class="cx"> 
</span><span class="cx">                 // Category stuff
</span><span class="cx"> 
</span><span class="lines">@@ -2243,8 +2243,8 @@
</span><span class="cx">                 // Apply filters on where and join prior to paging so that any
</span><span class="cx">                 // manipulations to them are reflected in the paging by day queries.
</span><span class="cx">                 if ( !$q['suppress_filters'] ) {
</span><del>-                        $where = apply_filters('posts_where', $where);
-                        $join = apply_filters('posts_join', $join);
</del><ins>+                        $where = apply_filters_ref_array('posts_where', array( $where, &amp;$this ) );
+                        $join = apply_filters_ref_array('posts_join', array( $join, &amp;$this ) );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 // Paging
</span><span class="lines">@@ -2278,11 +2278,11 @@
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         if ( !$q['suppress_filters'] ) {
</span><del>-                                $cjoin = apply_filters('comment_feed_join', $cjoin);
-                                $cwhere = apply_filters('comment_feed_where', $cwhere);
-                                $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
-                                $corderby = apply_filters('comment_feed_orderby', 'comment_date_gmt DESC');
-                                $climits = apply_filters('comment_feed_limits', 'LIMIT ' . get_option('posts_per_rss'));
</del><ins>+                                $cjoin = apply_filters_ref_array('comment_feed_join', array( $cjoin, &amp;$this ) );
+                                $cwhere = apply_filters_ref_array('comment_feed_where', array( $cwhere, &amp;$this ) );
+                                $cgroupby = apply_filters_ref_array('comment_feed_groupby', array( $cgroupby, &amp;$this ) );
+                                $corderby = apply_filters_ref_array('comment_feed_orderby', array( 'comment_date_gmt DESC', &amp;$this ) );
+                                $climits = apply_filters_ref_array('comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &amp;$this ) );
</ins><span class="cx">                         }
</span><span class="cx">                         $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
</span><span class="cx">                         $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
</span><span class="lines">@@ -2308,14 +2308,13 @@
</span><span class="cx">                 // Apply post-paging filters on where and join.  Only plugins that
</span><span class="cx">                 // manipulate paging queries should use these hooks.
</span><span class="cx">                 if ( !$q['suppress_filters'] ) {
</span><del>-                        $where = apply_filters('posts_where_paged', $where);
-                        $groupby = apply_filters('posts_groupby', $groupby);
-                        $join = apply_filters('posts_join_paged', $join);
-                        $orderby = apply_filters('posts_orderby', $orderby);
-                        $distinct = apply_filters('posts_distinct', $distinct);
-                        $limits = apply_filters( 'post_limits', $limits );
-
-                        $fields = apply_filters('posts_fields', $fields);
</del><ins>+                        $where                = apply_filters_ref_array( 'posts_where_paged',        array( $where, &amp;$this ) );
+                        $groupby        = apply_filters_ref_array( 'posts_groupby',                array( $groupby, &amp;$this ) );
+                        $join                = apply_filters_ref_array( 'posts_join_paged',        array( $join, &amp;$this ) );
+                        $orderby        = apply_filters_ref_array( 'posts_orderby',                array( $orderby, &amp;$this ) );
+                        $distinct        = apply_filters_ref_array( 'posts_distinct',        array( $distinct, &amp;$this ) );
+                        $limits                = apply_filters_ref_array( 'post_limits',                array( $limits, &amp;$this ) );
+                        $fields                = apply_filters_ref_array( 'posts_fields',                array( $fields, &amp;$this ) );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 // Announce current selection parameters.  For use by caching plugins.
</span><span class="lines">@@ -2323,13 +2322,13 @@
</span><span class="cx"> 
</span><span class="cx">                 // Filter again for the benefit of caching plugins.  Regular plugins should use the hooks above.
</span><span class="cx">                 if ( !$q['suppress_filters'] ) {
</span><del>-                        $where = apply_filters('posts_where_request', $where);
-                        $groupby = apply_filters('posts_groupby_request', $groupby);
-                        $join = apply_filters('posts_join_request', $join);
-                        $orderby = apply_filters('posts_orderby_request', $orderby);
-                        $distinct = apply_filters('posts_distinct_request', $distinct);
-                        $fields = apply_filters('posts_fields_request', $fields);
-                        $limits = apply_filters( 'post_limits_request', $limits );
</del><ins>+                        $where                = apply_filters_ref_array( 'posts_where_request',        array( $where, &amp;$this ) );
+                        $groupby        = apply_filters_ref_array( 'posts_groupby_request',                array( $groupby, &amp;$this ) );
+                        $join                = apply_filters_ref_array( 'posts_join_request',        array( $join, &amp;$this ) );
+                        $orderby        = apply_filters_ref_array( 'posts_orderby_request',                array( $orderby, &amp;$this ) );
+                        $distinct        = apply_filters_ref_array( 'posts_distinct_request',        array( $distinct, &amp;$this ) );
+                        $fields                = apply_filters_ref_array( 'posts_fields_request',                array( $fields, &amp;$this ) );
+                        $limits                = apply_filters_ref_array( 'post_limits_request',                array( $limits, &amp;$this ) );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ( ! empty($groupby) )
</span><span class="lines">@@ -2342,30 +2341,30 @@
</span><span class="cx"> 
</span><span class="cx">                 $this-&gt;request = &quot; SELECT $found_rows $distinct $fields FROM $wpdb-&gt;posts $join WHERE 1=1 $where $groupby $orderby $limits&quot;;
</span><span class="cx">                 if ( !$q['suppress_filters'] )
</span><del>-                        $this-&gt;request = apply_filters('posts_request', $this-&gt;request);
</del><ins>+                        $this-&gt;request = apply_filters_ref_array('posts_request', array( $this-&gt;request, &amp;$this ) );
</ins><span class="cx"> 
</span><span class="cx">                 $this-&gt;posts = $wpdb-&gt;get_results($this-&gt;request);
</span><span class="cx">                 // Raw results filter.  Prior to status checks.
</span><span class="cx">                 if ( !$q['suppress_filters'] )
</span><del>-                        $this-&gt;posts = apply_filters('posts_results', $this-&gt;posts);
</del><ins>+                        $this-&gt;posts = apply_filters_ref_array('posts_results', array( $this-&gt;posts, &amp;$this ) );
</ins><span class="cx"> 
</span><span class="cx">                 if ( !empty($this-&gt;posts) &amp;&amp; $this-&gt;is_comment_feed &amp;&amp; $this-&gt;is_singular ) {
</span><del>-                        $cjoin = apply_filters('comment_feed_join', '');
-                        $cwhere = apply_filters('comment_feed_where', &quot;WHERE comment_post_ID = '{$this-&gt;posts[0]-&gt;ID}' AND comment_approved = '1'&quot;);
-                        $cgroupby = apply_filters('comment_feed_groupby', '');
</del><ins>+                        $cjoin = apply_filters_ref_array('comment_feed_join', array( '', &amp;$this ) );
+                        $cwhere = apply_filters_ref_array('comment_feed_where', array( &quot;WHERE comment_post_ID = '{$this-&gt;posts[0]-&gt;ID}' AND comment_approved = '1'&quot;, &amp;$this ) );
+                        $cgroupby = apply_filters_ref_array('comment_feed_groupby', array( '', &amp;$this ) );
</ins><span class="cx">                         $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
</span><del>-                        $corderby = apply_filters('comment_feed_orderby', 'comment_date_gmt DESC');
</del><ins>+                        $corderby = apply_filters_ref_array('comment_feed_orderby', array( 'comment_date_gmt DESC', &amp;$this ) );
</ins><span class="cx">                         $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
</span><del>-                        $climits = apply_filters('comment_feed_limits', 'LIMIT ' . get_option('posts_per_rss'));
</del><ins>+                        $climits = apply_filters_ref_array('comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &amp;$this ) );
</ins><span class="cx">                         $comments_request = &quot;SELECT $wpdb-&gt;comments.* FROM $wpdb-&gt;comments $cjoin $cwhere $cgroupby $corderby $climits&quot;;
</span><span class="cx">                         $this-&gt;comments = $wpdb-&gt;get_results($comments_request);
</span><span class="cx">                         $this-&gt;comment_count = count($this-&gt;comments);
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ( !$q['no_found_rows'] &amp;&amp; !empty($limits) ) {
</span><del>-                        $found_posts_query = apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()' );
</del><ins>+                        $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &amp;$this ) );
</ins><span class="cx">                         $this-&gt;found_posts = $wpdb-&gt;get_var( $found_posts_query );
</span><del>-                        $this-&gt;found_posts = apply_filters( 'found_posts', $this-&gt;found_posts );
</del><ins>+                        $this-&gt;found_posts = apply_filters_ref_array( 'found_posts', array( $this-&gt;found_posts, &amp;$this ) );
</ins><span class="cx">                         $this-&gt;max_num_pages = ceil($this-&gt;found_posts / $q['posts_per_page']);
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="lines">@@ -2398,7 +2397,7 @@
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         if ( $this-&gt;is_preview &amp;&amp; current_user_can( $edit_cap, $this-&gt;posts[0]-&gt;ID ) )
</span><del>-                                $this-&gt;posts[0] = apply_filters('the_preview', $this-&gt;posts[0]);
</del><ins>+                                $this-&gt;posts[0] = apply_filters_ref_array('the_preview', array( $this-&gt;posts[0], &amp;$this ));
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 // Put sticky posts at the top of the posts array
</span><span class="lines">@@ -2447,7 +2446,7 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ( !$q['suppress_filters'] )
</span><del>-                        $this-&gt;posts = apply_filters('the_posts', $this-&gt;posts);
</del><ins>+                        $this-&gt;posts = apply_filters_ref_array('the_posts', array( $this-&gt;posts, &amp;$this ) );
</ins><span class="cx"> 
</span><span class="cx">                 $this-&gt;post_count = count($this-&gt;posts);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>