/** * PNP ULTIMATE MASTER SPEED - v9.0 NUCLEAR EDITION * 1. Admin Speed: Kills RankMath Analyzer & Woo Analytics (Fixes "Update" lag) * 2. Visitor Speed: A+ Asset Diet & Image Preload * 3. Checkout: Instant Typing & PK Phone Validation (03XXXXXXXXX) * 4. UX: Celebration Popup, Confetti, & Double-Click Reset */ /* ========================================================================== 1. NUCLEAR ADMIN SPEED (FOR PERMANENT FAST UPDATES) ========================================================================== */ if ( is_admin() || current_user_can('edit_posts') ) { // Kill heavy background scripts that cause 403 errors and slow saves add_action('admin_enqueue_scripts', function() { wp_deregister_script('rank-math-analyzer'); wp_deregister_script('rank-math-common'); wp_deregister_script('rank-math-editor'); wp_dequeue_script('wc-admin-app'); // Kills heavy Analytics Dashboard }, 999); // Disable background features that hang the "Update" button add_filter('rank_math/modules/content_ai', '__return_false'); add_filter('woocommerce_admin_disabled', '__return_true'); add_filter('woocommerce_analytics_enabled', '__return_false'); add_filter('woocommerce_enable_admin_notes', '__return_false'); // Extend security key life to prevent "Session Expired" errors add_filter( 'nonce_life', function () { return 86400; } ); // Prevent "ob_end_flush" notice lag remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); // Preload Hero Image for Admin Preview add_action( 'wp_head', function() { echo ''; }, 1 ); return; // STOP HERE: Do not run visitor restrictions for Admin } /* ========================================================================== 2. VISITOR PERFORMANCE (GTmetrix A+) ========================================================================== */ add_action( 'init', function() { if ( is_checkout() ) wp_deregister_script('heartbeat'); remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); }, 1); add_action( 'wp_enqueue_scripts', function() { if ( is_admin() || isset($_GET['elementor-preview']) ) return; wp_dequeue_style( 'wp-block-library' ); wp_dequeue_style( 'classic-theme-styles' ); if ( is_front_page() ) { wp_dequeue_script( 'contact-form-7' ); wp_dequeue_style( 'contact-form-7' ); wp_dequeue_script( 'sbr-scripts' ); wp_dequeue_style( 'sbr_styles' ); } if ( is_checkout() || is_order_received_page() ) { $killers = ['wc-cart-fragments','xt-woofc-js','sbi_scripts','cffscripts','trustindex-js','google-listings-and-ads']; foreach ( $killers as $h ) { wp_dequeue_script( $h ); wp_deregister_script( $h ); } wp_dequeue_style( 'xt-woofc-css' ); } }, 9999); /* ========================================================================== 3. CHECKOUT LOGIC: TYPING, PHONE, CELEBRATION ========================================================================== */ // A. Remove Typing Lag add_filter( 'woocommerce_checkout_fields', function( $fields ) { $flds = ['billing_first_name', 'billing_last_name', 'billing_email', 'billing_phone']; foreach ( $flds as $f ) { if ( isset( $fields['billing'][$f]['class'] ) ) { $fields['billing'][$f]['class'] = array_diff($fields['billing'][$f]['class'], ['address-field', 'update_totals_on_change']); } } return $fields; }, 999); // B. Server-Side Phone Check add_action('woocommerce_checkout_process', function() { if (isset($_POST['billing_phone'])) { $p = str_replace([' ', '-', '+'], '', $_POST['billing_phone']); if ( !preg_match('/^03[0-9]{9}$/', $p) ) { wc_add_notice( 'Invalid Phone: Use exactly 11 digits starting with 03.', 'error' ); } } }); // C. Front-End Magic: Checker, Reset & Celebration add_action( 'wp_footer', function() { if ( ! is_checkout() || current_user_can('edit_posts') ) return; ?>
Processing... ✨

Finalizing your Pins & Pearls order.