Ticket #40188: 40188.8.patch
File 40188.8.patch, 5.4 KB (added by , 4 years ago) |
---|
-
src/wp-admin/includes/class-wp-comments-list-table.php
diff --git a/src/wp-admin/includes/class-wp-comments-list-table.php b/src/wp-admin/includes/class-wp-comments-list-table.php index 5f0d373547..39dd8fe380 100644
a b class WP_Comments_List_Table extends WP_List_Table { 387 387 if ( ! isset( $has_items ) ) { 388 388 $has_items = $this->has_items(); 389 389 } 390 ?> 391 <div class="alignleft actions"> 392 <?php 390 echo '<div class="alignleft actions">'; 393 391 if ( 'top' === $which ) { 394 ?> 395 <label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label> 396 <select id="filter-by-comment-type" name="comment_type"> 397 <option value=""><?php _e( 'All comment types' ); ?></option> 398 <?php 399 /** 400 * Filters the comment types dropdown menu. 401 * 402 * @since 2.7.0 403 * 404 * @param string[] $comment_types An array of comment types. Accepts 'Comments', 'Pings'. 405 */ 406 $comment_types = apply_filters( 407 'admin_comment_types_dropdown', 408 array( 409 'comment' => __( 'Comments' ), 410 'pings' => __( 'Pings' ), 411 ) 412 ); 392 ob_start(); 413 393 414 foreach ( $comment_types as $type => $label ) { 415 echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n"; 416 } 417 ?> 418 </select> 419 <?php 394 $this->comment_status_dropdown( $comment_type ); 420 395 /** 421 396 * Fires just before the Filter submit button for comment types. 422 397 * 423 398 * @since 3.5.0 424 399 */ 425 400 do_action( 'restrict_manage_comments' ); 426 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 401 402 $output = ob_get_clean(); 403 404 if ( ! empty( $output ) && $this->has_items() ) { 405 echo $output; 406 submit_button( esc_html__( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 407 } 427 408 } 428 409 429 410 if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $has_items ) { … … class WP_Comments_List_Table extends WP_List_Table { 480 461 return $columns; 481 462 } 482 463 464 /** 465 * Displays a comment status drop-down for filtering on the Comments list table. 466 * 467 * @since 4.9.0 468 * 469 * @param string $comment_type The current comment type slug. 470 */ 471 protected function comment_status_dropdown( $comment_type ) { 472 /** 473 * Filters the comment types dropdown menu. 474 * 475 * @since 2.7.0 476 * 477 * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'. 478 */ 479 $comment_types = apply_filters( 'admin_comment_types_dropdown', array( 480 'comment' => esc_html__( 'Comments' ), 481 'pings' => esc_html__( 'Pings' ), 482 ) ); 483 484 if ( $comment_types && is_array( $comment_types ) ) { 485 printf( '<label class="screen-reader-text" for="filter-by-comment-type">%s</label>', esc_html__( 'Filter by comment type' ) ); 486 487 echo '<select id="filter-by-comment-type" name="comment_type">'; 488 489 printf( "\t<option value=''>%s</option>", esc_html__( 'All comment types' ) ); 490 491 foreach ( $comment_types as $type => $label ) { 492 if ( get_comments( array( 'number' => 1, 'type' => $type ) ) ) { 493 printf ( 494 "\t<option value='%s'%s>%s</option>\n", 495 esc_attr( $type ), 496 selected( $comment_type, $type, false ), 497 esc_html( $label ) 498 ); 499 } 500 } 501 echo '</select>'; 502 } 503 } 504 483 505 /** 484 506 * @return array 485 507 */ -
tests/phpunit/tests/admin/includesListTable.php
diff --git a/tests/phpunit/tests/admin/includesListTable.php b/tests/phpunit/tests/admin/includesListTable.php index 745b224e9c..3df69cdd67 100644
a b class Tests_Admin_includesListTable extends WP_UnitTestCase { 281 281 $this->assertNotContains( 'id="delete_all"', $output ); 282 282 } 283 283 284 /** 285 * @ticket 40188 286 */ 287 public function test_filter_button_should_not_be_shown_if_there_are_no_comments() { 288 $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 289 290 ob_start(); 291 $table->extra_tablenav( 'top' ); 292 $output = ob_get_clean(); 293 294 $this->assertNotContains( 'id="post-query-submit"', $output ); 295 } 296 297 /** 298 * @ticket 40188 299 */ 300 public function test_filter_button_should_be_shown_if_there_are_comments() { 301 $post_id = self::factory()->post->create(); 302 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, 'comment_approved' => '1' ) ); 303 304 $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 305 $table->prepare_items(); 306 307 ob_start(); 308 $table->extra_tablenav( 'top' ); 309 $output = ob_get_clean(); 310 311 $this->assertContains( 'id="post-query-submit"', $output ); 312 } 313 314 /** 315 * @ticket 40188 316 */ 317 public function test_filter_comment_status_dropdown_should_be_shown_if_there_are_comments() { 318 $post_id = self::factory()->post->create(); 319 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, 'comment_approved' => '1' ) ); 320 321 $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 322 $table->prepare_items(); 323 324 ob_start(); 325 $table->extra_tablenav( 'top' ); 326 $output = ob_get_clean(); 327 328 $this->assertContains( 'id="filter-by-comment-type"', $output ); 329 $this->assertContains( "<option value='comment'>", $output ); 330 } 331 284 332 /** 285 333 * @ticket 38341 286 334 */