Automattic\WooCommerce\Internal\Features

FeaturesController::handle_plugins_page_views_list()privateWC 1.0

Handler for the 'views_plugins' hook that shows the links to the different views in the plugins page. If we come from a "Manage incompatible plugins" in the features page we'll show just two views: "All" (so that it's easy to go back to a known state) and "Incompatible with X". We'll skip the rest of the views since the counts are wrong anyway, as we are modifying the plugins list via the all_plugins

Method of the class: FeaturesController{}

No Hooks.

Return

String[]. The actual views array to use.

Usage

// private - for code of main (parent) class only
$result = $this->handle_plugins_page_views_list( $views ): array;
$views(array) (required)
An array of view ids => view links.

FeaturesController::handle_plugins_page_views_list() code WC 7.1.0

private function handle_plugins_page_views_list( $views ): array {
	// phpcs:disable WordPress.Security.NonceVerification
	if ( 'incompatible_with_feature' !== ArrayUtil::get_value_or_default( $_GET, 'plugin_status' ) ) {
		return $views;
	}

	$feature_id = ArrayUtil::get_value_or_default( $_GET, 'feature_id', 'all' );
	if ( 'all' !== $feature_id && ! $this->feature_exists( $feature_id ) ) {
		return $views;
	}
	// phpcs:enable WordPress.Security.NonceVerification

	$all_items = get_plugins();

	$incompatible_plugins_count = count( $this->filter_plugins_list( $all_items ) );
	$incompatible_text          =
		'all' === $feature_id
		? __( 'Incompatible with WooCommerce features', 'woocommerce' )
		/* translators: %s = name of a WooCommerce feature */
		: sprintf( __( "Incompatible with '%s'", 'woocommerce' ), $this->features[ $feature_id ]['name'] );
	$incompatible_link = "<a href='plugins.php?plugin_status=incompatible_with_feature&feature_id={$feature_id}' class='current' aria-current='page'>{$incompatible_text} <span class='count'>({$incompatible_plugins_count})</span></a>";

	$all_plugins_count = count( $all_items );
	$all_text          = __( 'All', 'woocommerce' );
	$all_link          = "<a href='plugins.php?plugin_status=all'>{$all_text} <span class='count'>({$all_plugins_count})</span></a>";

	return array(
		'all'                       => $all_link,
		'incompatible_with_feature' => $incompatible_link,
	);
}