From b0abaa3062161c3e468adac3e1e1ac9b3f0a610a Mon Sep 17 00:00:00 2001 From: prconcepcion Date: Thu, 21 Dec 2023 00:15:45 +0800 Subject: [PATCH 1/6] conditionally add args through filters --- src/init.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/init.php b/src/init.php index 40b4f4c69..0b03efd44 100644 --- a/src/init.php +++ b/src/init.php @@ -101,10 +101,7 @@ public function register_frontend_assets() { wp_register_script( 'ugb-block-frontend-js', null, [], STACKABLE_VERSION ); } - $args = apply_filters( 'stackable_localize_frontend_script', array( - 'restUrl' => get_rest_url(), - 'i18n' => array(), // Translatable labels used in the frontend should go here. - ) ); + $args = apply_filters( 'stackable_localize_frontend_script', array() ); wp_localize_script( 'ugb-block-frontend-js', 'stackable', $args ); // Register inline frontend styles, these are always loaded. From 6be733a30b36e18aeaa85317aad7e817d2954cb2 Mon Sep 17 00:00:00 2001 From: prconcepcion Date: Thu, 28 Dec 2023 15:16:47 +0800 Subject: [PATCH 2/6] refactored implementation --- src/init.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/init.php b/src/init.php index 0b03efd44..e7178047e 100644 --- a/src/init.php +++ b/src/init.php @@ -55,6 +55,7 @@ function __construct() { // Adds a special class to the body tag, to indicate we can now run animations. add_action( 'wp_footer', array( $this, 'init_animation' ) ); + add_action( 'wp_footer', array( $this, 'init_stackable_vars' ) ); // Add the fallback values for the default block width and wide block width. // These are used for the inside "Content width" option of Columns. @@ -101,9 +102,6 @@ public function register_frontend_assets() { wp_register_script( 'ugb-block-frontend-js', null, [], STACKABLE_VERSION ); } - $args = apply_filters( 'stackable_localize_frontend_script', array() ); - wp_localize_script( 'ugb-block-frontend-js', 'stackable', $args ); - // Register inline frontend styles, these are always loaded. // Register via a dummy style. wp_register_style( 'ugb-style-css-nodep', false ); @@ -452,6 +450,13 @@ public function load_plugin_textdomain() { public function init_animation() { echo ''; } + + public function init_stackable_vars() { + $args = apply_filters( 'stackable_localize_frontend_script', array() ); + if ( array_key_exists( 'restUrl', $args ) ) { + echo ''; + } + } } new Stackable_init(); From 376f0154c2eead601aaa46a5eb6e87d4758aaf6e Mon Sep 17 00:00:00 2001 From: prconcepcion Date: Tue, 2 Jan 2024 12:31:16 +0800 Subject: [PATCH 3/6] added comments --- src/init.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.php b/src/init.php index e7178047e..6868d7c0e 100644 --- a/src/init.php +++ b/src/init.php @@ -451,6 +451,7 @@ public function init_animation() { echo ''; } + // TODO: make this dynamic public function init_stackable_vars() { $args = apply_filters( 'stackable_localize_frontend_script', array() ); if ( array_key_exists( 'restUrl', $args ) ) { From 71e5a81129daca078236bd3f987f65504f087449 Mon Sep 17 00:00:00 2001 From: Benjamin Intal Date: Wed, 3 Jan 2024 13:13:55 +0800 Subject: [PATCH 4/6] Update src/init.php [skip ci] --- src/init.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/init.php b/src/init.php index 6868d7c0e..e7178047e 100644 --- a/src/init.php +++ b/src/init.php @@ -451,7 +451,6 @@ public function init_animation() { echo ''; } - // TODO: make this dynamic public function init_stackable_vars() { $args = apply_filters( 'stackable_localize_frontend_script', array() ); if ( array_key_exists( 'restUrl', $args ) ) { From f04544e5fd5ac1c8cfc18b9ad7474e78f6e1ec95 Mon Sep 17 00:00:00 2001 From: prconcepcion Date: Fri, 5 Jan 2024 13:57:14 +0800 Subject: [PATCH 5/6] encode args as json --- src/init.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/init.php b/src/init.php index e7178047e..396bb642a 100644 --- a/src/init.php +++ b/src/init.php @@ -453,8 +453,8 @@ public function init_animation() { public function init_stackable_vars() { $args = apply_filters( 'stackable_localize_frontend_script', array() ); - if ( array_key_exists( 'restUrl', $args ) ) { - echo ''; + if ( ! empty( $args ) ) { + echo ' '; } } } From c1b635ab6b43e3d1b3220713a8ca56dd6fbb9b6e Mon Sep 17 00:00:00 2001 From: Benjamin Intal Date: Wed, 17 Jan 2024 14:46:13 +0800 Subject: [PATCH 6/6] Removed spaces [skip ci] --- src/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.php b/src/init.php index 396bb642a..63372e3f9 100644 --- a/src/init.php +++ b/src/init.php @@ -454,7 +454,7 @@ public function init_animation() { public function init_stackable_vars() { $args = apply_filters( 'stackable_localize_frontend_script', array() ); if ( ! empty( $args ) ) { - echo ' '; + echo ''; } } }