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
$features_controller = wc_get_container()->get( FeaturesController::class );
[41] Fix | Delete
$feature = $features_controller->get_feature_definition( $feature_id );
[42] Fix | Delete
[43] Fix | Delete
// Log deprecation notice for deprecated features (only from the public API).
[44] Fix | Delete
if ( ! empty( $feature['deprecated_since'] ) ) {
[45] Fix | Delete
self::log_deprecated_feature_usage( $feature_id, $feature['deprecated_since'] );
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
return $features_controller->feature_is_enabled( $feature_id );
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Log usage of a deprecated feature.
[53] Fix | Delete
*
[54] Fix | Delete
* This method ensures logging only happens once per request to avoid spam.
[55] Fix | Delete
*
[56] Fix | Delete
* @param string $feature_id The feature id being checked.
[57] Fix | Delete
* @param string $deprecated_since The version since which the feature is deprecated.
[58] Fix | Delete
*/
[59] Fix | Delete
private static function log_deprecated_feature_usage( string $feature_id, string $deprecated_since ): void {
[60] Fix | Delete
static $logged = array();
[61] Fix | Delete
[62] Fix | Delete
if ( isset( $logged[ $feature_id ] ) ) {
[63] Fix | Delete
return;
[64] Fix | Delete
}
[65] Fix | Delete
$logged[ $feature_id ] = true;
[66] Fix | Delete
[67] Fix | Delete
wc_deprecated_function(
[68] Fix | Delete
"FeaturesUtil::feature_is_enabled('{$feature_id}')",
[69] Fix | Delete
$deprecated_since
[70] Fix | Delete
);
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Declare (in)compatibility with a given feature for a given plugin.
[75] Fix | Delete
*
[76] Fix | Delete
* This method MUST be executed from inside a handler for the 'before_woocommerce_init' hook and
[77] Fix | Delete
* SHOULD be executed from the main plugin file passing __FILE__ or 'my-plugin/my-plugin.php' for the
[78] Fix | Delete
* $plugin_file argument.
[79] Fix | Delete
*
[80] Fix | Delete
* @param string $feature_id Unique feature id.
[81] Fix | Delete
* @param string $plugin_file The full plugin file path.
[82] Fix | Delete
* @param bool $positive_compatibility True if the plugin declares being compatible with the feature, false if it declares being incompatible.
[83] Fix | Delete
* @return bool True on success, false on error (feature doesn't exist or not inside the required hook).
[84] Fix | Delete
*/
[85] Fix | Delete
public static function declare_compatibility( string $feature_id, string $plugin_file, bool $positive_compatibility = true ): bool {
[86] Fix | Delete
return wc_get_container()->get( FeaturesController::class )->declare_compatibility(
[87] Fix | Delete
$feature_id,
[88] Fix | Delete
$plugin_file,
[89] Fix | Delete
$positive_compatibility
[90] Fix | Delete
);
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Get the ids of the features that a certain plugin has declared compatibility for.
[95] Fix | Delete
*
[96] Fix | Delete
* This method can't be called before the 'woocommerce_init' hook is fired.
[97] Fix | Delete
*
[98] Fix | Delete
* @param string $plugin_name Plugin name, in the form 'directory/file.php'.
[99] Fix | Delete
* @return array An array having a 'compatible' and an 'incompatible' key, each holding an array of plugin ids.
[100] Fix | Delete
*/
[101] Fix | Delete
public static function get_compatible_features_for_plugin( string $plugin_name ): array {
[102] Fix | Delete
return wc_get_container()->get( FeaturesController::class )->get_compatible_features_for_plugin( $plugin_name );
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* Get the names of the plugins that have been declared compatible or incompatible with a given feature.
[107] Fix | Delete
*
[108] Fix | Delete
* @param string $feature_id Feature id.
[109] Fix | Delete
* @return array An array having a 'compatible' and an 'incompatible' key, each holding an array of plugin names.
[110] Fix | Delete
*/
[111] Fix | Delete
public static function get_compatible_plugins_for_feature( string $feature_id ): array {
[112] Fix | Delete
return wc_get_container()->get( FeaturesController::class )->get_compatible_plugins_for_feature( $feature_id );
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Sets a flag indicating that it's allowed to enable features for which incompatible plugins are active
[117] Fix | Delete
* from the WooCommerce feature settings page.
[118] Fix | Delete
*/
[119] Fix | Delete
public static function allow_enabling_features_with_incompatible_plugins(): void {
[120] Fix | Delete
wc_get_container()->get( FeaturesController::class )->allow_enabling_features_with_incompatible_plugins();
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Sets a flag indicating that it's allowed to activate plugins for which incompatible features are enabled
[125] Fix | Delete
* from the WordPress plugins page.
[126] Fix | Delete
*/
[127] Fix | Delete
public static function allow_activating_plugins_with_incompatible_features(): void {
[128] Fix | Delete
wc_get_container()->get( FeaturesController::class )->allow_activating_plugins_with_incompatible_features();
[129] Fix | Delete
}
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function