Plugin Directory


Ignore:
Timestamp:
11/20/2026 04:34:16 AM (2 hours ago)
Author:
brokensmile.2103
Message:

Release v2.0.2 - Smart loading, hand-drawn holiday scenes, tsParticles backgrounds, faster Snowfall, blurred spoilers, security & Grayscale fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • init-fx-engine/trunk/init-fx-engine.php

    r3723121 r3812923  
    22/**
    33 * Plugin Name: Init FX Engine
    4  * Description: Add interactive visual effects like fireworks, emoji rain, snowfall and seasonal holiday scenes — triggered by comments, keywords, or holidays. Now with native Block Editor support. Make your WordPress site come alive!
     4 * Description: Add interactive visual effects like fireworks, emoji rain, snowfall, particle backgrounds and seasonal holiday scenes — triggered by comments, keywords, blocks or holidays. Scripts only load on pages that actually use them. Make your WordPress site come alive!
    55 * Plugin URI: https://inithtml.com/plugin/init-fx-engine/
    6  * Version: 2.0.1
     6 * Version: 2.0.2
    77 * Author: Init HTML
    88 * Author URI: https://inithtml.com/
    … …  
    1010 * Domain Path: /languages
    1111 * Requires at least: 6.9
    12  * Tested up to: 7.1
    1312 * Requires PHP: 7.4
    1413 * License: GPLv2 or later
    1514 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
     15 *
     16 * @package Init_FX_Engine
    1617 */
    1718
    … …  
    2021// === DEFINE CONSTANTS ===
    2122
    22 define( 'INIT_PLUGIN_SUITE_FX_ENGINE_VERSION',        '2.0.1' );
    23 define( 'INIT_PLUGIN_SUITE_FX_ENGINE_SLUG',           'init-fx-engine' );
    24 define( 'INIT_PLUGIN_SUITE_FX_ENGINE_OPTION',         'init_plugin_suite_fx_engine_settings' );
    25 define( 'INIT_PLUGIN_SUITE_FX_ENGINE_URL',            plugin_dir_url( __FILE__ ) );
    26 define( 'INIT_PLUGIN_SUITE_FX_ENGINE_PATH',           plugin_dir_path( __FILE__ ) );
    27 define( 'INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_URL',     INIT_PLUGIN_SUITE_FX_ENGINE_URL . 'assets/' );
    28 define( 'INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_PATH',    INIT_PLUGIN_SUITE_FX_ENGINE_PATH . 'assets/' );
    29 define( 'INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH',  INIT_PLUGIN_SUITE_FX_ENGINE_PATH . 'includes/' );
     23define( 'INIT_PLUGIN_SUITE_FX_ENGINE_VERSION', '2.0.2' );
     24define( 'INIT_PLUGIN_SUITE_FX_ENGINE_SLUG', 'init-fx-engine' );
     25define( 'INIT_PLUGIN_SUITE_FX_ENGINE_OPTION', 'init_plugin_suite_fx_engine_settings' );
     26define( 'INIT_PLUGIN_SUITE_FX_ENGINE_URL', plugin_dir_url( __FILE__ ) );
     27define( 'INIT_PLUGIN_SUITE_FX_ENGINE_PATH', plugin_dir_path( __FILE__ ) );
     28define( 'INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_URL', INIT_PLUGIN_SUITE_FX_ENGINE_URL . 'assets/' );
     29define( 'INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_PATH', INIT_PLUGIN_SUITE_FX_ENGINE_PATH . 'assets/' );
     30define( 'INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH', INIT_PLUGIN_SUITE_FX_ENGINE_PATH . 'includes/' );
    3031
    31 // === LOAD SHORTCODES ===
     32// === LOAD MODULES ===
    3233
     34require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'assets.php';
    3335require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'shortcodes.php';
    34 require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'settings-page.php';
     36require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'snowfall.php';
     37require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'seasonal.php';
    3538require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'blocks.php';
    36 require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'seasonal.php';
    37 require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'settings-seasonal.php';
    3839
    39 // === ENQUEUE JS ENGINE ===
    40 
    41 add_action( 'wp_enqueue_scripts', 'init_plugin_suite_fx_engine_enqueue_scripts' );
    42 function init_plugin_suite_fx_engine_enqueue_scripts() {
    43     wp_enqueue_script(
    44         'init-plugin-suite-fx-confetti',
    45         INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_URL . 'js/canvas-confetti.min.js',
    46         [],
    47         INIT_PLUGIN_SUITE_FX_ENGINE_VERSION,
    48         true
    49     );
    50 
    51     wp_enqueue_script(
    52         'init-plugin-suite-fx-engine',
    53         INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_URL . 'js/fx-engine.js',
    54         ['init-plugin-suite-fx-confetti'],
    55         INIT_PLUGIN_SUITE_FX_ENGINE_VERSION,
    56         true
    57     );
    58 
    59     $inlinefmt = get_option('init_plugin_suite_fx_engine_inlinefmt', [
    60         'enabled' => true,
    61     ]);
    62 
    63     $i18n = [
    64         'tap_to_reveal' => __('Tap to reveal', 'init-fx-engine'),
    65     ];
    66 
    67     wp_add_inline_script(
    68         'init-plugin-suite-fx-engine',
    69         'window.INIT_FX = window.INIT_FX || {};
    70          window.INIT_FX.inlinefmt = ' . wp_json_encode($inlinefmt) . ';
    71          window.INIT_FX.i18n = ' . wp_json_encode($i18n) . ';
    72          window.INIT_FX.assets = ' . wp_json_encode(init_plugin_suite_fx_engine_lazy_assets()) . ';',
    73         'before'
    74     );
    75 
    76     $raw_keywords = get_option('init_plugin_suite_fx_engine_keywords', []);
    77     $raw_keywords = is_array($raw_keywords) ? $raw_keywords : [];
    78     $mapped = [];
    79 
    80     foreach ($raw_keywords as $effect => $raw) {
    81         if (empty($raw)) continue;
    82 
    83         if ($effect === 'emojiRain') {
    84             $entries = array_map('trim', explode(',', $raw));
    85             foreach ($entries as $entry) {
    86                 [$kw, $emoji] = array_pad(explode(':', $entry, 2), 2, null);
    87                 if ($kw) {
    88                     $mapped[$effect][] = ['keyword' => $kw, 'emoji' => $emoji];
    89                 }
    90             }
    91         } else {
    92             $words = array_map('trim', explode(',', $raw));
    93             foreach ($words as $kw) {
    94                 if ($kw) {
    95                     $mapped[$effect][] = ['keyword' => $kw];
    96                 }
    97             }
    98         }
    99     }
    100 
    101     // OK dùng localize cho data
    102     wp_localize_script('init-plugin-suite-fx-engine', 'FX_KEYWORDS', $mapped);
     40if ( is_admin() ) {
     41        require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'settings-page.php';
     42        require_once INIT_PLUGIN_SUITE_FX_ENGINE_INCLUDES_PATH . 'settings-seasonal.php';
    10343}
    104 
    105 /**
    106  * Thư viện chỉ tải khi cần (lazy load) — fx-engine.js tự chèn <script> khi hiệu ứng được gọi.
    107  *
    108  * @return array
    109  */
    110 function init_plugin_suite_fx_engine_lazy_assets() {
    111     return [
    112         'fireworks' => INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_URL . 'js/fireworks.min.js?ver=' . rawurlencode( INIT_PLUGIN_SUITE_FX_ENGINE_VERSION ),
    113     ];
    114 }
    115 
    116 /**
    117  * PRELOADER - Anti-flash solution (FIXED VERSION)
    118  * - Che content ngay từ đầu bằng CSS critical
    119  * - Preloader show immediately, content hidden cho đến khi ready
    120  * - Fixed z-index và visibility issues
    121  */
    122 add_action('wp_head', function () {
    123     $preloader = get_option('init_plugin_suite_fx_engine_preloader', [
    124         'enabled'      => false,
    125         'style'        => 'dot',
    126         'bg'           => '#ffffff',
    127         'session_once' => false
    128     ]);
    129 
    130     if (empty($preloader['enabled'])) {
    131         return;
    132     }
    133 
    134     $bg = esc_attr($preloader['bg']);
    135     $bgCSS = strpos($bg, ',') !== false ? "linear-gradient(to right, {$bg})" : $bg;
    136    
    137     // Critical CSS để che content ngay lập tức - FIXED VERSION
    138     ?>
    139     <style id="init-fx-critical-preloader">
    140         html.init-fx-preloading {
    141             overflow: hidden !important;
    142         }
    143        
    144         html.init-fx-preloading body {
    145             overflow: hidden !important;
    146             visibility: hidden !important;
    147             transition: visibility 0.3s ease !important;
    148         }
    149        
    150         html:not(.init-fx-preloading) body {
    151             visibility: visible !important;
    152         }
    153        
    154         html.init-fx-preloading #init-fx-preloader {
    155             visibility: visible !important;
    156             opacity: 1 !important;
    157         }
    158        
    159         #init-fx-preloader {
    160             position: fixed !important;
    161             top: 0 !important;
    162             left: 0 !important;
    163             width: 100vw !important;
    164             height: 100vh !important;
    165             background: <?php echo esc_attr($bgCSS); ?> !important;
    166             z-index: 999999999 !important; /* Fixed z-index */
    167             display: flex !important;
    168             align-items: center !important;
    169             justify-content: center !important;
    170             visibility: hidden;
    171             opacity: 1;
    172             transition: opacity 0.8s cubic-bezier(0.4, 0.0, 0.2, 1), visibility 0s linear 0.8s !important;
    173         }
    174        
    175         html.init-fx-preloading #wpadminbar {
    176             visibility: hidden !important;
    177             opacity: 0 !important;
    178             pointer-events: none !important;
    179         }
    180        
    181         @keyframes preloaderFadeOut {
    182             0% {
    183                 opacity: 1;
    184                 visibility: visible;
    185                 transform: scale(1);
    186             }
    187             70% {
    188                 opacity: 0.3;
    189                 visibility: visible;
    190                 transform: scale(1.02);
    191             }
    192             100% {
    193                 opacity: 0;
    194                 visibility: hidden;
    195                 transform: scale(1);
    196             }
    197         }
    198        
    199         #init-fx-preloader.fx-animate-out {
    200             animation: preloaderFadeOut 1s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards !important;
    201         }
    202 
    203         #init-fx-preloader * {
    204             z-index: inherit !important;
    205         }
    206     </style>
    207    
    208     <script>
    209         (function() {
    210             document.documentElement.classList.add('init-fx-preloading');
    211            
    212             window.INIT_FX = window.INIT_FX || {};
    213             window.INIT_FX.preloader = <?php echo wp_json_encode($preloader); ?>;
    214            
    215             function createPreloaderImmediately() {
    216                 var container = document.body || document.documentElement;
    217                
    218                 var existing = document.getElementById('init-fx-preloader');
    219                 if (!existing && container) {
    220                     var preloader = document.createElement('div');
    221                     preloader.id = 'init-fx-preloader';
    222                     preloader.setAttribute('data-style', '<?php echo esc_js($preloader['style']); ?>');
    223                    
    224                     preloader.style.cssText = `
    225                         position: fixed !important;
    226                         top: 0 !important;
    227                         left: 0 !important;
    228                         width: 100vw !important;
    229                         height: 100vh !important;
    230                         background: <?php echo esc_js($bgCSS); ?> !important;
    231                         z-index: 999999999 !important;
    232                         display: flex !important;
    233                         align-items: center !important;
    234                         justify-content: center !important;
    235                         visibility: visible !important;
    236                         opacity: 1 !important;
    237                     `;
    238                    
    239                     container.appendChild(preloader);
    240                     return true;
    241                 }
    242                 return false;
    243             }
    244            
    245             if (!createPreloaderImmediately()) {
    246                 var retryCount = 0;
    247                 var retryInterval = setInterval(function() {
    248                     if (createPreloaderImmediately() || retryCount++ > 20) {
    249                         clearInterval(retryInterval);
    250                     }
    251                 }, 10);
    252             }
    253         })();
    254     </script>
    255     <?php
    256 }, 0); // Priority 0 để chạy đầu tiên
    257 
    258 // Enqueue JS để xử lý preloader animation
    259 add_action('wp_enqueue_scripts', function () {
    260     $preloader = get_option('init_plugin_suite_fx_engine_preloader', [
    261         'enabled'      => false,
    262         'style'        => 'dot',
    263         'bg'           => '#ffffff',
    264         'session_once' => false, // thêm default luôn
    265     ]);
    266 
    267     if (empty($preloader['enabled'])) {
    268         return;
    269     }
    270 
    271     wp_enqueue_script(
    272         'init-plugin-suite-fx-preloader',
    273         INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_URL . 'js/fx-preloader.js',
    274         [],
    275         INIT_PLUGIN_SUITE_FX_ENGINE_VERSION,
    276         false // Load sớm ở header
    277     );
    278 
    279     // Truyền settings xuống JS
    280     wp_add_inline_script(
    281         'init-plugin-suite-fx-preloader',
    282         'window.INIT_FX = window.INIT_FX || {};
    283          window.INIT_FX.preloader = ' . wp_json_encode($preloader) . ';',
    284         'before'
    285     );
    286 });
    287 
    288 // Fallback nếu JS fail - auto remove preloader sau 3.5s
    289 add_action('wp_footer', function () {
    290     $preloader = get_option('init_plugin_suite_fx_engine_preloader', [
    291         'enabled' => false
    292     ]);
    293 
    294     if (empty($preloader['enabled'])) {
    295         return;
    296     }
    297    
    298     ?>
    299     <script>
    300         setTimeout(function() {
    301             document.documentElement.classList.remove('init-fx-preloading');
    302             var preloader = document.getElementById('init-fx-preloader');
    303             var criticalCSS = document.getElementById('init-fx-critical-preloader');
    304            
    305             if (preloader) preloader.remove();
    306             if (criticalCSS) criticalCSS.remove();
    307         }, 3500);
    308     </script>
    309     <?php
    310 }, 999);
    311 
    312 /**
    313  * SNOWFALL
    314  */
    315 add_action('wp_enqueue_scripts', function () {
    316     $snowfall = get_option('init_plugin_suite_fx_engine_snowfall', [
    317         'enabled'       => false,
    318         'mode'          => 'auto',
    319         'custom_start'  => '',
    320         'custom_end'    => '',
    321         'homepage_only' => false,
    322     ]);
    323 
    324     // Không bật thì thôi
    325     if (empty($snowfall['enabled'])) {
    326         return;
    327     }
    328 
    329     // Nếu chọn chỉ chạy ở trang chủ → thoát nếu không phải homepage
    330     // (static front page hoặc blog home — xem includes/seasonal.php)
    331     if (!empty($snowfall['homepage_only']) && !init_plugin_suite_fx_engine_is_homepage_request()) {
    332         return;
    333     }
    334 
    335     $should_run = false;
    336     $today = current_time('Y-m-d');
    337 
    338     if (($snowfall['mode'] ?? 'auto') === 'auto') {
    339         $year       = current_time('Y');
    340         $start      = "$year-12-20";
    341         $end        = "$year-12-31";
    342         $should_run = ($today >= $start && $today <= $end);
    343     } elseif (($snowfall['mode'] ?? 'auto') === 'custom') {
    344         $start = sanitize_text_field($snowfall['custom_start'] ?? '');
    345         $end   = sanitize_text_field($snowfall['custom_end'] ?? '');
    346         if ($start && $end) {
    347             $should_run = ($today >= $start && $today <= $end);
    348         }
    349     }
    350 
    351     if (!$should_run) {
    352         return;
    353     }
    354 
    355     // Normalize + default
    356     $snowfall = wp_parse_args($snowfall, [
    357         'enabled'        => false,
    358         'mode'           => 'auto',
    359         'custom_start'   => '',
    360         'custom_end'     => '',
    361         'homepage_only'  => false,
    362 
    363         // Snow settings
    364         'amount'         => 80,
    365         'size'           => 4,
    366         'speed'          => 1.2,
    367         'opacity'        => 0.6,
    368     ]);
    369 
    370     // Hard clamp
    371     $snowfall['amount']  = max(20, min(200, (int) $snowfall['amount']));
    372     $snowfall['size']    = max(1,  min(10,  (int) $snowfall['size']));
    373     $snowfall['speed']   = max(0.3, min(5,  (float) $snowfall['speed']));
    374     $snowfall['opacity'] = max(0.1, min(1,  (float) $snowfall['opacity']));
    375 
    376     wp_enqueue_script(
    377         'init-plugin-suite-fx-particles',
    378         INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_URL . 'js/particles.min.js',
    379         [],
    380         INIT_PLUGIN_SUITE_FX_ENGINE_VERSION,
    381         true
    382     );
    383 
    384     wp_enqueue_script(
    385         'init-plugin-suite-fx-snowfall',
    386         INIT_PLUGIN_SUITE_FX_ENGINE_ASSETS_URL . 'js/fx-snowfall.js',
    387         ['init-plugin-suite-fx-particles'],
    388         INIT_PLUGIN_SUITE_FX_ENGINE_VERSION,
    389         true
    390     );
    391 
    392     // Chỉ truyền những thứ frontend cần
    393     $frontend_snowfall = [
    394         'amount'  => $snowfall['amount'],
    395         'size'    => $snowfall['size'],
    396         'speed'   => $snowfall['speed'],
    397         'opacity' => $snowfall['opacity'],
    398     ];
    399 
    400     wp_add_inline_script(
    401         'init-plugin-suite-fx-snowfall',
    402         'window.INIT_FX = window.INIT_FX || {}; window.INIT_FX.snowfall = ' . wp_json_encode($frontend_snowfall) . ';',
    403         'before'
    404     );
    405 });
    406 
    407 /**
    408  * GRAYSCALE
    409  * - Chuyển sang enqueue thay vì in thẳng <style>/<script> ở footer
    410  */
    411 add_action('wp_enqueue_scripts', function () {
    412     $grayscale = get_option('init_plugin_suite_fx_engine_grayscale', [
    413         'enabled'      => false,
    414         'mode'         => 'off',
    415         'custom_start' => '',
    416         'custom_end'   => ''
    417     ]);
    418 
    419     if (empty($grayscale['enabled'])) {
    420         return;
    421     }
    422 
    423     $today = current_time('Y-m-d');
    424     $mode  = $grayscale['mode'] ?? 'off';
    425     $should_run = false;
    426 
    427     if ($mode === 'always') {
    428         $should_run = true;
    429     } elseif ($mode === 'custom') {
    430         $start = sanitize_text_field($grayscale['custom_start'] ?? '');
    431         $end   = sanitize_text_field($grayscale['custom_end'] ?? '');
    432         if ($start && $end) {
    433             $should_run = ($today >= $start && $today <= $end);
    434         }
    435     }
    436 
    437     if (!$should_run) {
    438         return;
    439     }
    440 
    441     // Tạo handle “ảo” để gắn inline CSS/JS
    442     $handle = 'init-plugin-suite-fx-grayscale';
    443 
    444     wp_register_style($handle, false, [], INIT_PLUGIN_SUITE_FX_ENGINE_VERSION);
    445     wp_enqueue_style($handle);
    446     wp_add_inline_style(
    447         $handle,
    448         'body.init-fx-grayscale{filter:grayscale(100%) !important;-webkit-filter:grayscale(100%) !important;}'
    449     );
    450 
    451     wp_register_script($handle, false, [], INIT_PLUGIN_SUITE_FX_ENGINE_VERSION, true);
    452     wp_enqueue_script($handle);
    453     wp_add_inline_script(
    454         $handle,
    455         'document.addEventListener("DOMContentLoaded",function(){document.body.classList.add("init-fx-grayscale");});'
    456     );
    457 });
    45844
    45945// ==========================
    … …  
    46147// ==========================
    46248
    463 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'init_plugin_suite_fx_engine_add_settings_link');
    464 // Add a "Settings" link to the plugin row in the Plugins admin screen
    465 function init_plugin_suite_fx_engine_add_settings_link($links) {
    466     $settings_link = '<a href="' . admin_url('options-general.php?page=' . INIT_PLUGIN_SUITE_FX_ENGINE_SLUG) . '">' . __('Settings', 'init-fx-engine') . '</a>';
    467     array_unshift($links, $settings_link);
    468     return $links;
     49add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'init_plugin_suite_fx_engine_add_settings_link' );
     50/**
     51 * Add a "Settings" link to the plugin row in the Plugins admin screen.
     52 *
     53 * @param array $links Existing action links.
     54 * @return array
     55 */
     56function init_plugin_suite_fx_engine_add_settings_link( $links ) {
     57        $settings_link = sprintf(
     58                '<a href="%s">%s</a>',
     59                esc_url( admin_url( 'options-general.php?page=' . INIT_PLUGIN_SUITE_FX_ENGINE_SLUG ) ),
     60                esc_html__( 'Settings', 'init-fx-engine' )
     61        );
     62
     63        array_unshift( $links, $settings_link );
     64
     65        return $links;
    46966}
Note: See TracChangeset for help on using the changeset viewer.