Admin_Products_Filter::display_channel_select( string $post_type, string $which )

Summary

Display the channel select above the Products list table


Parameters

$post_type

(string) (Required)

$which

(string) (Required)


Return

(void)


Source

File: src/BigCommerce/Taxonomies/Channel/Admin_Products_Filter.php

	public function display_channel_select( $post_type, $which ) {
		if ( $post_type !== Product::NAME || $which !== 'top' ) {
			return;
		}

		$connections = new Connections();
		$channel_options = $connections->active();

		if ( count( $channel_options ) <= 1 ) {
			return; // one or zero channels available, so don't display the filter
		}

		try {
			$current = filter_input( INPUT_GET, Channel::NAME, FILTER_SANITIZE_STRING ) ?: $connections->primary()->slug;
		} catch ( Channel_Not_Found_Exception $e ) {
			$current = '';
		}

		printf( '<label for="filter-by-%s" class="screen-reader-text">%s</label>', esc_attr( Channel::NAME ), __( 'Filter by channel', 'bigcommerce' ) );
		printf( '<select name="%s" id="filter-by-%s">', esc_attr( Channel::NAME ), esc_attr( Channel::NAME ) );
		if ( $current === '' ) {
			// unlikely condition
			printf( '<option value="" selected="selected">%s</option>', __( 'Select a channel', 'bigcommerce' ) );
		}
		foreach ( $channel_options as $channel ) {
			printf( '<option value="%s" %s>%s</option>', esc_attr( $channel->slug ), selected( $channel->slug, $current, false ), esc_html( $channel->name ) );
		}
		echo '</select>';
	}

User Contributed Notes

You must log in before being able to contribute a note or feedback.