Reviews.php
4 months ago
ReviewsCommentsOverrides.php
1 month ago
ReviewsListTable.php
4 months ago
ReviewsUtil.php
3 months ago
ReviewsCommentsOverrides.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Internal\Admin\ProductReviews; |
| 4 | |
| 5 | use WP_Comment_Query; |
| 6 | use WP_Screen; |
| 7 | |
| 8 | /** |
| 9 | * Tweaks the WordPress comments page to exclude reviews. |
| 10 | */ |
| 11 | class ReviewsCommentsOverrides { |
| 12 | |
| 13 | /** |
| 14 | * Constructor. |
| 15 | */ |
| 16 | public function __construct() { |
| 17 | add_filter( 'comments_list_table_query_args', array( $this, 'exclude_reviews_from_comments' ) ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Excludes product reviews from showing in the comments page. |
| 22 | * |
| 23 | * @param array|mixed $args {@see WP_Comment_Query} query args. |
| 24 | * @return array |
| 25 | * |
| 26 | * @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed. |
| 27 | */ |
| 28 | public function exclude_reviews_from_comments( $args ): array { |
| 29 | $screen = get_current_screen(); |
| 30 | |
| 31 | // We only wish to intervene if the edit comments screen has been requested. |
| 32 | if ( ! $screen instanceof WP_Screen || 'edit-comments' !== $screen->id ) { |
| 33 | return $args; |
| 34 | } |
| 35 | |
| 36 | if ( ! empty( $args['post_type'] ) && $args['post_type'] !== 'any' ) { |
| 37 | $post_types = (array) $args['post_type']; |
| 38 | } else { |
| 39 | $post_types = get_post_types(); |
| 40 | } |
| 41 | |
| 42 | $index = array_search( 'product', $post_types ); |
| 43 | |
| 44 | if ( $index !== false ) { |
| 45 | unset( $post_types[ $index ] ); |
| 46 | } |
| 47 | |
| 48 | if ( ! is_array( $args ) ) { |
| 49 | $args = []; |
| 50 | } |
| 51 | |
| 52 | $args['post_type'] = $post_types; |
| 53 | |
| 54 | return $args; |
| 55 | } |
| 56 | |
| 57 | } |
| 58 |