Automattic\WooCommerce\Internal\Admin\Settings
PaymentsProviders::enhance_extension_suggestion
Enhance a payment extension suggestion with additional information.
Method of the class: PaymentsProviders{}
No Hooks.
Returns
Array. The enhanced payment extension suggestion.
Usage
// private - for code of main (parent) class only $result = $this->enhance_extension_suggestion( $extension_suggestion ): array;
- $extension_suggestion(array) (required)
- The extension suggestion.
PaymentsProviders::enhance_extension_suggestion() PaymentsProviders::enhance extension suggestion code WC 10.7.0
private function enhance_extension_suggestion( array $extension_suggestion ): array {
// Determine the category of the extension.
switch ( $extension_suggestion['_type'] ) {
case ExtensionSuggestions::TYPE_PSP:
$extension_suggestion['category'] = self::CATEGORY_PSP;
break;
case ExtensionSuggestions::TYPE_EXPRESS_CHECKOUT:
$extension_suggestion['category'] = self::CATEGORY_EXPRESS_CHECKOUT;
break;
case ExtensionSuggestions::TYPE_BNPL:
$extension_suggestion['category'] = self::CATEGORY_BNPL;
break;
case ExtensionSuggestions::TYPE_CRYPTO:
$extension_suggestion['category'] = self::CATEGORY_CRYPTO;
break;
default:
$extension_suggestion['category'] = '';
break;
}
// Determine the PES's plugin status.
// Default to not installed.
$extension_suggestion['plugin']['status'] = self::EXTENSION_NOT_INSTALLED;
// Put in the default plugin file.
$extension_suggestion['plugin']['file'] = '';
if ( ! empty( $extension_suggestion['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_suggestion['plugin']['slug'], true );
// Favor active plugins by checking the entire variations list for active plugins first.
// This way we handle cases where there are multiple variations installed and one is active.
$found = false;
foreach ( $plugin_slug_variations as $plugin_slug ) {
if ( $this->proxy->call_static( PluginsHelper::class, 'is_plugin_active', $plugin_slug ) ) {
$found = true;
$extension_suggestion['plugin']['status'] = self::EXTENSION_ACTIVE;
// Make sure we put in the actual slug and file path that we found.
$extension_suggestion['plugin']['slug'] = $plugin_slug;
$extension_suggestion['plugin']['file'] = $this->proxy->call_static( PluginsHelper::class, 'get_plugin_path_from_slug', $plugin_slug );
// Sanity check.
if ( ! is_string( $extension_suggestion['plugin']['file'] ) ) {
$extension_suggestion['plugin']['file'] = '';
break;
}
// Remove the .php extension from the file path. The WP API expects it without it.
$extension_suggestion['plugin']['file'] = Utils::trim_php_file_extension( $extension_suggestion['plugin']['file'] );
break;
}
}
if ( ! $found ) {
foreach ( $plugin_slug_variations as $plugin_slug ) {
if ( $this->proxy->call_static( PluginsHelper::class, 'is_plugin_installed', $plugin_slug ) ) {
$extension_suggestion['plugin']['status'] = self::EXTENSION_INSTALLED;
// Make sure we put in the actual slug and file path that we found.
$extension_suggestion['plugin']['slug'] = $plugin_slug;
$extension_suggestion['plugin']['file'] = $this->proxy->call_static( PluginsHelper::class, 'get_plugin_path_from_slug', $plugin_slug );
// Sanity check.
if ( ! is_string( $extension_suggestion['plugin']['file'] ) ) {
$extension_suggestion['plugin']['file'] = '';
break;
}
// Remove the .php extension from the file path. The WP API expects it without it.
$extension_suggestion['plugin']['file'] = Utils::trim_php_file_extension( $extension_suggestion['plugin']['file'] );
break;
}
}
}
}
// Finally, allow the extension suggestion's matching provider to add further details.
$gateway_provider = $this->get_payment_extension_suggestion_provider_instance( $extension_suggestion['id'] );
$extension_suggestion = $gateway_provider->enhance_extension_suggestion( $extension_suggestion );
return $extension_suggestion;
}