Automattic\WooCommerce\Internal\Admin\Settings

PaymentProviders::enhance_extension_suggestion()privateWC 1.0

Enhance a payment extension suggestion with additional information.

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

Хуков нет.

Возвращает

Массив. The enhanced payment extension suggestion.

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

// private - только в коде основоного (родительского) класса
$result = $this->enhance_extension_suggestion( $extension ): array;
$extension(массив) (обязательный)
The extension suggestion.

Код PaymentProviders::enhance_extension_suggestion() WC 9.6.1

private function enhance_extension_suggestion( array $extension ): array {
	// Determine the category of the extension.
	switch ( $extension['_type'] ) {
		case ExtensionSuggestions::TYPE_PSP:
			$extension['category'] = self::CATEGORY_PSP;
			break;
		case ExtensionSuggestions::TYPE_EXPRESS_CHECKOUT:
			$extension['category'] = self::CATEGORY_EXPRESS_CHECKOUT;
			break;
		case ExtensionSuggestions::TYPE_BNPL:
			$extension['category'] = self::CATEGORY_BNPL;
			break;
		default:
			$extension['category'] = '';
			break;
	}

	// Determine the PES's plugin status.
	// Default to not installed.
	$extension['plugin']['status'] = self::EXTENSION_NOT_INSTALLED;
	// Put in the default plugin file.
	$extension['plugin']['file'] = '';
	if ( ! empty( $extension['plugin']['slug'] ) ) {
		// This is a best-effort approach, as the plugin might be sitting under a directory (slug) that we can't handle.
		// Always try the official plugin slug first, then the testing variations.
		$plugin_slug_variations = Utils::generate_testing_plugin_slugs( $extension['plugin']['slug'], true );
		foreach ( $plugin_slug_variations as $plugin_slug ) {
			if ( PluginsHelper::is_plugin_installed( $plugin_slug ) ) {
				// Make sure we put in the actual slug and file path that we found.
				$extension['plugin']['slug'] = $plugin_slug;
				$extension['plugin']['file'] = PluginsHelper::get_plugin_path_from_slug( $plugin_slug );
				// Remove the .php extension from the file path. The WP API expects it without it.
				if ( ! empty( $extension['plugin']['file'] ) && str_ends_with( $extension['plugin']['file'], '.php' ) ) {
					$extension['plugin']['file'] = substr( $extension['plugin']['file'], 0, -4 );
				}

				$extension['plugin']['status'] = self::EXTENSION_INSTALLED;
				if ( PluginsHelper::is_plugin_active( $plugin_slug ) ) {
					$extension['plugin']['status'] = self::EXTENSION_ACTIVE;
				}
				break;
			}
		}
	}

	return $extension;
}