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, $admin_features_disabled ): array;
$feature_id(строка) (обязательный)
The feature id.
$feature(массив) (обязательный)
The feature parameters, as returned by get_features.
$admin_features_disabled(true|false) (обязательный)
True if admin features have been disabled via woocommerce_admin_disabled

Код FeaturesController::get_setting_for_feature() WC 7.1.0

private function get_setting_for_feature( string $feature_id, array $feature, bool $admin_features_disabled ): array {
	$description = $feature['description'];
	$disabled    = false;
	$desc_tip    = '';

	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 ) {
		$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>'
			);
			$description .= $update_text;
			$disabled     = true;
		}
	}

	if ( ! $this->is_legacy_feature( $feature_id ) && ! $disabled && $this->verify_did_woocommerce_init() ) {
		$plugin_info_for_feature = $this->get_compatible_plugins_for_feature( $feature_id, true );
		$incompatibles           = array_merge( $plugin_info_for_feature['incompatible'], $plugin_info_for_feature['uncertain'] );
		$incompatibles           = array_filter( $incompatibles, 'is_plugin_active' );
		$incompatible_count      = count( $incompatibles );
		if ( $incompatible_count > 0 ) {
			if ( 1 === $incompatible_count ) {
				/* translators: %s = printable plugin name */
				$desc_tip = sprintf( __( "⚠ This feature shouldn't be enabled, the %s plugin is active and isn't compatible with it.", 'woocommerce' ), $this->plugin_util->get_plugin_name( $incompatibles[0] ) );
			} elseif ( 2 === $incompatible_count ) {
				/* translators: %1\$s, %2\$s = printable plugin names */
				$desc_tip = sprintf(
					__( "⚠ This feature shouldn't be enabled: the %1\$s and %2\$s plugins are active and aren't compatible with it.", 'woocommerce' ),
					$this->plugin_util->get_plugin_name( $incompatibles[0] ),
					$this->plugin_util->get_plugin_name( $incompatibles[1] )
				);
			} else {
				/* translators: %1\$s, %2\$s = printable plugin names, %3\$d = plugins count */
				$desc_tip = sprintf(
					_n(
						"⚠ This feature shouldn't be enabled: %1\$s, %2\$s and %3\$d more active plugin isn't compatible with it",
						"⚠ This feature shouldn't be enabled: the %1\$s and %2\$s plugins are active and aren't compatible with it. There are %3\$d other incompatible plugins.",
						$incompatible_count - 2,
						'woocommerce'
					),
					$this->plugin_util->get_plugin_name( $incompatibles[0] ),
					$this->plugin_util->get_plugin_name( $incompatibles[1] ),
					$incompatible_count - 2
				);
			}

			$incompatible_plugins_url = add_query_arg(
				array(
					'plugin_status' => 'incompatible_with_feature',
					'feature_id'    => $feature_id,
				),
				admin_url( 'plugins.php' )
			);
			/* translators: %s = URL of the plugins page */
			$extra_desc_tip = sprintf( __( " <a href='%s'>Manage incompatible plugins</a>", 'woocommerce' ), $incompatible_plugins_url );

			$desc_tip .= $extra_desc_tip;

			$disabled = ! $this->feature_is_enabled( $feature_id );
		}
	}

	/**
	 * 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 );

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