true, 'dynamic_icons' => true, 'inline_dynamic_styles' => true, 'critical_css' => false, 'critical_threshold' => 'medium', 'dynamic_javascript' => true, 'disable_emojis' => false, 'optimize_google_fonts' => true, 'disable_google_fonts' => false, ]; } public static function google_fonts_disabled() { return ! empty( self::get_settings()['disable_google_fonts'] ); } public static function get_settings() { $settings = self::sanitize_import_settings( Prefix_Migration::get_option( self::OPTION_KEY, [] ) ); /** Future recovery systems may override effective values without changing saved preferences. */ $effective = apply_filters( 'nyxonn_fx_effective_performance_settings', $settings ); return self::sanitize_import_settings( is_array( $effective ) ? $effective : $settings ); } public static function is_enabled( $key ) { $settings = self::get_settings(); return ! empty( $settings[ sanitize_key( $key ) ] ); } public static function get_critical_threshold_pixels() { $settings = self::get_settings(); $thresholds = [ 'low' => 600, 'medium' => 900, 'high' => 1200 ]; return $thresholds[ $settings['critical_threshold'] ] ?? $thresholds['medium']; } public static function sanitize_import_settings( $settings ) { $settings = is_array( $settings ) ? $settings : []; $clean = self::get_defaults(); foreach ( [ 'dynamic_module_assets', 'dynamic_icons', 'inline_dynamic_styles', 'critical_css', 'dynamic_javascript', 'disable_emojis', 'optimize_google_fonts', 'disable_google_fonts' ] as $key ) { if ( array_key_exists( $key, $settings ) ) { $clean[ $key ] = (bool) $settings[ $key ]; } } $threshold = sanitize_key( $settings['critical_threshold'] ?? $clean['critical_threshold'] ); $clean['critical_threshold'] = in_array( $threshold, [ 'low', 'medium', 'high' ], true ) ? $threshold : 'medium'; return $clean; } public static function handle_save() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to update performance settings.', 'nyxonn-builder' ), '', [ 'response' => 403 ] ); } check_admin_referer( 'nyxonn_builder_save_performance' ); $submitted = []; foreach ( array_keys( self::get_defaults() ) as $key ) { if ( 'critical_threshold' === $key ) { $submitted[ $key ] = isset( $_POST[ $key ] ) ? sanitize_key( wp_unslash( $_POST[ $key ] ) ) : 'medium'; } else { $submitted[ $key ] = isset( $_POST[ $key ] ); } } update_option( self::OPTION_KEY, self::sanitize_import_settings( $submitted ), false ); wp_safe_redirect( add_query_arg( 'nyxonn_builder_notice', 'saved', admin_url( 'admin.php?page=nyxonn-builder-performance' ) ) ); exit; } public static function handle_reset() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to reset performance settings.', 'nyxonn-builder' ), '', [ 'response' => 403 ] ); } check_admin_referer( 'nyxonn_builder_reset_performance' ); update_option( self::OPTION_KEY, self::get_defaults(), false ); wp_safe_redirect( add_query_arg( 'nyxonn_builder_notice', 'reset', admin_url( 'admin.php?page=nyxonn-builder-performance' ) ) ); exit; } private static function maybe_disable_emojis() { if ( is_admin() || ! self::is_enabled( 'disable_emojis' ) ) { return; } remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' ); } }