ompatibility defaults are seeded. * * @since 11.1.0 * * @param array $features Array of feature slugs. */ return apply_filters( 'woocommerce_admin_features', array_keys( self::get_legacy_feature_compatibility_defaults() ) ); } /** * Checks if Analytics was disabled by legacy WooCommerce Admin filters. * * @return bool True if Analytics was disabled by legacy filters. */ public static function is_analytics_disabled_by_legacy_filters(): bool { /** * Filter allowing WooCommerce Admin optional features to be disabled. * * @param bool $disabled False. */ if ( apply_filters( 'woocommerce_admin_disabled', false ) ) { // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment return true; } return ! in_array( 'analytics', self::get_features_with_legacy_compatibility_defaults(), true ); } /** * Checks if analytics is enabled, without going through FeaturesController. * * @return bool */ private static function is_analytics_enabled() { return ! self::is_analytics_disabled_by_legacy_filters() && 'yes' === get_option( Analytics::TOGGLE_OPTION_NAME, 'yes' ); } /** * Checks if a feature slug is supported only by the legacy compatibility shim. * * @param string $feature Feature slug. * @return bool */ private static function is_legacy_compatibility_feature( $feature ) { return array_key_exists( $feature, self::get_legacy_feature_compatibility_defaults() ); } /** * Gets version metadata for a legacy feature flag shim. * * @param string $feature Feature slug. * @return array{deprecated_since: string, removed_in: ?string}|null */ private static function get_legacy_feature_compatibility_versions( $feature ) { return self::$retired_feature_compatibility_versions[ $feature ] ?? null; } /** * Gets the WooCommerce version where a legacy feature flag shim was deprecated. * * @param string $feature Feature slug. * @return string|null */ private static function get_legacy_feature_compatibility_deprecation_version( $feature ) { $versions = self::get_legacy_feature_compatibility_versions( $feature ); return $versions['deprecated_since'] ?? null; } /** * Gets the WooCommerce version where a legacy feature flag shim will be removed. * * @param string $feature Feature slug. * @return string|null */ private static function get_legacy_feature_compatibility_removal_version( $feature ) { $versions = self::get_legacy_feature_compatibility_versions( $feature ); return $versions['removed_in'] ?? null; } /** * Emits a deprecation notice for a direct legacy feature flag shim lookup. * * @param string $method Method name. * @param string $feature Feature slug. */ private static function warn_legacy_feature_compatibility_usage( $method, $feature ): void { $deprecation_version = self::get_legacy_feature_compatibility_deprecation_version( $feature ); $removal_version = self::get_legacy_feature_compatibility_removal_version( $feature ); if ( ! $deprecation_version ) { return; } wc_deprecated_function( sprintf( "%s( '%s' )", $method, $feature ), $deprecation_version, sprintf( 'direct feature behavior checks. The %1$s WC Admin feature flag shim will be removed in %2$s.', $feature, $removal_version ? 'WooCommerce ' . $removal_version : 'a future version of WooCommerce' ) ); } /** * Alias internal features classes to make them backward compatible. * We've moved our feature classes to src-internal as part of merging this * repository with WooCommerce Core to form a monorepo. * See https://wp.me/p90Yrv-2HY for details. */ private function register_internal_class_aliases() { $aliases = array( // new class => original class (this will be aliased). 'Automattic\WooCommerce\Internal\Admin\WCPayPromotion\Init' => 'Automattic\WooCommerce\Admin\Features\WcPayPromotion\Init', 'Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\Init' => 'Automattic\WooCommerce\Admin\Features\RemoteFreeExtensions\Init', 'Automattic\WooCommerce\Internal\Admin\ActivityPanels' => 'Automattic\WooCommerce\Admin\Features\ActivityPanels', 'Automattic\WooCommerce\Internal\Admin\Analytics' => 'Automattic\WooCommerce\Admin\Features\Analytics', 'Automattic\WooCommerce\Internal\Admin\Coupons' => 'Automattic\WooCommerce\Admin\Features\Coupons', 'Automattic\WooCommerce\Internal\Admin\CouponsMovedTrait' => 'Automattic\WooCommerce\Admin\Features\CouponsMovedTrait', 'Automattic\WooCommerce\Internal\Admin\CustomerEffortScoreTracks' => 'Automattic\WooCommerce\Admin\Features\CustomerEffortScoreTracks', 'Automattic\WooCommerce\Internal\Admin\Homescreen' => 'Automattic\WooCommerce\Admin\Features\Homescreen', 'Automattic\WooCommerce\Internal\Admin\Marketing' => 'Automattic\WooCommerce\Admin\Features\Marketing', 'Automattic\WooCommerce\Internal\Admin\MobileAppBanner' => 'Automattic\WooCommerce\Admin\Features\MobileAppBanner', 'Automattic\WooCommerce\Internal\Admin\RemoteInboxNotifications' => 'Automattic\WooCommerce\Admin\Features\RemoteInboxNotifications', 'Automattic\WooCommerce\Internal\Admin\ShippingLabelBanner' => 'Automattic\WooCommerce\Admin\Features\ShippingLabelBanner', 'Automattic\WooCommerce\Internal\Admin\ShippingLabelBannerDisplayRules' => 'Automattic\WooCommerce\Admin\Features\ShippingLabelBannerDisplayRules', 'Automattic\WooCommerce\Internal\Admin\WcPayWelcomePage' => 'Automattic\WooCommerce\Admin\Features\WcPayWelcomePage', ); foreach ( $aliases as $new_class => $orig_class ) { class_alias( $new_class, $orig_class ); } } /** * Check if we're in an admin context where features should be loaded. * * @return boolean */ private static function should_load_features() { $should_load = ( is_admin() || wp_doing_ajax() || wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ) || ( WC()->is_rest_api_request() && ! WC()->is_store_api_request() ) || // Allow features to be loaded in frontend for admin users. This is needed for the use case such as the coming soon footer banner. current_user_can( 'manage_woocommerce' ) ); /** * Filter to determine if admin features should be loaded. * * @since 9.6.0 * @param boolean $should_load Whether admin features should be loaded. It defaults to true when the current request is in an admin context. */ return apply_filters( 'woocommerce_admin_should_load_features', $should_load ); } }