Created
July 9, 2022 23:53
-
-
Save patrickfreitasdev/9bf4232e2ae60eafe91a34fb71a3580b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// JS doc https://github.com/fancyapps/ui | |
// Handle the shortcode | |
function custom_gallery_forminator_html_function( $atts = [] ){ | |
// get the IDs from shorcode | |
$gallery = ( isset( $atts['ids'] ) ) ? explode( ',', $atts['ids'] ) : null; | |
if( ! $gallery ){ return; } | |
ob_start(); | |
// Loop using fancybox JS | |
foreach( $gallery as $item ): $desc = get_post($item); | |
?> | |
<a href="<?php echo esc_url( wp_get_attachment_image_url( $item, 'full' ) ) ?>" data-fancybox="gallery" data-caption="<?php echo esc_attr( $desc->post_content ) ?>"> | |
<img src="<?php echo esc_url( wp_get_attachment_image_url( $item, 'medium' ) ) ?>" alt="<?php echo esc_attr( $desc->post_content ) ?>" /> | |
</a> | |
<?php endforeach; | |
return ob_get_clean(); | |
} | |
add_shortcode('forminator-gallery','custom_gallery_forminator_html_function'); | |
// Allow shortcode on Forminator | |
add_filter( 'forminator_replace_variables', 'do_shortcode' ); | |
// Call the scripts, must be improved, this calls everywhere we should apply some conditionals | |
add_action( 'wp_enqueue_scripts', function(){ | |
wp_enqueue_style( 'fancybox', 'https://cdn.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.css', '4.0', 'all' ); | |
wp_enqueue_script( 'fancybox', 'https://cdn.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.umd.js', '4.0', true ); | |
}, 10 ); | |
// Similar here, must be improved to call only where form is located. | |
add_action( 'wp_footer', function(){ | |
?> | |
<script type="text/javascript"> | |
Fancybox.bind("[data-fancybox]", { | |
// Your options go here | |
}); | |
</script> | |
<?php | |
}, 9999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment