Automattic\WooCommerce\Internal\Features
FeaturesController::declare_compatibility
Declare (in)compatibility with a given feature for a given plugin.
This method MUST be executed from inside a handler for the before_woocommerce_init
The plugin name is expected to be in the form 'directory/file.php' and be one of the keys of the array returned by 'get_plugins', but this won't be checked. Plugins are expected to use FeaturesUtil::declare_compatibility instead, passing the full plugin file path instead of the plugin name.
Method of the class: FeaturesController{}
No Hooks.
Returns
true|false. True on success, false on error (feature doesn't exist or not inside the required hook).
Usage
$FeaturesController = new FeaturesController(); $FeaturesController->declare_compatibility( $feature_id, $plugin_file, $positive_compatibility ): bool;
- $feature_id(string) (required)
- Unique feature id.
- $plugin_file(string) (required)
- Plugin file path, either full or in the form
'directory/file.php'. - $positive_compatibility(true|false)
- True if the plugin declares being compatible with the feature, false if it declares being incompatible.
Default:true
FeaturesController::declare_compatibility() FeaturesController::declare compatibility code WC 10.8.1
public function declare_compatibility( string $feature_id, string $plugin_file, bool $positive_compatibility = true ): bool {
if ( ! $this->proxy->call_function( 'doing_action', 'before_woocommerce_init' ) ) {
$class_and_method = ( new \ReflectionClass( $this ) )->getShortName() . '::' . __FUNCTION__;
/* translators: 1: class::method 2: before_woocommerce_init */
$this->proxy->call_function( 'wc_doing_it_wrong', $class_and_method, sprintf( __( '%1$s should be called inside the %2$s action.', 'woocommerce' ), $class_and_method, 'before_woocommerce_init' ), '7.0' );
return false;
}
if ( ! $this->feature_exists( $feature_id ) ) {
return false;
}
if ( $this->lazy ) {
// Lazy mode: Queue to be normalized later.
$this->pending_declarations[] = array( $feature_id, $plugin_file, $positive_compatibility );
return true;
}
// Late call: Normalize and register immediately.
return $this->register_compatibility_internal( $feature_id, $plugin_file, $positive_compatibility );
}