Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Utilitie...
File: FeaturesUtil.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* FeaturesUtil class file.
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace Automattic\WooCommerce\Utilities;
[5] Fix | Delete
[6] Fix | Delete
use Automattic\WooCommerce\Internal\Features\FeaturesController;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Class with methods that allow to retrieve information about the existing WooCommerce features,
[10] Fix | Delete
* also has methods for WooCommerce plugins to declare (in)compatibility with the features.
[11] Fix | Delete
*/
[12] Fix | Delete
class FeaturesUtil {
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Get all the existing WooCommerce features.
[16] Fix | Delete
*
[17] Fix | Delete
* Returns an associative array where keys are unique feature ids
[18] Fix | Delete
* and values are arrays with these keys:
[19] Fix | Delete
*
[20] Fix | Delete
* - name
[21] Fix | Delete
* - description
[22] Fix | Delete
* - is_experimental
[23] Fix | Delete
* - is_enabled (if $include_enabled_info is passed as true)
[24] Fix | Delete
*
[25] Fix | Delete
* @param bool $include_experimental Include also experimental/work in progress features in the list.
[26] Fix | Delete
* @param bool $include_enabled_info True to include the 'is_enabled' field in the returned features info.
[27] Fix | Delete
* @returns array An array of information about existing features.
[28] Fix | Delete
*/
[29] Fix | Delete
public static function get_features( bool $include_experimental = false, bool $include_enabled_info = false ): array {
[30] Fix | Delete
return wc_get_container()->get( FeaturesController::class )->get_features( $include_experimental, $include_enabled_info );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Check if a given feature is currently enabled.
[35] Fix | Delete
*
[36] Fix | Delete
* @param string $feature_id Unique feature id.
[37] Fix | Delete
* @return bool True if the feature is enabled, false if not or if the feature doesn't exist.
[38] Fix | Delete
*/
[39] Fix | Delete
public static function feature_is_enabled( string $feature_id ): bool {
[40] Fix | Delete
return wc_get_container()->get( FeaturesController::class )->feature_is_enabled( $feature_id );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Declare (in)compatibility with a given feature for a given plugin.
[45] Fix | Delete
*
[46] Fix | Delete
* This method MUST be executed from inside a handler for the 'before_woocommerce_init' hook and
[47] Fix | Delete
* SHOULD be executed from the main plugin file passing __FILE__ or 'my-plugin/my-plugin.php' for the
[48] Fix | Delete
* $plugin_file argument.
[49] Fix | Delete
*
[50] Fix | Delete
* @param string $feature_id Unique feature id.
[51] Fix | Delete
* @param string $plugin_file The full plugin file path.
[52] Fix | Delete
* @param bool $positive_compatibility True if the plugin declares being compatible with the feature, false if it declares being incompatible.
[53] Fix | Delete
* @return bool True on success, false on error (feature doesn't exist or not inside the required hook).
[54] Fix | Delete
*/
[55] Fix | Delete
public static function declare_compatibility( string $feature_id, string $plugin_file, bool $positive_compatibility = true ): bool {
[56] Fix | Delete
return wc_get_container()->get( FeaturesController::class )->declare_compatibility(
[57] Fix | Delete
$feature_id,
[58] Fix | Delete
$plugin_file,
[59] Fix | Delete
$positive_compatibility
[60] Fix | Delete
);
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* Get the ids of the features that a certain plugin has declared compatibility for.
[65] Fix | Delete
*
[66] Fix | Delete
* This method can't be called before the 'woocommerce_init' hook is fired.
[67] Fix | Delete
*
[68] Fix | Delete
* @param string $plugin_name Plugin name, in the form 'directory/file.php'.
[69] Fix | Delete
* @return array An array having a 'compatible' and an 'incompatible' key, each holding an array of plugin ids.
[70] Fix | Delete
*/
[71] Fix | Delete
public static function get_compatible_features_for_plugin( string $plugin_name ): array {
[72] Fix | Delete
return wc_get_container()->get( FeaturesController::class )->get_compatible_features_for_plugin( $plugin_name );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Get the names of the plugins that have been declared compatible or incompatible with a given feature.
[77] Fix | Delete
*
[78] Fix | Delete
* @param string $feature_id Feature id.
[79] Fix | Delete
* @return array An array having a 'compatible' and an 'incompatible' key, each holding an array of plugin names.
[80] Fix | Delete
*/
[81] Fix | Delete
public static function get_compatible_plugins_for_feature( string $feature_id ): array {
[82] Fix | Delete
return wc_get_container()->get( FeaturesController::class )->get_compatible_plugins_for_feature( $feature_id );
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Sets a flag indicating that it's allowed to enable features for which incompatible plugins are active
[87] Fix | Delete
* from the WooCommerce feature settings page.
[88] Fix | Delete
*/
[89] Fix | Delete
public static function allow_enabling_features_with_incompatible_plugins(): void {
[90] Fix | Delete
wc_get_container()->get( FeaturesController::class )->allow_enabling_features_with_incompatible_plugins();
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Sets a flag indicating that it's allowed to activate plugins for which incompatible features are enabled
[95] Fix | Delete
* from the WordPress plugins page.
[96] Fix | Delete
*/
[97] Fix | Delete
public static function allow_activating_plugins_with_incompatible_features(): void {
[98] Fix | Delete
wc_get_container()->get( FeaturesController::class )->allow_activating_plugins_with_incompatible_features();
[99] Fix | Delete
}
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function