From f8e0e8cdcb0fc5264444a186537c47414f4a7a27 Mon Sep 17 00:00:00 2001 From: "bfintal@gmail.com" <> Date: Wed, 22 Oct 2025 23:36:53 +0800 Subject: [PATCH 1/2] feat: added enqueue_frontend_assets_for_content static function --- src/compatibility/ewww.php | 2 +- src/init.php | 77 +++++++++++++++++++++++++++----------- src/lightbox/index.php | 2 +- 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/compatibility/ewww.php b/src/compatibility/ewww.php index e536a16077..7c7a73b764 100644 --- a/src/compatibility/ewww.php +++ b/src/compatibility/ewww.php @@ -6,7 +6,7 @@ } if ( ! function_exists( 'stackable_load_image_optimizer_polyfill_frontend_script' ) ) { - function stackable_load_image_optimizer_polyfill_frontend_script( $block_content, $block ) { + function stackable_load_image_optimizer_polyfill_frontend_script( $block_content ) { // If Easy IO setting is activated for EWWW Image Optimizer, dynamic images becomes blurry. // Load the script to fix the issue. if ( ! is_admin() ) { diff --git a/src/init.php b/src/init.php index ab886cb39e..47af91431d 100644 --- a/src/init.php +++ b/src/init.php @@ -20,14 +20,14 @@ class Stackable_Init { * Holds the scripts which are already enqueued, to ensure we only do it once per script. * @var Array */ - public $scripts_loaded = array(); + public static $scripts_loaded = array(); /** * Enqueue the frontend scripts, ensures we only do it once. * * @var boolean */ - public $is_main_script_loaded = false; + public static $is_main_script_loaded = false; /** * Add our hooks. @@ -81,9 +81,9 @@ function __construct() { * @return void */ public function maybe_force_css_load() { - if ( ! $this->is_main_script_loaded && apply_filters( 'stackable_force_css_load', false ) ) { - $this->block_enqueue_frontend_assets(); - $this->is_main_script_loaded = true; + if ( ! self::$is_main_script_loaded && apply_filters( 'stackable_force_css_load', false ) ) { + self::block_enqueue_frontend_assets(); + self::$is_main_script_loaded = true; } } @@ -92,7 +92,7 @@ public function maybe_force_css_load() { * * @since 0.1 */ - public function register_frontend_assets() { + public static function register_frontend_assets() { // Frontend block styles. wp_register_style( 'ugb-style-css', @@ -171,7 +171,7 @@ public function register_frontend_assets() { */ public function load_frontend_scripts_conditionally_head() { // Only do this in the frontend. - if ( $this->is_main_script_loaded ) { + if ( self::$is_main_script_loaded ) { return; } @@ -186,8 +186,8 @@ public function load_frontend_scripts_conditionally_head() { stripos( $post->post_content, 'stk-highlight' ) !== false ) { // Enqueue our main scripts and styles. - $this->block_enqueue_frontend_assets(); - $this->is_main_script_loaded = true; + self::block_enqueue_frontend_assets(); + self::$is_main_script_loaded = true; } } } @@ -216,12 +216,12 @@ public function load_frontend_scripts_conditionally( $block_content, $block ) { // Load our main frontend scripts if there's a Stackable block // loaded in the frontend. - if ( ! $this->is_main_script_loaded && ! is_admin() ) { + if ( ! self::$is_main_script_loaded && ! is_admin() ) { if ( strpos( $block_content, '