From 40ec420689950917988c0d90849ebd6a1471cb04 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 24 Oct 2014 02:51:19 +0000 Subject: [PATCH] Allow ORDER BY in `WP_Comment_Query::query()` to be disabled. Disable ORDER BY by passing boolean false, an empty array, or the string 'none' to the 'orderby parameter. This mirrors the behavior of `WP_Query`. Props psycleuk. Fixes #29902. Built from https://develop.svn.wordpress.org/trunk@30004 git-svn-id: http://core.svn.wordpress.org/trunk@30004 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 11 +++++++++-- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 20b208ed9e..c5776512c0 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -387,7 +387,10 @@ class WP_Comment_Query { $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC'; - if ( ! empty( $this->query_vars['orderby'] ) ) { + // Disable ORDER BY with 'none', an empty array, or boolean false. + if ( in_array( $this->query_vars['orderby'], array( 'none', array(), false ), true ) ) { + $orderby = ''; + } else if ( ! empty( $this->query_vars['orderby'] ) ) { $ordersby = is_array( $this->query_vars['orderby'] ) ? $this->query_vars['orderby'] : preg_split( '/[,\s]/', $this->query_vars['orderby'] ); @@ -588,7 +591,11 @@ class WP_Comment_Query { $groupby = 'GROUP BY ' . $groupby; } - $this->request = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby $orderby $order $limits"; + if ( $orderby ) { + $orderby = "ORDER BY $orderby $order"; + } + + $this->request = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby $orderby $limits"; if ( $this->query_vars['count'] ) { return $wpdb->get_var( $this->request ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 75feb8dba7..fd2566a64c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-alpha-30003'; +$wp_version = '4.1-alpha-30004'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.