Ticket #40188: 40188.7.patch
File 40188.7.patch, 5.6 KB (added by , 7 years ago) |
---|
-
src/wp-admin/includes/class-wp-comments-list-table.php
diff --git src/wp-admin/includes/class-wp-comments-list-table.php src/wp-admin/includes/class-wp-comments-list-table.php index 37e65cf..2af30e4 100644
class WP_Comments_List_Table extends WP_List_Table { 323 323 if ( ! isset( $has_items ) ) { 324 324 $has_items = $this->has_items(); 325 325 } 326 ?> 327 <div class="alignleft actions"> 328 <?php 326 echo '<div class="alignleft actions">'; 327 329 328 if ( 'top' === $which ) { 330 ?> 331 <label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label> 332 <select id="filter-by-comment-type" name="comment_type"> 333 <option value=""><?php _e( 'All comment types' ); ?></option> 334 <?php 335 /** 336 * Filters the comment types dropdown menu. 337 * 338 * @since 2.7.0 339 * 340 * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'. 341 */ 342 $comment_types = apply_filters( 'admin_comment_types_dropdown', array( 343 'comment' => __( 'Comments' ), 344 'pings' => __( 'Pings' ), 345 ) ); 346 347 foreach ( $comment_types as $type => $label ) 348 echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n"; 349 ?> 350 </select> 351 <?php 329 330 ob_start(); 331 332 $this->comment_status_dropdown( $comment_type ); 333 352 334 /** 353 335 * Fires just before the Filter submit button for comment types. 354 336 * 355 337 * @since 3.5.0 356 338 */ 357 339 do_action( 'restrict_manage_comments' ); 358 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 359 } 340 341 $output = ob_get_clean(); 342 343 if( ! empty( $output ) && $this->has_items() ) { 344 echo $output; 345 submit_button( esc_html__( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); 346 } 347 } 360 348 361 349 if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $has_items ) { 362 350 wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); … … class WP_Comments_List_Table extends WP_List_Table { 375 363 } 376 364 377 365 /** 366 * Displays a comment status drop-down for filtering on the Comments list table. 367 * 368 * @since 4.9.0 369 * 370 * @param string $comment_type The current comment type slug. 371 */ 372 protected function comment_status_dropdown( $comment_type ) { 373 374 /** 375 * Filters the comment types dropdown menu. 376 * 377 * @since 2.7.0 378 * 379 * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'. 380 */ 381 $comment_types = apply_filters( 'admin_comment_types_dropdown', array( 382 'comment' => esc_html__( 'Comments' ), 383 'pings' => esc_html__( 'Pings' ), 384 ) ); 385 386 if( $comment_types && is_array( $comment_types ) ) { 387 388 printf( 389 '<label class="screen-reader-text" for="filter-by-comment-type">%s</label>', 390 esc_html__( 'Filter by comment type' ) 391 ); 392 393 echo '<select id="filter-by-comment-type" name="comment_type">'; 394 395 printf( 396 "\t<option value=''>%s</option>", 397 esc_html__( 'All comment types' ) 398 ); 399 400 foreach ( $comment_types as $type => $label ) { 401 if( get_comments( array( 'number' => 1, 'type' => $type ) ) ) { 402 printf ( 403 "\t<option value='%s'%s>%s</option>\n", 404 esc_attr( $type ), 405 selected( $comment_type, $type, false ), 406 esc_html( $label ) 407 ); 408 } 409 } 410 411 echo '</select>'; 412 } 413 } 414 415 /** 378 416 * @return string|false 379 417 */ 380 418 public function current_action() { -
tests/phpunit/tests/admin/includesListTable.php
diff --git tests/phpunit/tests/admin/includesListTable.php tests/phpunit/tests/admin/includesListTable.php index cf40457..fd9bdb8 100644
class Tests_Admin_includesListTable extends WP_UnitTestCase { 262 262 263 263 $this->assertNotContains( 'id="delete_all"', $output ); 264 264 } 265 266 /** 267 * @ticket 40188 268 */ 269 public function test_filter_button_should_not_be_shown_if_there_are_no_comments() { 270 $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 271 272 ob_start(); 273 $table->extra_tablenav( 'top' ); 274 $output = ob_get_clean(); 275 276 $this->assertNotContains( 'id="post-query-submit"', $output ); 277 } 278 279 /** 280 * @ticket 40188 281 */ 282 public function test_filter_button_should_be_shown_if_there_are_comments() { 283 284 $post_id = self::factory()->post->create(); 285 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, 'comment_approved' => '1' ) ); 286 287 $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 288 $table->prepare_items(); 289 290 ob_start(); 291 $table->extra_tablenav( 'top' ); 292 $output = ob_get_clean(); 293 294 $this->assertContains( 'id="post-query-submit"', $output ); 295 } 296 297 /** 298 * @ticket 40188 299 */ 300 public function test_filter_comment_status_dropdown_should_be_shown_if_there_are_comments() { 301 302 $post_id = self::factory()->post->create(); 303 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, 'comment_approved' => '1' ) ); 304 305 $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); 306 $table->prepare_items(); 307 308 ob_start(); 309 $table->extra_tablenav( 'top' ); 310 $output = ob_get_clean(); 311 312 $this->assertContains( 'id="filter-by-comment-type"', $output ); 313 $this->assertContains( "<option value='comment'>", $output ); 314 } 265 315 }