From fdd091747154f0134671a65f922608347851aad3 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 23 Jun 2015 14:36:27 +0000 Subject: [PATCH] In `WP_Comment_Query`, parse meta_query vars after the `pre_get_comments` hook. [31467] included a change that involved generating meta_query SQL before the `pre_get_comments` hook, with the result that `pre_get_comments` callbacks were no longer able to modify comment meta queries. We fix the problem by moving the SQL generation to after the hook. This changeset also includes a second call to `meta_query->parse_query_vars()`, to ensure that modifications to metadata-related query vars (such as `meta_key` and `meta_value`) performed in `pre_get_comments` callbacks have the expected effect on the comment query. Fixes #32762. Built from https://develop.svn.wordpress.org/trunk@32911 git-svn-id: http://core.svn.wordpress.org/trunk@32882 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 10 ++++++---- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 80f30e2a8a..ccd8464c51 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -482,10 +482,6 @@ class WP_Comment_Query { $this->meta_query = new WP_Meta_Query(); $this->meta_query->parse_query_vars( $this->query_vars ); - if ( ! empty( $this->meta_query->queries ) ) { - $meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this ); - } - /** * Fires before comments are retrieved. * @@ -495,6 +491,12 @@ class WP_Comment_Query { */ do_action_ref_array( 'pre_get_comments', array( &$this ) ); + // Reparse query vars, in case they were modified in a 'pre_get_comments' callback. + $this->meta_query->parse_query_vars( $this->query_vars ); + if ( ! empty( $this->meta_query->queries ) ) { + $meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this ); + } + // $args can include anything. Only use the args defined in the query_var_defaults to compute the key. $key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) ); $last_changed = wp_cache_get( 'last_changed', 'comment' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 0a1a9337d2..3c7851a4fe 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-alpha-32910'; +$wp_version = '4.3-alpha-32911'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.