Automattic\WooCommerce\Internal\Features

FeaturesController::get_compatible_features_for_plugin()publicWC 1.0

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.

{} Это метод класса: FeaturesController{}

Хуков нет.

Возвращает

Массив. An array having a 'compatible' and an 'incompatible' key, each holding an array of feature ids.

Использование

$FeaturesController = new FeaturesController();
$FeaturesController->get_compatible_features_for_plugin( $plugin_name, $enabled_features_only ) : array;
$plugin_name(строка) (обязательный)
Plugin name, in the form 'directory/file.php'.
$enabled_features_only(true|false)
True to return only names of enabled plugins.
По умолчанию: false

Код FeaturesController::get_compatible_features_for_plugin() WC 7.1.0

public function get_compatible_features_for_plugin( string $plugin_name, bool $enabled_features_only = false ) : array {
	$this->verify_did_woocommerce_init( __FUNCTION__ );

	$features = $this->features;
	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(
			'compatible'   => array(),
			'incompatible' => array(),
			'uncertain'    => array_keys( $features ),
		);
	}

	$info                 = $this->compatibility_info_by_plugin[ $plugin_name ];
	$info['compatible']   = array_values( array_intersect( array_keys( $features ), $info['compatible'] ) );
	$info['incompatible'] = array_values( array_intersect( array_keys( $features ), $info['incompatible'] ) );
	$info['uncertain']    = array_values( array_diff( array_keys( $features ), $info['compatible'], $info['incompatible'] ) );

	return $info;
}