'', 'post_id' => null, ), $atts); if (empty($atts['field'])) { return ''; } // Get post ID with multiple fallbacks for Elementor compatibility $post_id = null; if (!empty($atts['post_id'])) { $post_id = intval($atts['post_id']); } elseif (get_the_ID()) { $post_id = get_the_ID(); } elseif (isset($GLOBALS['post'])) { $post_id = $GLOBALS['post']->ID; } elseif (is_singular()) { global $wp_query; $post_id = $wp_query->get_queried_object_id(); } if (!$post_id) { return ''; } return agrfuxd_render_enhanced_gallery($atts['field'], $post_id); } add_shortcode('agrfuxd_gallery', 'agrfuxd_gallery_shortcode'); /** * Helper function to render Enhanced Gallery on frontend */ function agrfuxd_render_enhanced_gallery($field_name, $post_id = null) { if (!$post_id) { $post_id = get_the_ID(); } $field = get_field_object($field_name, $post_id); if (!$field) { return ''; } if ($field['type'] !== 'enhanced_gallery') { return ''; } $images = $field['value']; if (empty($images) || !is_array($images)) { return ''; } $layout = $field['display_layout'] ?? 'grid'; $lightbox = $field['enable_lightbox'] ?? true; $unique_id = 'agrfuxd-gallery-' . uniqid(); ob_start(); switch ($layout) { case 'carousel': // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped in render function echo agrfuxd_render_carousel_gallery($images, $field, $unique_id); break; case 'masonry': // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped in render function echo agrfuxd_render_masonry_gallery($images, $field, $unique_id); break; case 'justified': // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped in render function echo agrfuxd_render_justified_gallery($images, $field, $unique_id); break; default: // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped in render function echo agrfuxd_render_grid_gallery($images, $field, $unique_id); } if ($lightbox) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped in render function echo agrfuxd_render_lightbox_modal($images, $unique_id); } return ob_get_clean(); } /** * Render Grid Gallery */ function agrfuxd_render_grid_gallery($images, $field, $unique_id) { $columns = $field['columns'] ?? 3; $gap = $field['gap'] ?? 15; $image_size = $field['image_size'] ?? 'medium'; $lightbox = $field['enable_lightbox'] ?? true; $caption = $field['show_caption'] ?? false; $lazy = $field['enable_lazy_load'] ?? true; ob_start(); ?>