Automattic\WooCommerce\Utilities

PluginUtil::generate_incompatible_plugin_feature_warning()publicWC 1.0

Utility method to generate warning string for incompatible features based on active plugins.

Additionally, this method will manually print a warning message on the HPOS feature if both the Legacy REST API and HPOS are active.

Метод класса: PluginUtil{}

Возвращает

Строку. Warning string.

Использование

$PluginUtil = new PluginUtil();
$PluginUtil->generate_incompatible_plugin_feature_warning( $feature_id, $plugin_feature_info ): string;
$feature_id(строка) (обязательный)
Feature id.
$plugin_feature_info(массив) (обязательный)
Array of plugin feature info, as provided by FeaturesController->get_compatible_plugins_for_feature().

Код PluginUtil::generate_incompatible_plugin_feature_warning() WC 9.3.3

public function generate_incompatible_plugin_feature_warning( string $feature_id, array $plugin_feature_info ): string {
	$incompatibles      = $this->get_items_considered_incompatible( $feature_id, $plugin_feature_info );
	$incompatibles      = array_filter( $incompatibles, 'is_plugin_active' );
	$incompatibles      = array_values( array_diff( $incompatibles, $this->get_plugins_excluded_from_compatibility_ui() ) );
	$incompatible_count = count( $incompatibles );

	$feature_warnings = array();
	if ( 'custom_order_tables' === $feature_id && 'yes' === get_option( 'woocommerce_api_enabled' ) ) {
		if ( is_plugin_active( 'woocommerce-legacy-rest-api/woocommerce-legacy-rest-api.php' ) ) {
			$legacy_api_and_hpos_incompatibility_warning_text =
				sprintf(
					// translators: %s is a URL.
					__( '⚠ <b><a target="_blank" href="%s">The Legacy REST API plugin</a> is installed and active on this site.</b> Please be aware that the WooCommerce Legacy REST API is <b>not</b> compatible with HPOS.', 'woocommerce' ),
					'https://wordpress.org/plugins/woocommerce-legacy-rest-api/'
				);
		} else {
			$legacy_api_and_hpos_incompatibility_warning_text =
			sprintf(
				// translators: %s is a URL.
				__( '⚠ <b><a target="_blank" href="%s">The Legacy REST API</a> is active on this site.</b> Please be aware that the WooCommerce Legacy REST API is <b>not</b> compatible with HPOS.', 'woocommerce' ),
				admin_url( 'admin.php?page=wc-settings&tab=advanced&section=legacy_api' )
			);
		}

		/**
		 * Filter to modify the warning text that appears in the HPOS section of the features settings page
		 * when both the Legacy REST API is active (via WooCommerce core or via the Legacy REST API plugin)
		 * and the orders table is in use as the primary data store for orders.
		 *
		 * @param string $legacy_api_and_hpos_incompatibility_warning_text Original warning text.
		 * @returns string|null Actual warning text to use, or null to suppress the warning.
		 *
		 * @since 8.9.0
		 */
		$legacy_api_and_hpos_incompatibility_warning_text = apply_filters( 'woocommerce_legacy_api_and_hpos_incompatibility_warning_text', $legacy_api_and_hpos_incompatibility_warning_text );

		if ( ! is_null( $legacy_api_and_hpos_incompatibility_warning_text ) ) {
			$feature_warnings[] = $legacy_api_and_hpos_incompatibility_warning_text . "\n";
		}
	}

	if ( $incompatible_count > 0 ) {
		if ( 1 === $incompatible_count ) {
			/* translators: %s = printable plugin name */
			$feature_warnings[] = sprintf( __( '⚠ 1 Incompatible plugin detected (%s).', 'woocommerce' ), $this->get_plugin_name( $incompatibles[0] ) );
		} elseif ( 2 === $incompatible_count ) {
			$feature_warnings[] = sprintf(
				/* translators: %1\$s, %2\$s = printable plugin names */
				__( '⚠ 2 Incompatible plugins detected (%1$s and %2$s).', 'woocommerce' ),
				$this->get_plugin_name( $incompatibles[0] ),
				$this->get_plugin_name( $incompatibles[1] )
			);
		} else {
			$feature_warnings[] = sprintf(
				/* translators: %1\$s, %2\$s = printable plugin names, %3\$d = plugins count */
				_n(
					'⚠ Incompatible plugins detected (%1$s, %2$s and %3$d other).',
					'⚠ Incompatible plugins detected (%1$s and %2$s plugins and %3$d others).',
					$incompatible_count - 2,
					'woocommerce'
				),
				$this->get_plugin_name( $incompatibles[0] ),
				$this->get_plugin_name( $incompatibles[1] ),
				$incompatible_count - 2
			);
		}

		$incompatible_plugins_url = add_query_arg(
			array(
				'plugin_status' => 'incompatible_with_feature',
				'feature_id'    => $feature_id,
			),
			admin_url( 'plugins.php' )
		);

		$feature_warnings[] = sprintf(
			/* translators: %1$s opening link tag %2$s closing link tag. */
			__( '%1$sView and manage%2$s', 'woocommerce' ),
			'<a href="' . esc_url( $incompatible_plugins_url ) . '">',
			'</a>'
		);
	}

	return str_replace( "\n", '<br>', implode( "\n", $feature_warnings ) );
}