W3cubDocs

/WordPress

WP_Comments_List_Table::comment_status_dropdown( string $comment_type )

Displays a comment status drop-down for filtering on the Comments list table.

Parameters

$comment_type

(string) (Required) The current comment type slug.

Source

File: wp-admin/includes/class-wp-comments-list-table.php

protected function comment_status_dropdown( $comment_type ) {
		/**
		 * Filters the comment types dropdown menu.
		 *
		 * @since 2.7.0
		 *
		 * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
		 */
		$comment_types = apply_filters(
			'admin_comment_types_dropdown',
			array(
				'comment' => esc_html__( 'Comments' ),
				'pings'   => esc_html__( 'Pings' ),
			)
		);

		if ( $comment_types && is_array( $comment_types ) ) {
			printf( '<label class="screen-reader-text" for="filter-by-comment-type">%s</label>', esc_html__( 'Filter by comment type' ) );

			echo '<select id="filter-by-comment-type" name="comment_type">';

			printf( "\t<option value=''>%s</option>", esc_html__( 'All comment types' ) );

			foreach ( $comment_types as $type => $label ) {
				if ( get_comments(
					array(
						'number' => 1,
						'type'   => $type,
					)
				) ) {
					printf(
						"\t<option value='%s'%s>%s</option>\n",
						esc_attr( $type ),
						selected( $comment_type, $type, false ),
						esc_html( $label )
					);
				}
			}
				echo '</select>';
		}
	}

Changelog

Version Description
5.5.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_comments_list_table/comment_status_dropdown