Old value. * @param string $value New value. */ public static function maybe_disable_features( $old_value, $value ) { if ( 'yes' === $value ) { return; } foreach ( self::get_features() as $feature ) { self::disable( $feature ); } } /** * Adds the Features section to the advanced tab of WooCommerce Settings * * @param array $sections Sections. * @return array */ public static function add_features_section( $sections ) { $features = apply_filters( 'woocommerce_settings_features', array() ); if ( empty( $features ) ) { return $sections; } $sections['features'] = __( 'Features', 'woocommerce' ); return $sections; } /** * Adds the Features settings. * * @param array $settings Settings. * @param string $current_section Current section slug. * @return array */ public static function add_features_settings( $settings, $current_section ) { if ( 'features' !== $current_section ) { return $settings; } $features = apply_filters( 'woocommerce_settings_features', array() ); if ( empty( $features ) ) { return $settings; } return array_merge( 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, array( array( 'type' => 'sectionend', 'id' => 'features_options', ), ) ); } /** * Conditionally loads the beta features tracking modal. * * @param string $hook Page hook. */ public static function maybe_load_beta_features_modal( $hook ) { if ( 'woocommerce_page_wc-settings' !== $hook || ! isset( $_GET['tab'] ) || 'advanced' !== $_GET['tab'] || // phpcs:ignore CSRF ok. ! isset( $_GET['section'] ) || 'features' !== $_GET['section'] // phpcs:ignore CSRF ok. ) { return; } $tracking_enabled = get_option( 'woocommerce_allow_tracking', 'no' ); if ( 'yes' === $tracking_enabled ) { return; } $rtl = is_rtl() ? '.rtl' : ''; wp_enqueue_style( 'wc-admin-beta-features-tracking-modal', Loader::get_url( "beta-features-tracking-modal/style{$rtl}", 'css' ), array( 'wp-components' ), Loader::get_file_version( 'css' ) ); wp_enqueue_script( 'wc-admin-beta-features-tracking-modal', Loader::get_url( 'wp-admin-scripts/beta-features-tracking-modal', 'js' ), array( 'wp-i18n', 'wp-element', WC_ADMIN_APP ), Loader::get_file_version( 'js' ), true ); } /** * Loads the required scripts on the correct pages. */ public static function load_scripts() { if ( ! Loader::is_admin_or_embed_page() ) { return; } $features = self::get_features(); $enabled_features = array(); foreach ( $features as $key ) { $enabled_features[ $key ] = self::is_enabled( $key ); } wp_add_inline_script( WC_ADMIN_APP, 'window.wcAdminFeatures = ' . wp_json_encode( $enabled_features ), 'before' ); } /** * Adds body classes to the main wp-admin wrapper, allowing us to better target elements in specific scenarios. * * @param string $admin_body_class Body class to add. */ public static function add_admin_body_classes( $admin_body_class = '' ) { if ( ! Loader::is_admin_or_embed_page() ) { return $admin_body_class; } $classes = explode( ' ', trim( $admin_body_class ) ); $features = self::get_features(); foreach ( $features as $feature_key ) { $classes[] = sanitize_html_class( 'woocommerce-feature-enabled-' . $feature_key ); } $admin_body_class = implode( ' ', array_unique( $classes ) ); return " $admin_body_class "; } }