Automattic\WooCommerce\Internal\Features
FeaturesController::get_compatible_features_for_plugin
Get the ids of the features that a certain plugin has declared compatibility for.
This method can't be called before the woocommerce_init is fired.
Method of the class: FeaturesController{}
No Hooks.
Returns
Array. An array having a 'compatible' and an 'incompatible' key, each holding an array of feature ids.
Usage
$FeaturesController = new FeaturesController(); $FeaturesController->get_compatible_features_for_plugin( $plugin_name, $enabled_features_only, $resolve_uncertain ): array;
- $plugin_name(string) (required)
- Plugin name, in the form
'directory/file.php'. - $enabled_features_only(true|false)
- True to return only names of enabled plugins.
Default:false - $resolve_uncertain(true|false)
- True to resolve the uncertain features to compatible or incompatible.
Default:false
FeaturesController::get_compatible_features_for_plugin() FeaturesController::get compatible features for plugin code WC 10.8.1
public function get_compatible_features_for_plugin( string $plugin_name, bool $enabled_features_only = false, bool $resolve_uncertain = false ): array {
$this->process_pending_declarations();
$this->verify_did_woocommerce_init( __FUNCTION__ );
$features = $this->get_feature_definitions();
if ( $enabled_features_only ) {
$features = array_filter(
$features,
array( $this, 'feature_is_enabled' ),
ARRAY_FILTER_USE_KEY
);
}
if ( ! isset( $this->compatibility_info_by_plugin[ $plugin_name ] ) ) {
return array(
FeaturePluginCompatibility::COMPATIBLE => array(),
FeaturePluginCompatibility::INCOMPATIBLE => array(),
FeaturePluginCompatibility::UNCERTAIN => array_keys( $features ),
);
}
$info = $this->compatibility_info_by_plugin[ $plugin_name ];
$info[ FeaturePluginCompatibility::COMPATIBLE ] = array_values( array_intersect( array_keys( $features ), $info[ FeaturePluginCompatibility::COMPATIBLE ] ) );
$info[ FeaturePluginCompatibility::INCOMPATIBLE ] = array_values( array_intersect( array_keys( $features ), $info[ FeaturePluginCompatibility::INCOMPATIBLE ] ) );
$info[ FeaturePluginCompatibility::UNCERTAIN ] = array_values( array_diff( array_keys( $features ), $info[ FeaturePluginCompatibility::COMPATIBLE ], $info[ FeaturePluginCompatibility::INCOMPATIBLE ] ) );
if ( $resolve_uncertain ) {
foreach ( $info[ FeaturePluginCompatibility::UNCERTAIN ] as $feature_id ) {
$key = $this->get_default_plugin_compatibility( $feature_id );
$info[ $key ][] = $feature_id;
}
$info[ FeaturePluginCompatibility::UNCERTAIN ] = array();
}
return $info;
}