Comments: Restore the ability to bypass post_id filter using 0 or '0'.
The changes introduced in [36381], while logical and clearly awesome, introduce the potential for much breakage. Those who want to query for comments with a null `comment_post_ID` should use `'post_in' => array( 0 )` instead. Reverts [36381], [36387]. See #35090. git-svn-id: https://develop.svn.wordpress.org/trunk@36480 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3ec4faf6e3
commit
ef99ae21be
@ -33,14 +33,14 @@ class WP_Comments_List_Table extends WP_List_Table {
|
||||
*
|
||||
* @see WP_List_Table::__construct() for more information on default arguments.
|
||||
*
|
||||
* @global int|bool $post_id
|
||||
* @global int $post_id
|
||||
*
|
||||
* @param array $args An associative array of arguments.
|
||||
*/
|
||||
public function __construct( $args = array() ) {
|
||||
global $post_id;
|
||||
|
||||
$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : false;
|
||||
$post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
|
||||
|
||||
if ( get_option( 'show_avatars' ) ) {
|
||||
add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 );
|
||||
@ -69,7 +69,7 @@ class WP_Comments_List_Table extends WP_List_Table {
|
||||
|
||||
/**
|
||||
*
|
||||
* @global int|bool $post_id
|
||||
* @global int $post_id
|
||||
* @global string $comment_status
|
||||
* @global string $search
|
||||
* @global string $comment_type
|
||||
@ -192,7 +192,7 @@ class WP_Comments_List_Table extends WP_List_Table {
|
||||
|
||||
/**
|
||||
*
|
||||
* @global int|bool $post_id
|
||||
* @global int $post_id
|
||||
* @global string $comment_status
|
||||
* @global string $comment_type
|
||||
*/
|
||||
@ -383,7 +383,7 @@ class WP_Comments_List_Table extends WP_List_Table {
|
||||
|
||||
/**
|
||||
*
|
||||
* @global int|bool $post_id
|
||||
* @global int $post_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
@ -214,7 +214,7 @@ class WP_Comment_Query {
|
||||
* Default empty.
|
||||
* @type int $post_ID Currently unused.
|
||||
* @type int $post_id Limit results to those affiliated with a given post ID.
|
||||
* Default null.
|
||||
* Default 0.
|
||||
* @type array $post__in Array of post IDs to include affiliated comments for.
|
||||
* Default empty.
|
||||
* @type array $post__not_in Array of post IDs to exclude affiliated comments for.
|
||||
@ -278,7 +278,7 @@ class WP_Comment_Query {
|
||||
'post_author__in' => '',
|
||||
'post_author__not_in' => '',
|
||||
'post_ID' => '',
|
||||
'post_id' => null,
|
||||
'post_id' => 0,
|
||||
'post__in' => '',
|
||||
'post__not_in' => '',
|
||||
'post_author' => '',
|
||||
@ -647,8 +647,9 @@ class WP_Comment_Query {
|
||||
$fields = "$wpdb->comments.comment_ID";
|
||||
}
|
||||
|
||||
if ( strlen( $this->query_vars['post_id'] ) ) {
|
||||
$this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $this->query_vars['post_id'] );
|
||||
$post_id = absint( $this->query_vars['post_id'] );
|
||||
if ( ! empty( $post_id ) ) {
|
||||
$this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id );
|
||||
}
|
||||
|
||||
// Parse comment IDs for an IN clause.
|
||||
|
@ -36,12 +36,8 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_0_should_return_comments_with_no_parent() {
|
||||
public function test_query_post_id_0() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
@ -49,71 +45,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_string_0_should_return_comments_with_no_parent() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
'post_id' => '0',
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_null_should_be_ignored() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
'post_id' => null,
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c1, $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_false_should_be_ignored() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
'post_id' => false,
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c1, $c2 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35090
|
||||
*/
|
||||
public function test_post_id_empty_string_should_be_ignored() {
|
||||
$c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
|
||||
$c2 = self::factory()->comment->create( array( 'comment_post_ID' => 0, 'comment_approved' => '1' ) );
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
$found = $q->query( array(
|
||||
'post_id' => '',
|
||||
'fields' => 'ids',
|
||||
) );
|
||||
|
||||
$this->assertEqualSets( array( $c1, $c2 ), $found );
|
||||
$this->assertEqualSets( array( $c1 ), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user