Automattic\WooCommerce\Internal\Features

FeaturesController::handle_plugin_list_rows()privateWC 1.0

Handler for the after_plugin_row Displays a "This plugin is incompatible with X features" notice if necessary.

Method of the class: FeaturesController{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->handle_plugin_list_rows( $plugin_file, $plugin_data );
$plugin_file(string) (required)
The id of the plugin for which a row has been rendered in the plugins page.
$plugin_data(array) (required)
Plugin data, as returned by 'get_plugins'.

FeaturesController::handle_plugin_list_rows() code WC 8.7.0

<?php
private function handle_plugin_list_rows( $plugin_file, $plugin_data ) {
	global $wp_list_table;

	if ( 'incompatible_with_feature' !== ArrayUtil::get_value_or_default( $_GET, 'plugin_status' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
		return;
	}

	if ( is_null( $wp_list_table ) || ! $this->plugin_util->is_woocommerce_aware_plugin( $plugin_data ) ) {
		return;
	}

	if ( ! $this->proxy->call_function( 'is_plugin_active', $plugin_file ) ) {
		return;
	}

	$features                   = $this->get_feature_definitions();
	$feature_compatibility_info = $this->get_compatible_features_for_plugin( $plugin_file, true );
	$incompatible_features      = array_merge( $feature_compatibility_info['incompatible'], $feature_compatibility_info['uncertain'] );
	$incompatible_features      = array_values(
		array_filter(
			$incompatible_features,
			function( $feature_id ) {
				return ! $this->is_legacy_feature( $feature_id );
			}
		)
	);

	$incompatible_features_count = count( $incompatible_features );
	if ( $incompatible_features_count > 0 ) {
		$columns_count      = $wp_list_table->get_column_count();
		$is_active          = true; // For now we are showing active plugins in the "Incompatible with..." view.
		$is_active_class    = $is_active ? 'active' : 'inactive';
		$is_active_td_style = $is_active ? " style='border-left: 4px solid #72aee6;'" : '';

		if ( 1 === $incompatible_features_count ) {
			$message = sprintf(
				/* translators: %s = printable plugin name */
				__( "⚠ This plugin is incompatible with the enabled WooCommerce feature '%s', it shouldn't be activated.", 'woocommerce' ),
				$features[ $incompatible_features[0] ]['name']
			);
		} elseif ( 2 === $incompatible_features_count ) {
			/* translators: %1\$s, %2\$s = printable plugin names */
			$message = sprintf(
				__( "⚠ This plugin is incompatible with the enabled WooCommerce features '%1\$s' and '%2\$s', it shouldn't be activated.", 'woocommerce' ),
				$features[ $incompatible_features[0] ]['name'],
				$features[ $incompatible_features[1] ]['name']
			);
		} else {
			/* translators: %1\$s, %2\$s = printable plugin names, %3\$d = plugins count */
			$message = sprintf(
				__( "⚠ This plugin is incompatible with the enabled WooCommerce features '%1\$s', '%2\$s' and %3\$d more, it shouldn't be activated.", 'woocommerce' ),
				$features[ $incompatible_features[0] ]['name'],
				$features[ $incompatible_features[1] ]['name'],
				$incompatible_features_count - 2
			);
		}
		$features_page_url       = $this->get_features_page_url();
		$manage_features_message = __( 'Manage WooCommerce features', 'woocommerce' );

		// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
		?>
		<tr class='plugin-update-tr update <?php echo $is_active_class; ?>' data-plugin='<?php echo $plugin_file; ?>' data-plugin-row-type='feature-incomp-warn'>
			<td colspan='<?php echo $columns_count; ?>' class='plugin-update'<?php echo $is_active_td_style; ?>>
				<div class='notice inline notice-warning notice-alt'>
					<p>
						<?php echo $message; ?>
						<a href="<?php echo $features_page_url; ?>"><?php echo $manage_features_message; ?></a>
					</p>
				</div>
			</td>
		</tr>
		<?php
		// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
	}
}