WP_Comments_List_Table::comment_type_dropdown()protectedWP 5.5.0

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

Method of the class: WP_Comments_List_Table{}

Hooks from the method

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->comment_type_dropdown( $comment_type );
$comment_type(string) (required)
The current comment type slug.

Changelog

Since 5.5.0 Introduced.
Since 5.6.0 Renamed from comment_status_dropdown() to comment_type_dropdown().

WP_Comments_List_Table::comment_type_dropdown() code WP 6.4.3

protected function comment_type_dropdown( $comment_type ) {
	/**
	 * Filters the comment types shown in the drop-down menu on the Comments list table.
	 *
	 * @since 2.7.0
	 *
	 * @param string[] $comment_types Array of comment type labels keyed by their name.
	 */
	$comment_types = apply_filters(
		'admin_comment_types_dropdown',
		array(
			'comment' => __( 'Comments' ),
			'pings'   => __( 'Pings' ),
		)
	);

	if ( $comment_types && is_array( $comment_types ) ) {
		printf(
			'<label class="screen-reader-text" for="filter-by-comment-type">%s</label>',
			/* translators: Hidden accessibility text. */
			__( 'Filter by comment type' )
		);

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

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

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

		echo '</select>';
	}
}