Minor changes
This commit is contained in:
@ -207,7 +207,7 @@ function build_gallery_items_html($gallery_items_data, $attributes) {
|
||||
|
||||
// Create the HTML structure for each item, including data-responsive
|
||||
$html .= '
|
||||
<a data-lg-size="' . esc_attr($lg_size) . '"
|
||||
<a class="lcp-gallery-item" data-lg-size="' . esc_attr($lg_size) . '"
|
||||
data-responsive="' . esc_attr($responsive) . '"
|
||||
class="lcp-gallery-item"
|
||||
data-src="' . esc_url($src) . '"
|
||||
@ -279,8 +279,9 @@ function build_dynamic_elements_array($gallery_items_data) {
|
||||
}
|
||||
|
||||
// Build the gallery settings JSON
|
||||
function build_gallery_settings_json($attributes,$unique_class) {
|
||||
$container_class = ".". $unique_class;
|
||||
function build_gallery_settings_json($attributes, $unique_class) {
|
||||
$container_class = "." . $unique_class;
|
||||
|
||||
// Step 1: Get the media IDs based on the attributes
|
||||
$media_ids = get_media_ids($attributes);
|
||||
if (empty($media_ids)) {
|
||||
@ -312,10 +313,18 @@ function build_gallery_settings_json($attributes,$unique_class) {
|
||||
$lgSettings['dynamicEl'] = $dynamic_elements;
|
||||
}
|
||||
|
||||
// Step 7: Return the modified lgSettings object as JSON
|
||||
// Step 7: Get the plugins array
|
||||
$plugins = build_plugins_json($attributes);
|
||||
|
||||
// Step 8: Add plugins to lgSettings
|
||||
if (!empty($plugins)) {
|
||||
$lgSettings['plugins'] = $plugins;
|
||||
}
|
||||
|
||||
// Step 9: Return the modified lgSettings object as JSON
|
||||
$json = json_encode($lgSettings);
|
||||
|
||||
// Step 8: Check for JSON encoding errors
|
||||
// Step 10: Check for JSON encoding errors
|
||||
if ($json === false) {
|
||||
return json_encode(['error' => 'JSON encoding failed', 'error_details' => json_last_error_msg()]);
|
||||
}
|
||||
@ -324,6 +333,7 @@ function build_gallery_settings_json($attributes,$unique_class) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Build the gallery styles based on $attributes and a unique class for rendering multiple galleries on the same page
|
||||
function build_gallery_styles($attributes,$unique_class) {
|
||||
$styles = "<style>";
|
||||
@ -346,7 +356,8 @@ function build_gallery_styles($attributes,$unique_class) {
|
||||
|
||||
// Render the block
|
||||
function render_lcp_gallery_block($attributes) {
|
||||
$unique_class = lcp_random_string(8, true);
|
||||
// Generate a unique class for each gallery
|
||||
$unique_class = lcp_random_string(12, true);
|
||||
// Get the media IDs based on the attributes
|
||||
$media_ids = get_media_ids($attributes);
|
||||
|
||||
@ -363,7 +374,8 @@ function render_lcp_gallery_block($attributes) {
|
||||
|
||||
|
||||
// Generate styles for the gallery based on the unique class
|
||||
$classes = 'lcp-gallery'; // Start with lcp-gallery class
|
||||
$classes = 'lcp-gallery '; // Start with lcp-gallery class
|
||||
$classes .= $unique_class;
|
||||
|
||||
// Check if 'initialLayout' is set to 'grid' and add grid column classes if applicable
|
||||
if (isset($attributes['initialLayout']) && $attributes['initialLayout'] === 'grid') {
|
||||
@ -385,15 +397,16 @@ if (isset($attributes['initialLayout']) && $attributes['initialLayout'] === 'gri
|
||||
|
||||
// Add 'initialLayout' class if it exists and isn't 'grid'
|
||||
if (isset($attributes['initialLayout']) && !empty($attributes['initialLayout']) && $attributes['initialLayout'] !== 'grid') {
|
||||
$classes .= ' ' . esc_attr($attributes['initialLayout']);
|
||||
$classes .= ' ' . "lcp-inline-gallery";
|
||||
}
|
||||
|
||||
|
||||
// Build the styles using the unique class (if necessary)
|
||||
$styles = build_gallery_styles($attributes, $unique_class);
|
||||
|
||||
// Return the complete gallery HTML with the unique class and the settings as a JSON string
|
||||
return "
|
||||
<div class= '{$classes}' data-lgSettings='" . esc_attr($gallery_settings_json) . "'>
|
||||
<div class= '{$classes}' data-lgSettings='" . esc_attr($gallery_settings_json) . "'>
|
||||
{$gallery_items_html}
|
||||
</div>";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user