<!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 .= " AND ($wpdb->posts.post_password = '') ";
</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, &$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, &$this ) );
+                        $join = apply_filters_ref_array('posts_join', array( $join, &$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, &$this ) );
+                                $cwhere = apply_filters_ref_array('comment_feed_where', array( $cwhere, &$this ) );
+                                $cgroupby = apply_filters_ref_array('comment_feed_groupby', array( $cgroupby, &$this ) );
+                                $corderby = apply_filters_ref_array('comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
+                                $climits = apply_filters_ref_array('comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$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, &$this ) );
+                        $groupby        = apply_filters_ref_array( 'posts_groupby',                array( $groupby, &$this ) );
+                        $join                = apply_filters_ref_array( 'posts_join_paged',        array( $join, &$this ) );
+                        $orderby        = apply_filters_ref_array( 'posts_orderby',                array( $orderby, &$this ) );
+                        $distinct        = apply_filters_ref_array( 'posts_distinct',        array( $distinct, &$this ) );
+                        $limits                = apply_filters_ref_array( 'post_limits',                array( $limits, &$this ) );
+                        $fields                = apply_filters_ref_array( 'posts_fields',                array( $fields, &$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, &$this ) );
+                        $groupby        = apply_filters_ref_array( 'posts_groupby_request',                array( $groupby, &$this ) );
+                        $join                = apply_filters_ref_array( 'posts_join_request',        array( $join, &$this ) );
+                        $orderby        = apply_filters_ref_array( 'posts_orderby_request',                array( $orderby, &$this ) );
+                        $distinct        = apply_filters_ref_array( 'posts_distinct_request',        array( $distinct, &$this ) );
+                        $fields                = apply_filters_ref_array( 'posts_fields_request',                array( $fields, &$this ) );
+                        $limits                = apply_filters_ref_array( 'post_limits_request',                array( $limits, &$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->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
</span><span class="cx">                 if ( !$q['suppress_filters'] )
</span><del>-                        $this->request = apply_filters('posts_request', $this->request);
</del><ins>+                        $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) );
</ins><span class="cx">
</span><span class="cx">                 $this->posts = $wpdb->get_results($this->request);
</span><span class="cx">                 // Raw results filter. Prior to status checks.
</span><span class="cx">                 if ( !$q['suppress_filters'] )
</span><del>-                        $this->posts = apply_filters('posts_results', $this->posts);
</del><ins>+                        $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
</ins><span class="cx">
</span><span class="cx">                 if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
</span><del>-                        $cjoin = apply_filters('comment_feed_join', '');
-                        $cwhere = apply_filters('comment_feed_where', "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'");
-                        $cgroupby = apply_filters('comment_feed_groupby', '');
</del><ins>+                        $cjoin = apply_filters_ref_array('comment_feed_join', array( '', &$this ) );
+                        $cwhere = apply_filters_ref_array('comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
+                        $cgroupby = apply_filters_ref_array('comment_feed_groupby', array( '', &$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', &$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'), &$this ) );
</ins><span class="cx">                         $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits";
</span><span class="cx">                         $this->comments = $wpdb->get_results($comments_request);
</span><span class="cx">                         $this->comment_count = count($this->comments);
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 if ( !$q['no_found_rows'] && !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()', &$this ) );
</ins><span class="cx">                         $this->found_posts = $wpdb->get_var( $found_posts_query );
</span><del>-                        $this->found_posts = apply_filters( 'found_posts', $this->found_posts );
</del><ins>+                        $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) );
</ins><span class="cx">                         $this->max_num_pages = ceil($this->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->is_preview && current_user_can( $edit_cap, $this->posts[0]->ID ) )
</span><del>-                                $this->posts[0] = apply_filters('the_preview', $this->posts[0]);
</del><ins>+                                $this->posts[0] = apply_filters_ref_array('the_preview', array( $this->posts[0], &$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->posts = apply_filters('the_posts', $this->posts);
</del><ins>+                        $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) );
</ins><span class="cx">
</span><span class="cx">                 $this->post_count = count($this->posts);
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>