Automattic\WooCommerce\Internal\Admin\Suggestions
PaymentsExtensionSuggestions::get_by_plugin_slug
Get the base details of a payment extension by its plugin slug.
If there are multiple extensions with the same plugin slug, the first one found will be returned.
Method of the class: PaymentsExtensionSuggestions{}
No Hooks.
Returns
Array|null. The extension details for the given plugin slug. Null if not found or the slug is empty.
Usage
$PaymentsExtensionSuggestions = new PaymentsExtensionSuggestions(); $PaymentsExtensionSuggestions->get_by_plugin_slug( $plugin_slug, $country_code, $context ): ?array;
- $plugin_slug(string) (required)
- The plugin slug.
- $country_code(string)
- The two-letter country code for which the extension suggestion should be retrieved.
Default: '' - $context(string)
- The context ID of where this extension suggestion is being used.
Default: ''
PaymentsExtensionSuggestions::get_by_plugin_slug() PaymentsExtensionSuggestions::get by plugin slug code WC 10.3.3
public function get_by_plugin_slug( string $plugin_slug, string $country_code = '', string $context = '' ): ?array {
$plugin_slug = sanitize_title( $plugin_slug );
if ( empty( $plugin_slug ) ) {
return null;
}
// If we have a country code, try to find a fully localized extension suggestion.
if ( ! empty( $country_code ) ) {
$extensions = $this->get_country_extensions( $country_code, $context );
foreach ( $extensions as $extension_details ) {
if ( isset( $extension_details['plugin']['slug'] ) &&
$plugin_slug === $extension_details['plugin']['slug']
) {
// The extension details are already standardized.
return $extension_details;
}
}
}
// Fallback to the base details.
$extensions = $this->get_all_extensions_base_details();
foreach ( $extensions as $extension_id => $extension_details ) {
if ( isset( $extension_details['plugin']['slug'] ) &&
$plugin_slug === $extension_details['plugin']['slug']
) {
$extension_details['id'] = $extension_id;
$extension_details['_priority'] = 0;
return $this->standardize_extension_details( $extension_details );
}
}
return null;
}