| | 1682 | |
| | 1683 | /** |
| | 1684 | * @ticket 32762 |
| | 1685 | */ |
| | 1686 | public function test_it_should_be_possible_to_modify_meta_query_using_pre_get_comments_action() { |
| | 1687 | $comments = $this->factory->comment->create_many( 2, array( |
| | 1688 | 'comment_post_ID' => $this->post_id, |
| | 1689 | ) ); |
| | 1690 | |
| | 1691 | add_comment_meta( $comments[1], 'foo', 'bar' ); |
| | 1692 | |
| | 1693 | add_action( 'pre_get_comments', array( $this, 'modify_meta_query' ) ); |
| | 1694 | |
| | 1695 | $q = new WP_Comment_Query( array( |
| | 1696 | 'comment_post_ID' => $this->post_id, |
| | 1697 | 'fields' => 'ids', |
| | 1698 | ) ); |
| | 1699 | |
| | 1700 | remove_action( 'pre_get_comments', array( $this, 'modify_meta_query' ) ); |
| | 1701 | |
| | 1702 | $this->assertEqualSets( array( $comments[1] ), $q->comments ); |
| | 1703 | } |
| | 1704 | |
| | 1705 | public function modify_meta_query( $q ) { |
| | 1706 | $q->meta_query = new WP_Meta_Query( array( |
| | 1707 | array( |
| | 1708 | 'key' => 'foo', |
| | 1709 | 'value' => 'bar', |
| | 1710 | ), |
| | 1711 | ) ); |
| | 1712 | } |
| | 1713 | |
| | 1714 | /** |
| | 1715 | * @ticket 32762 |
| | 1716 | */ |
| | 1717 | public function test_it_should_be_possible_to_modify_meta_params_using_pre_get_comments_action() { |
| | 1718 | $comments = $this->factory->comment->create_many( 2, array( |
| | 1719 | 'comment_post_ID' => $this->post_id, |
| | 1720 | ) ); |
| | 1721 | |
| | 1722 | add_comment_meta( $comments[1], 'foo', 'bar' ); |
| | 1723 | |
| | 1724 | add_action( 'pre_get_comments', array( $this, 'modify_meta_params' ) ); |
| | 1725 | |
| | 1726 | $q = new WP_Comment_Query( array( |
| | 1727 | 'comment_post_ID' => $this->post_id, |
| | 1728 | 'fields' => 'ids', |
| | 1729 | ) ); |
| | 1730 | |
| | 1731 | remove_action( 'pre_get_comments', array( $this, 'modify_meta_params' ) ); |
| | 1732 | |
| | 1733 | $this->assertEqualSets( array( $comments[1] ), $q->comments ); |
| | 1734 | } |
| | 1735 | |
| | 1736 | public function modify_meta_params( $q ) { |
| | 1737 | $q->query_vars['meta_key'] = 'foo'; |
| | 1738 | $q->query_vars['meta_value'] = 'bar'; |
| | 1739 | } |