From 7ccb41a76bfc8d9d1f0515bb54757f9a1817fd3c Mon Sep 17 00:00:00 2001 From: Darren Cooney Date: Sat, 7 Jan 2023 13:12:19 -0500 Subject: [PATCH] Fixed issue with localized data variables not working in Full Site Editing (FSE) themes. --- ajax-load-more.php | 4 ++++ core/classes/class-alm-localize.php | 16 +++++++--------- core/classes/class-alm-shortcode.php | 18 ++++++++++++++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ajax-load-more.php b/ajax-load-more.php index 99b25f8..443e227 100755 --- a/ajax-load-more.php +++ b/ajax-load-more.php @@ -14,6 +14,10 @@ * @package AjaxLoadMore */ +/* +* FIX: Fixed issue with localized data variables not working in Full Site Editing (FSE) themes. +*/ + define( 'ALM_VERSION', '5.5.5' ); define( 'ALM_RELEASE', 'January 5, 2023' ); define( 'ALM_STORE_URL', 'https://connekthq.com' ); diff --git a/core/classes/class-alm-localize.php b/core/classes/class-alm-localize.php index 76ec366..39f823d 100755 --- a/core/classes/class-alm-localize.php +++ b/core/classes/class-alm-localize.php @@ -1,6 +1,8 @@ variables for use with Preloaded addon. + * Return the localized data. * - * @param string $id The ALM ID. - * @since 3.7 + * @return array The localized data. */ - public static function create_script_vars( $id ) { - if ( ! empty( self::$vars ) && isset( self::$vars[ $id ] ) && is_array( self::$vars[ $id ] ) ) { - // Render wp_localize_script vars with 'ajax-load-more' script handle. - wp_localize_script( 'ajax-load-more', alm_convert_dashes_to_underscore( $id ) . '_vars', self::$vars[ $id ] ); - } + public static function return_localized_data() { + return self::$vars; } } diff --git a/core/classes/class-alm-shortcode.php b/core/classes/class-alm-shortcode.php index ea7e483..2c28fc5 100755 --- a/core/classes/class-alm-shortcode.php +++ b/core/classes/class-alm-shortcode.php @@ -1385,15 +1385,25 @@ public static function alm_render_shortcode( $atts ) { } } - // Add localized vars. + /** + * Build localized script variables for each ALM instance. + */ + + // Add basic localized vars. ALM_LOCALIZE::add_localized_var( 'id', $master_id, $localize_id ); + ALM_LOCALIZE::add_localized_var( 'script', alm_convert_dashes_to_underscore( $localize_id ) . '_vars', $localize_id ); + + // Get the localized data. + $localized_data = ALM_LOCALIZE::return_localized_data( $localize_id ); /** - * Build localized script vars for each ALM instance. + * Append the localized data `', json_encode( $localized_data[$localize_id] ) ); + }); // End $ajaxloadmore element. return $ajaxloadmore;