Automattic\WooCommerce\Internal\Features

FeaturesController::get_setting_for_feature()privateWC 1.0

Get the parameters to display the setting enable/disable UI for a given feature.

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

Возвращает

Массив. The parameters to add to the settings array.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_setting_for_feature( $feature_id, $feature ): array;
$feature_id(строка) (обязательный)
The feature id.
$feature(массив) (обязательный)
The feature parameters, as returned by get_features.

Код FeaturesController::get_setting_for_feature() WC 8.6.1

private function get_setting_for_feature( string $feature_id, array $feature ): array {
	$description        = $feature['description'] ?? '';
	$disabled           = false;
	$desc_tip           = '';
	$tooltip            = $feature['tooltip'] ?? '';
	$type               = $feature['type'] ?? 'checkbox';
	$setting_definition = $feature['setting'] ?? array();

	// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
	/**
	 * Filter allowing WooCommerce Admin to be disabled.
	 *
	 * @param bool $disabled False.
	 */
	$admin_features_disabled = apply_filters( 'woocommerce_admin_disabled', false );
	// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment

	if ( ( 'analytics' === $feature_id || 'new_navigation' === $feature_id ) && $admin_features_disabled ) {
		$disabled = true;
		$desc_tip = __( 'WooCommerce Admin has been disabled', 'woocommerce' );
	} elseif ( 'new_navigation' === $feature_id ) {
		$disabled = ! $this->feature_is_enabled( $feature_id );

		if ( $disabled ) {
			$update_text = sprintf(
				// translators: 1: line break tag.
				__( '%1$s The development of this feature is currently on hold.', 'woocommerce' ),
				'<br/>'
			);
		} else {
			$update_text = sprintf(
				// translators: 1: line break tag.
				__(
					'%1$s This navigation will soon become unavailable while we make necessary improvements.
		             If you turn it off now, you will not be able to turn it back on.',
					'woocommerce'
				),
				'<br/>'
			);
		}

		$needs_update = version_compare( get_bloginfo( 'version' ), '5.6', '<' );
		if ( $needs_update && current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
			$update_text = sprintf(
				// translators: 1: line break tag, 2: open link to WordPress update link, 3: close link tag.
				__( '%1$s %2$sUpdate WordPress to enable the new navigation%3$s', 'woocommerce' ),
				'<br/>',
				'<a href="' . self_admin_url( 'update-core.php' ) . '" target="_blank">',
				'</a>'
			);
			$disabled = true;
		}

		if ( ! empty( $update_text ) ) {
			$description .= $update_text;
		}
	}

	if ( ! $this->is_legacy_feature( $feature_id ) && ! $disabled && $this->verify_did_woocommerce_init() ) {
		$disabled                = ! $this->feature_is_enabled( $feature_id );
		$plugin_info_for_feature = $this->get_compatible_plugins_for_feature( $feature_id, true );
		$desc_tip                = $this->plugin_util->generate_incompatible_plugin_feature_warning( $feature_id, $plugin_info_for_feature );
	}

	/**
	 * Filter to customize the description tip that appears under the description of each feature in the features settings page.
	 *
	 * @since 7.1.0
	 *
	 * @param string $desc_tip The original description tip.
	 * @param string $feature_id The id of the feature for which the description tip is being customized.
	 * @param bool $disabled True if the UI currently prevents changing the enable/disable status of the feature.
	 * @return string The new description tip to use.
	 */
	$desc_tip = apply_filters( 'woocommerce_feature_description_tip', $desc_tip, $feature_id, $disabled );

	$feature_setting_defaults = array(
		'title'    => $feature['name'],
		'desc'     => $description,
		'type'     => $type,
		'id'       => $this->feature_enable_option_name( $feature_id ),
		'disabled' => $disabled && ! $this->force_allow_enabling_features,
		'desc_tip' => $desc_tip,
		'tooltip'  => $tooltip,
		'default'  => $this->feature_is_enabled_by_default( $feature_id ) ? 'yes' : 'no',
	);

	$feature_setting = wp_parse_args( $setting_definition, $feature_setting_defaults );

	/**
	 * Allows to modify feature setting that will be used to render in the feature page.
	 *
	 * @param array $feature_setting The feature setting. Describes the feature:
	 *      - title: The title of the feature.
	 *      - desc: The description of the feature. Will be displayed under the title.
	 *      - type: The type of the feature. Could be any of supported settings types from `WC_Admin_Settings::output_fields`, but if it's anything other than checkbox or radio, it will need custom handling.
	 *      - id: The id of the feature. Will be used as the name of the setting.
	 *      - disabled: Whether the feature is disabled or not.
	 *      - desc_tip: The description tip of the feature. Will be displayed as a tooltip next to the description.
	 *      - tooltip: The tooltip of the feature. Will be displayed as a tooltip next to the name.
	 *      - default: The default value of the feature.
	 * @param string $feature_id The id of the feature.
	 * @since 8.0.0
	 */
	return apply_filters( 'woocommerce_feature_setting', $feature_setting, $feature_id );
}