Automattic\WooCommerce\Internal\Features
FeaturesController::handle_plugins_page_views_list
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.
Returns
String[]. The actual views array to use.
Usage
$FeaturesController = new FeaturesController(); $FeaturesController->handle_plugins_page_views_list( $views ): array;
- $views(array) (required)
- An array of view ids => view links.
FeaturesController::handle_plugins_page_views_list() FeaturesController::handle plugins page views list code WC 10.3.3
public function handle_plugins_page_views_list( $views ): array {
// phpcs:disable WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
if ( 'incompatible_with_feature' !== ArrayUtil::get_value_or_default( $_GET, 'plugin_status' ) ) {
return $views;
}
$feature_id = $_GET['feature_id'] ?? 'all';
if ( 'all' !== $feature_id && ! $this->feature_exists( $feature_id ) ) {
return $views;
}
// phpcs:enable WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
$all_items = get_plugins();
$features = $this->get_feature_definitions();
$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' ), $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,
);
}