WP_Comments_List_Table::comment_status_dropdown

Advertisement

Summery Summery

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

Syntax Syntax

WP_Comments_List_Table::comment_status_dropdown( string $comment_type )

Parameters Parameters

$comment_type

(Required) The current comment type slug.

Source 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>';
		}
	}

Advertisement

Changelog Changelog

Changelog
Version Description
5.5.0 Introduced.

Advertisement

Leave a Reply