<?php
/*
Plugin Name: StepraEngine Lite
Plugin URI: https://wordpress.org/plugins/stepraengine-lite/
Description: Convert supported long WordPress forms into clean multi-step forms with progress, navigation, and validation.
Version: 1.1.2
Requires at least: 5.8
Requires PHP: 7.4
Author: arcscripter
Author URI: https://profiles.wordpress.org/arcscripter/
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: stepraengine-lite
Domain Path: /languages
*/

if ( ! function_exists( 'stepra_lite_fs' ) ) {
    // Create a helper function for easy SDK access.
    function stepra_lite_fs() {
        global $stepra_lite_fs;

        if ( ! isset( $stepra_lite_fs ) ) {
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';

            $stepra_lite_fs = fs_dynamic_init( array(
                'id'                  => '31546',
                'slug'                => 'stepraengine-lite',
                'premium_slug'        => 'stepraengine-pro',
                'type'                => 'plugin',
                'public_key'          => 'pk_b862771a6b2983e712e029a8cf0b4',
                'is_premium'          => false,
                'has_premium_version' => true,
                'has_addons'          => false,
                'has_paid_plans'      => true,
                'is_org_compliant'    => true,
                'menu'                => array(
                    'slug'           => 'stepra-settings',
                    'first-path'     => 'admin.php?page=stepra-settings',
                    'account'        => false,
                    'contact'        => false,
                    'support'        => false,
                ),
            ) );
        }

        return $stepra_lite_fs;
    }

    // Init Freemius.
    stepra_lite_fs();

    // Keep Freemius in-dashboard Pro pricing aligned with StepraEngine launch pricing.
    if ( method_exists( stepra_lite_fs(), 'add_filter' ) ) {
        stepra_lite_fs()->add_filter( 'pricing/show_annual_in_monthly', '__return_false' );
        stepra_lite_fs()->add_filter( 'pricing/css_path', 'stepra_lite_freemius_pricing_css_path' );
    }

    if ( ! function_exists( 'stepra_lite_freemius_pricing_css_path' ) ) {
        /**
         * Load StepraEngine's light brand skin for the Freemius in-dashboard upgrade page.
         *
         * @return string Absolute path to the pricing CSS file.
         */
        function stepra_lite_freemius_pricing_css_path() {
            return dirname( __FILE__ ) . '/assets/css/freemius-pricing-stepra.css';
        }
    }

    // Signal that SDK was initiated.
    do_action( 'stepra_lite_fs_loaded' );
}

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( is_admin() && ! function_exists( 'stepra_lite_freemius_pricing_footer_script' ) ) {
    /**
     * Clarify Freemius plan labels in the in-dashboard upgrade table.
     *
     * Freemius controls the pricing-table markup and default button labels. This
     * script only adjusts visible wording inside StepraEngine's own upgrade page
     * so equal-feature license tiers are described by site activation count.
     */
    function stepra_lite_freemius_pricing_footer_script() {
        if ( ! current_user_can( 'manage_options' ) ) {
            return;
        }
        ?>
        <script id="stepra-lite-freemius-pricing-copy">
        (function () {
            'use strict';

            var noteText = 'All Pro plans include the same features. Choose the license by how many websites you need to activate.';
            var descriptions = {
                single: 'All Pro features for 1 website.',
                five: 'All Pro features for up to 5 websites.',
                twentyfive: 'All Pro features for up to 25 websites.'
            };
            var switchLabels = {
                single: 'Switch to Single Site',
                five: 'Switch to 5 Sites',
                twentyfive: 'Switch to 25 Sites'
            };

            function normalize(text) {
                return (text || '').replace(/\s+/g, ' ').trim().toLowerCase();
            }

            function getPlanKey(card) {
                var title = normalize(card.querySelector('.fs-plan-title') ? card.querySelector('.fs-plan-title').textContent : card.textContent);

                if (title.indexOf('25') !== -1) {
                    return 'twentyfive';
                }

                if (title.indexOf('5') !== -1) {
                    return 'five';
                }

                if (title.indexOf('single') !== -1 || title.indexOf('1 site') !== -1) {
                    return 'single';
                }

                return '';
            }

            function setNodeText(node, value) {
                if (!node || !value) {
                    return;
                }

                if (normalize(node.textContent) !== normalize(value)) {
                    node.textContent = value;
                }
            }

            function addSiteNote(app) {
                if (!app || app.querySelector('.stepra-pricing-site-note')) {
                    return;
                }

                var packagesSection = app.querySelector('.fs-section--packages');
                var packages = app.querySelector('.fs-packages');
                var anchor = packagesSection || packages;

                if (!anchor || !anchor.parentNode) {
                    return;
                }

                var note = document.createElement('div');
                note.className = 'stepra-pricing-site-note';
                note.textContent = noteText;
                anchor.parentNode.insertBefore(note, anchor);
            }

            function hasCurrentPlan(app) {
                return Array.prototype.some.call(app.querySelectorAll('.fs-upgrade-button a, .fs-upgrade-button button, a.fs-button, button.fs-button'), function (button) {
                    var text = normalize(button.textContent);

                    return text.indexOf('your plan') !== -1 || text.indexOf('current plan') !== -1;
                });
            }

            function isCurrentPlanButton(button) {
                var text = normalize(button.textContent);

                return text.indexOf('your plan') !== -1 || text.indexOf('current plan') !== -1;
            }

            function updateCard(card, userHasPlan) {
                var planKey = getPlanKey(card);

                if (!planKey) {
                    return;
                }

                setNodeText(card.querySelector('.fs-plan-description'), descriptions[planKey]);

                card.querySelectorAll('.fs-upgrade-button a, .fs-upgrade-button button, a.fs-button, button.fs-button').forEach(function (button) {
                    var currentText = normalize(button.textContent);

                    if (!currentText) {
                        return;
                    }

                    if (isCurrentPlanButton(button)) {
                        setNodeText(button, 'Your Plan');
                        return;
                    }

                    if (userHasPlan) {
                        setNodeText(button, switchLabels[planKey]);
                        return;
                    }

                    setNodeText(button, 'Upgrade');
                });
            }

            function applyStepraPricingCopy() {
                var app = document.getElementById('fs_pricing_app');

                if (!app) {
                    return;
                }

                var userHasPlan = hasCurrentPlan(app);

                addSiteNote(app);
                app.querySelectorAll('.fs-package').forEach(function (card) {
                    updateCard(card, userHasPlan);
                });
            }

            function start() {
                var wrapper = document.getElementById('fs_pricing_wrapper');

                if (!wrapper) {
                    return;
                }

                applyStepraPricingCopy();

                if ('MutationObserver' in window) {
                    new MutationObserver(applyStepraPricingCopy).observe(wrapper, {
                        childList: true,
                        subtree: true,
                        characterData: true
                    });
                }

                window.setTimeout(applyStepraPricingCopy, 500);
                window.setTimeout(applyStepraPricingCopy, 1500);
            }

            if (document.readyState === 'loading') {
                document.addEventListener('DOMContentLoaded', start);
            } else {
                start();
            }
        }());
        </script>
        <?php
    }

    add_action( 'admin_footer', 'stepra_lite_freemius_pricing_footer_script', 99 );
}

