Automattic\WooCommerce\Internal\Features

FeaturesController::add_feature_settings()privateWC 1.0

Handler for the 'woocommerce_get_settings_advanced' hook, it adds the settings UI for all the existing features.

Note that the settings added via the woocommerce_settings_features will be displayed in the non-experimental features section.

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

Хуки из метода

Возвращает

Массив. The updated settings array.

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

// private - только в коде основоного (родительского) класса
$result = $this->add_feature_settings( $settings, $current_section ): array;
$settings(массив) (обязательный)
The existing settings for the corresponding settings section.
$current_section(строка) (обязательный)
The section to get the settings for.

Код FeaturesController::add_feature_settings() WC 8.7.0

private function add_feature_settings( $settings, $current_section ): array {
	if ( 'features' !== $current_section ) {
		return $settings;
	}

	$feature_settings = array(
		array(
			'title' => __( 'Features', 'woocommerce' ),
			'type'  => 'title',
			'desc'  => __( 'Start using new features that are being progressively rolled out to improve the store management experience.', 'woocommerce' ),
			'id'    => 'features_options',
		),
	);

	$features = $this->get_features( true );

	$feature_ids              = array_keys( $features );
	usort( $feature_ids, function( $feature_id_a, $feature_id_b ) use ( $features ) {
		return ( $features[ $feature_id_b ]['order'] ?? 0 ) <=> ( $features[ $feature_id_a ]['order'] ?? 0 );
	} );
	$experimental_feature_ids = array_filter(
		$feature_ids,
		function( $feature_id ) use ( $features ) {
			return $features[ $feature_id ]['is_experimental'] ?? false;
		}
	);
	$mature_feature_ids       = array_diff( $feature_ids, $experimental_feature_ids );
	$feature_ids              = array_merge( $mature_feature_ids, array( 'mature_features_end' ), $experimental_feature_ids );

	foreach ( $feature_ids as $id ) {
		if ( 'mature_features_end' === $id ) {
			// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
			/**
			 * Filter allowing to add additional settings to the WooCommerce Advanced - Features settings page.
			 *
			 * @param bool $disabled False.
			 */
			$feature_settings = apply_filters( 'woocommerce_settings_features', $feature_settings );
			// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment

			if ( ! empty( $experimental_feature_ids ) ) {
				$feature_settings[] = array(
					'type' => 'sectionend',
					'id'   => 'features_options',
				);

				$feature_settings[] = array(
					'title' => __( 'Experimental features', 'woocommerce' ),
					'type'  => 'title',
					'desc'  => __( 'These features are either experimental or incomplete, enable them at your own risk!', 'woocommerce' ),
					'id'    => 'experimental_features_options',
				);
			}
			continue;
		}

		if ( isset( $features[ $id ]['disable_ui'] ) && $features[ $id ]['disable_ui'] ) {
			continue;
		}

		$feature_settings[] = $this->get_setting_for_feature( $id, $features[ $id ] );

		$additional_settings = $features[ $id ]['additional_settings'] ?? array();
		if ( count( $additional_settings ) > 0 ) {
			$feature_settings = array_merge( $feature_settings, $additional_settings );
		}
	}

	$feature_settings[] = array(
		'type' => 'sectionend',
		'id'   => empty( $experimental_feature_ids ) ? 'features_options' : 'experimental_features_options',
	);

	if ( $this->verify_did_woocommerce_init() ) {
		// Allow feature setting properties to be determined dynamically just before being rendered.
		$feature_settings = array_map(
			function( $feature_setting ) {
				foreach ( $feature_setting as $prop => $value ) {
					if ( is_callable( $value ) ) {
						$feature_setting[ $prop ] = call_user_func( $value );
					}
				}

				return $feature_setting;
			},
			$feature_settings
		);
	}

	return $feature_settings;
}