Automattic\WooCommerce\Internal\Features

FeaturesController::add_feature_definitionpublicWC 1.0

Register a feature.

This used to be called during the woocommerce_register_feature_definitions hook, now it's called directly from get_feature_definitions as needed.

Method of the class: FeaturesController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$FeaturesController = new FeaturesController();
$FeaturesController->add_feature_definition( $slug, $name, $args );
$slug(string) (required)
The ID slug of the feature.
$name(string) (required)
The name of the feature that will appear on the Features screen and elsewhere.
$args(array)

Properties that make up the feature definition. Each of these properties can also be set as a callback function, as long as that function returns the specified type.

Default: array()

  • default_plugin_compatibility(string)
    The default plugin compatibility for the feature: either 'compatible' or 'incompatible'. Required.

  • additional_settings(array[])
    An array of definitions for additional settings controls related to the feature that will display on the Features screen. See the Settings API for the schema of these props.

  • description(string)
    A brief description of the feature, used as an input label if the feature setting is a checkbox.

  • disabled(true|false)
    True to disable the setting field for this feature on the Features screen, so it can't be changed.

  • disable_ui(true|false)
    Set to true to hide the setting field for this feature on the Features screen.
    Default: false

  • enabled_by_default(true|false)
    Set to true to have this feature by opt-out instead of opt-in.
    Default: false

  • is_experimental(true|false)
    Set to true to display this feature under the "Experimental" heading on the Features screen. Features set to experimental are also omitted from the features list in some cases.
    Default: true

  • skip_compatibility_checks(true|false)
    Set to true if the feature should not produce warnings about incompatible plugins.
    Default: false

  • learn_more_url(string)
    The URL to the learn more page for the feature.

  • option_key(string)
    The key name for the option that enables/disables the feature.

  • order(int)
    The order that the feature will appear in the list on the Features screen. Higher number = higher in the list.
    Default: 10

  • setting(array)
    The properties used by the Settings API to render the setting control on the Features screen. See the Settings API for the schema of these props.

FeaturesController::add_feature_definition() code WC 10.3.6

public function add_feature_definition( $slug, $name, array $args = array() ) {
	$defaults = array(
		'disable_ui'                   => false,
		'enabled_by_default'           => false,
		'is_experimental'              => true,
		'default_plugin_compatibility' => FeaturePluginCompatibility::COMPATIBLE,
		'skip_compatibility_checks'    => false,
		'name'                         => $name,
		'order'                        => 10,
		'learn_more_url'               => '',
	);

	if ( empty( $args['default_plugin_compatibility'] ) ) {
		wc_doing_it_wrong(
			__FUNCTION__,
			sprintf(
				'Assuming positive compatibility by default will be deprecated in the future. Please set \'default_plugin_compatibility\' for feature "%s".',
				esc_html( $slug )
			),
			'10.3.0'
		);
	}

	$args = wp_parse_args( $args, $defaults );

	// Sanitize 'default_plugin_compatibility'.
	if ( ! in_array( $args['default_plugin_compatibility'], FeaturePluginCompatibility::VALID_REGISTRATION_VALUES, true ) ) {
		$args['default_plugin_compatibility'] = wc_string_to_bool( $args['default_plugin_compatibility'] ) ? FeaturePluginCompatibility::COMPATIBLE : FeaturePluginCompatibility::INCOMPATIBLE;
	}

	// Support 'is_legacy' flag for backwards compatibility.
	if ( ! empty( $args['is_legacy'] ) ) {
		$args['skip_compatibility_checks'] = true;
	}

	$this->features[ $slug ] = $args;
}