if ( ! defined( 'STEPRA_ENGINE_VERSION' ) ) {
    define( 'STEPRA_ENGINE_VERSION', '1.1.2' );
}

// ==========================================
// PLUGIN CONFLICT PROTECTION
// ==========================================
// Important: WordPress compiles plugin files before late activation hooks can run.
// Shared public function names below are wrapped with function_exists() as a final
// redeclare-safety layer while the early guard deactivates the other edition.
if ( ! defined( 'STEPRA_ENGINE_LITE_FILE' ) ) {
    define( 'STEPRA_ENGINE_LITE_FILE', __FILE__ );
}

if ( ! defined( 'STEPRA_LITE_PLUGIN_BASENAME' ) ) {
    define( 'STEPRA_LITE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
}

if ( ! defined( 'STEPRA_PRO_PLUGIN_BASENAME' ) ) {
    define( 'STEPRA_PRO_PLUGIN_BASENAME', 'stepraengine-pro/stepraengine.php' );
}

if ( ! defined( 'STEPRA_LITE_PRO_ACTIVE_NOTICE' ) ) {
    define( 'STEPRA_LITE_PRO_ACTIVE_NOTICE', 'stepra_lite_pro_active_notice' );
}

if ( is_admin() && ! function_exists( 'stepra_lite_conflict_admin_notice' ) ) {
    function stepra_lite_conflict_admin_notice() {
        if ( get_transient( STEPRA_LITE_PRO_ACTIVE_NOTICE ) ) {
            delete_transient( STEPRA_LITE_PRO_ACTIVE_NOTICE );

            echo '<div class="notice notice-warning is-dismissible"><p>' .
                esc_html__( 'StepraEngine Lite was not activated because StepraEngine Pro is already active. Keep only Pro active to avoid plugin conflicts.', 'stepraengine-lite' ) .
            '</p></div>';
        }
    }

    add_action( 'admin_notices', 'stepra_lite_conflict_admin_notice' );
}

if (
    ! function_exists( 'is_plugin_active' ) ||
    ! function_exists( 'is_plugin_active_for_network' ) ||
    ! function_exists( 'deactivate_plugins' )
) {
    require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

$stepra_lite_activation_action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$stepra_lite_activation_action = is_string( $stepra_lite_activation_action ) ? sanitize_key( $stepra_lite_activation_action ) : '';
$stepra_lite_activation_plugin = filter_input( INPUT_GET, 'plugin', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$stepra_lite_activation_plugin = is_string( $stepra_lite_activation_plugin ) ? sanitize_text_field( wp_unslash( $stepra_lite_activation_plugin ) ) : '';

$stepra_lite_is_activation_request = 'activate' === $stepra_lite_activation_action && STEPRA_LITE_PLUGIN_BASENAME === $stepra_lite_activation_plugin;
$stepra_lite_is_active             = is_plugin_active( STEPRA_LITE_PLUGIN_BASENAME );
$stepra_lite_is_network_active     = is_plugin_active_for_network( STEPRA_LITE_PLUGIN_BASENAME );
$stepra_pro_is_active              = is_plugin_active( STEPRA_PRO_PLUGIN_BASENAME ) || is_plugin_active_for_network( STEPRA_PRO_PLUGIN_BASENAME );
$stepra_pro_is_loaded              = defined( 'STEPRA_ENGINE_PRO' ) || defined( 'STEPRA_ENGINE_PRO_BUILD' );

if ( $stepra_pro_is_active || $stepra_pro_is_loaded ) {
    set_transient( STEPRA_LITE_PRO_ACTIVE_NOTICE, 1, 60 );

    if ( $stepra_lite_is_active || $stepra_lite_is_network_active ) {
        deactivate_plugins( STEPRA_LITE_PLUGIN_BASENAME, false, $stepra_lite_is_network_active );
    }

    if ( $stepra_lite_is_activation_request ) {
        wp_die(
            esc_html__( 'Stepra Engine Lite cannot be activated while Stepra Engine Pro is active. Keep only Pro active to avoid plugin conflicts.', 'stepraengine-lite' ),
            esc_html__( 'Plugin conflict detected', 'stepraengine-lite' ),
            array( 'back_link' => true )
        );
    }

    return;
}


if ( ! function_exists( 'stepra_get_builder_target_definitions' ) ) {
function stepra_get_builder_target_definitions() {
    $targets = array(
        'cf7'        => array(
            'option'   => 'stepra_target_cf7',
            'label'    => __( 'Contact Form 7', 'stepraengine-lite' ),
            'selector' => 'html:not(.stepra-visual-failsafe-global) body form.wpcf7-form:not(.stepra-visual-ready):not(.stepra-aborted):not(.stepra-failed):not(.stepra-visual-failsafe)',
        ),
        'wpforms'    => array(
            'option'   => 'stepra_target_wpforms',
            'label'    => __( 'WPForms', 'stepraengine-lite' ),
            'selector' => 'html:not(.stepra-visual-failsafe-global) body form.wpforms-form:not(.stepra-visual-ready):not(.stepra-aborted):not(.stepra-failed):not(.stepra-visual-failsafe)',
        ),
        'forminator' => array(
            'option'   => 'stepra_target_forminator',
            'label'    => __( 'Forminator', 'stepraengine-lite' ),
            'selector' => 'html:not(.stepra-visual-failsafe-global) body form.forminator-ui:not(.stepra-visual-ready):not(.stepra-aborted):not(.stepra-failed):not(.stepra-visual-failsafe),html:not(.stepra-visual-failsafe-global) body .forminator-custom-form:not(.stepra-visual-ready):not(.stepra-aborted):not(.stepra-failed):not(.stepra-visual-failsafe)',
        ),
        'elementor'  => array(
            'option'   => 'stepra_target_elementor',
            'label'    => __( 'Elementor Forms', 'stepraengine-lite' ),
            'selector' => 'html:not(.stepra-visual-failsafe-global) body form.elementor-form:not(.stepra-visual-ready):not(.stepra-aborted):not(.stepra-failed):not(.stepra-visual-failsafe)',
        ),
    );

    return $targets;
}
}

if ( ! function_exists( 'stepra_get_builder_targets' ) ) {
function stepra_get_builder_targets() {
    $targets = array();

    foreach ( stepra_get_builder_target_definitions() as $target_key => $target ) {
        $targets[ $target_key ] = (string) absint( get_option( $target['option'], '1' ) );
    }

    return $targets;
}
}

if ( ! function_exists( 'stepra_is_builder_target_enabled' ) ) {
function stepra_is_builder_target_enabled( $target_key ) {
    $target_key = sanitize_key( $target_key );
    $targets    = stepra_get_builder_targets();

    return isset( $targets[ $target_key ] ) && '1' === (string) $targets[ $target_key ];
}
}

if ( ! function_exists( 'stepra_has_enabled_builder_targets' ) ) {
function stepra_has_enabled_builder_targets() {
    foreach ( stepra_get_builder_targets() as $enabled ) {
        if ( '1' === (string) $enabled ) {
            return true;
        }
    }

    return false;
}
}

if ( ! function_exists( 'stepra_get_preload_shield_css' ) ) {
function stepra_get_preload_shield_css() {
    $selectors = array();

    foreach ( stepra_get_builder_target_definitions() as $target_key => $target ) {
        if ( ! stepra_is_builder_target_enabled( $target_key ) ) {
            continue;
        }

        if ( ! empty( $target['selector'] ) ) {
            $selectors[] = $target['selector'];
        }
    }

    if ( empty( $selectors ) ) {
        return '';
    }

    return implode( ',', $selectors ) . '{visibility:hidden!important;opacity:0!important;pointer-events:none!important;transition:none!important;}';
}
}

// ==========================================
// 1. REGISTER SETTINGS (WITH STRICT SANITIZATION)
// ==========================================
if ( ! function_exists( 'stepra_sanitize_validation_lang' ) ) {
function stepra_sanitize_validation_lang( $value ) {
    $value = sanitize_key( $value );
    return in_array( $value, array( 'en', 'fr', 'es' ), true ) ? $value : 'en';
}
}

if ( ! function_exists( 'stepra_sanitize_progress_style' ) ) {
function stepra_sanitize_progress_style( $value ) {
    $value = sanitize_key( $value );
    return in_array( $value, array( 'bar', 'numbered' ), true ) ? $value : 'bar';
}
}


if ( ! function_exists( 'stepra_sanitize_hex_color_safe' ) ) {
function stepra_sanitize_hex_color_safe( $value ) {
    $value = is_string( $value ) ? $value : '';
    $value = sanitize_hex_color( $value );
    return $value ? $value : '';
}
}

if ( ! function_exists( 'stepra_get_hex_option' ) ) {
function stepra_get_hex_option( $option_name, $default ) {
    $default = stepra_sanitize_hex_color_safe( $default );
    $value   = get_option( $option_name, $default );
    $value   = stepra_sanitize_hex_color_safe( $value );

    return '' !== $value ? $value : $default;
}
}

if ( ! function_exists( 'stepra_get_text_option' ) ) {
function stepra_get_text_option( $option_name, $default ) {
    $default = is_string( $default ) ? $default : '';
    $value   = get_option( $option_name, $default );
    $value   = is_string( $value ) ? sanitize_text_field( $value ) : '';

    return '' !== $value ? $value : $default;
}
}

if ( ! function_exists( 'stepra_register_settings' ) ) {
function stepra_register_settings() {
    register_setting('stepra_settings_group', 'stepra_enable_wrapper', array(
        'sanitize_callback' => 'absint'
    ));
    register_setting('stepra_settings_group', 'stepra_strict_heading', array(
        'sanitize_callback' => 'absint'
    ));
    register_setting('stepra_settings_group', 'stepra_primary_color', array(
        'sanitize_callback' => 'stepra_sanitize_hex_color_safe'
    ));
    register_setting('stepra_settings_group', 'stepra_btn_text_color', array(
        'sanitize_callback' => 'stepra_sanitize_hex_color_safe'
    ));
    register_setting('stepra_settings_group', 'stepra_progress_text_color', array(
        'sanitize_callback' => 'stepra_sanitize_hex_color_safe'
    ));
    register_setting('stepra_settings_group', 'stepra_progress_style', array(
        'sanitize_callback' => 'stepra_sanitize_progress_style'
    ));
    register_setting('stepra_settings_group', 'stepra_next_text', array(
        'sanitize_callback' => 'sanitize_text_field'
    ));
    register_setting('stepra_settings_group', 'stepra_prev_text', array(
        'sanitize_callback' => 'sanitize_text_field'
    ));
    register_setting('stepra_settings_group', 'stepra_validation_lang', array(
        'sanitize_callback' => 'stepra_sanitize_validation_lang'
    ));
    register_setting( 'stepra_settings_group', 'stepra_target_cf7', array(
        'sanitize_callback' => 'absint',
        'default'           => 1,
    ) );
    register_setting( 'stepra_settings_group', 'stepra_target_wpforms', array(
        'sanitize_callback' => 'absint',
        'default'           => 1,
    ) );
    register_setting( 'stepra_settings_group', 'stepra_target_forminator', array(
        'sanitize_callback' => 'absint',
        'default'           => 1,
    ) );
    register_setting( 'stepra_settings_group', 'stepra_target_elementor', array(
        'sanitize_callback' => 'absint',
        'default'           => 1,
    ) );
}
add_action( 'admin_init', 'stepra_register_settings' );
}

// ==========================================
// 2. ADMIN MENU
// ==========================================
if ( ! function_exists( 'stepra_register_admin_menu' ) ) {
function stepra_register_admin_menu() {
    add_menu_page(
        __('Stepra Settings', 'stepraengine-lite'),
        __('Stepra', 'stepraengine-lite'),
        'manage_options',
        'stepra-settings',
        'stepra_admin_page_html',
        'dashicons-feedback',
        80
    );
}
add_action( 'admin_menu', 'stepra_register_admin_menu', 20 );
}

if ( ! function_exists( 'stepra_admin_page_html' ) ) {
function stepra_admin_page_html() {
    require_once dirname(__FILE__) . '/admin/settings-page.php';
}
}

// ==========================================
// 3. ENQUEUE ASSETS
// ==========================================
if ( ! function_exists( 'stepra_enqueue_assets' ) ) {
function stepra_enqueue_assets() {
    if (get_option('stepra_enable_wrapper', '1') != 1) return;

    $css_path = plugin_dir_path(__FILE__) . 'assets/css/wrapper-style.css';
    $css_ver  = file_exists($css_path) ? filemtime($css_path) : STEPRA_ENGINE_VERSION;
    wp_enqueue_style(
    'stepra-style',
    plugin_dir_url( __FILE__ ) . 'assets/css/wrapper-style.css',
    array(),
    $css_ver
);
    $stepra_preload_css = stepra_get_preload_shield_css();
    if ( '' !== $stepra_preload_css ) {
        wp_add_inline_style( 'stepra-style', $stepra_preload_css );
    }


    wp_enqueue_script('jquery');

    $js_path = plugin_dir_path( __FILE__ ) . 'assets/js/wrapper-engine.js';
    $js_ver  = file_exists( $js_path ) ? filemtime( $js_path ) : STEPRA_ENGINE_VERSION;

    wp_enqueue_script( 'stepra-engine', plugin_dir_url( __FILE__ ) . 'assets/js/wrapper-engine.js', array( 'jquery' ), $js_ver, false );

    wp_localize_script('stepra-engine', 'stepra_settings', array(
        'primaryColor'   => stepra_get_hex_option( 'stepra_primary_color', '#0061e0' ),
        'btnTextColor'   => stepra_get_hex_option( 'stepra_btn_text_color', '#ffffff' ),
        'progTextColor'  => stepra_get_hex_option( 'stepra_progress_text_color', '#ffffff' ),
        'progressStyle'  => stepra_sanitize_progress_style( get_option( 'stepra_progress_style', 'bar' ) ),
        'nextText'       => stepra_get_text_option( 'stepra_next_text', __( 'Next step', 'stepraengine-lite' ) ),
        'prevText'       => stepra_get_text_option( 'stepra_prev_text', __( 'Previous', 'stepraengine-lite' ) ),
        'strictHeading'  => (string) absint( get_option( 'stepra_strict_heading', '0' ) ),
        'validationLang' => stepra_sanitize_validation_lang( get_option( 'stepra_validation_lang', 'en' ) ),
        'builderTargets'  => stepra_get_builder_targets(),
    ));
}
add_action( 'wp_enqueue_scripts', 'stepra_enqueue_assets', 1 );
}



// ==========================================
// 4. FRONTEND PRELOAD CLASS
// ==========================================
if ( ! function_exists( 'stepra_add_preload_body_class' ) ) {
function stepra_add_preload_body_class( $classes ) {
    if ( get_option( 'stepra_enable_wrapper', '1' ) == 1 && stepra_has_enabled_builder_targets() ) {
        $classes[] = 'stepra-preload';
    }

    return $classes;
}
add_filter( 'body_class', 'stepra_add_preload_body_class' );
}

// ==========================================
// 5. CACHING ENGINE IMMUNITY SHIELD
// ==========================================
if ( ! function_exists( 'stepra_protect_engine_js_from_cache' ) ) {
function stepra_protect_engine_js_from_cache( $tag, $handle, $src ) {
    if ( 'stepra-engine' === $handle ) {
        $tag = str_replace( ' src', ' data-no-minify="1" data-no-optimize="1" data-noptimize="1" src', $tag );
    }
    return $tag;
}
add_filter( 'script_loader_tag', 'stepra_protect_engine_js_from_cache', 10, 3 );
}

// ==========================================
// 6. ADD SETTINGS LINK TO PLUGIN LIST
// ==========================================
if ( ! function_exists( 'stepra_add_settings_link' ) ) {
function stepra_add_settings_link( $links ) {
    $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=stepra-settings' ) ) . '">' . esc_html__( 'Settings', 'stepraengine-lite' ) . '</a>';
    array_unshift( $links, $settings_link );

    return $links;
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'stepra_add_settings_link' );
}

// ==========================================
// 7. ENQUEUE ADMIN DASHBOARD ASSETS
// ==========================================
if ( ! function_exists( 'stepra_enqueue_admin_assets' ) ) {
function stepra_enqueue_admin_assets( $hook ) {
    if ( 'toplevel_page_stepra-settings' !== $hook ) {
        return;
    }
    $admin_css_path = plugin_dir_path( __FILE__ ) . 'assets/css/admin-style.css';
    $admin_css_ver  = file_exists( $admin_css_path ) ? filemtime( $admin_css_path ) : STEPRA_ENGINE_VERSION;
    wp_enqueue_style( 'stepra-admin-style', plugin_dir_url( __FILE__ ) . 'assets/css/admin-style.css', array(), $admin_css_ver );
}
add_action( 'admin_enqueue_scripts', 'stepra_enqueue_admin_assets' );
}

// ==========================================
// 3B. EARLY NORMAL-FORM PRELOAD SHIELD
// ==========================================
if ( ! function_exists( 'stepra_print_early_preload_shield' ) ) {
function stepra_print_early_preload_shield() {
    if ( get_option( 'stepra_enable_wrapper', '1' ) != 1 ) return;
    $stepra_preload_css = stepra_get_preload_shield_css();
    if ( '' === $stepra_preload_css ) {
        return;
    }

    echo "\n" . '<style id="stepra-early-preload-shield">' . esc_html( $stepra_preload_css ) . '</style>' . "\n";
    echo '<script id="stepra-early-preload-flag">(function(){try{document.documentElement.classList.add("stepra-preload");setTimeout(function(){document.documentElement.classList.add("stepra-visual-failsafe-global");},4500);}catch(e){}})();</script>' . "\n";
}
add_action( 'wp_head', 'stepra_print_early_preload_shield', 0 );
}
