Automattic\WooCommerce\Internal\Features

FeaturesController::add_feature_definition()publicWC 1.0

Register a feature.

This should be called during the woocommerce_register_feature_definitions hook.

Method of the class: FeaturesController{}

No Hooks.

Return

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()

  • 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

  • is_legacy(true|false)
    Set to true if this feature existed before the FeaturesController class was introduced. Features set to legacy also do not produce warnings about incompatible plugins.
    Default: false

  • 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 9.3.3

public function add_feature_definition( $slug, $name, array $args = array() ) {
	$defaults = array(
		'disable_ui'                          => false,
		'enabled_by_default'                  => false,
		'is_experimental'                     => true,
		'is_legacy'                           => false,
		'plugins_are_incompatible_by_default' => false,
		'name'                                => $name,
		'order'                               => 10,
	);
	$args     = wp_parse_args( $args, $defaults );

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