su_shortcode_custom_gallery

The shortcodes-ultimate su shortcode custom gallery function.

Published Date - February 15, 2021

Description

su_shortcode_custom_gallery( $atts, $content );

Parameters

  1. $atts

  2. $content


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_shortcode_custom_gallery' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/shortcodes/custom-gallery.php';
}

// The input(s). 
$atts = null;
$content = null;

// NOTICE! Understand what this does before running.
$result = su_shortcode_custom_gallery( $atts, $content );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/shortcodes/custom-gallery.php

function su_shortcode_custom_gallery( $atts = null, $content = null ) {
	$return = '';
	$atts   = shortcode_atts(
		array(
			'source'  => 'none',
			'limit'   => 20,
			'gallery' => null, // Dep. 4.4.0
			'link'    => 'none',
			'width'   => 90,
			'height'  => 90,
			'title'   => 'hover',
			'target'  => 'self',
			'class'   => '',
		),
		$atts,
		'custom_gallery'
	);

	$slides = su_get_slides( $atts );
	$slides = apply_filters( 'su/shortcode/custom_gallery/slides', $slides, $atts );

	// Loop slides
	if ( count( $slides ) ) {
		// Prepare links target
		$atts['target'] = ( 'yes' === $atts['target'] || 'blank' === $atts['target'] ) ? ' target="_blank"' : '';
		// Add lightbox class
		if ( 'lightbox' === $atts['link'] ) {
			$atts['class'] .= ' su-lightbox-gallery';
		}
		// Open gallery
		$return = '<div class="su-custom-gallery su-custom-gallery-title-' . $atts['title'] . su_get_css_class( $atts ) . '">';
		// Create slides
		foreach ( $slides as $slide ) {
			// Crop image
			$image = su_image_resize( $slide['image'], $atts['width'], $atts['height'] );

			if ( is_wp_error( $image ) ) {
				continue;
			}

			// Prepare slide title
			$title = ( $slide['title'] ) ? '<span class="su-custom-gallery-title">' . stripslashes( $slide['title'] ) . '</span>' : '';
			// Open slide
			$return .= '<div class="su-custom-gallery-slide">';
			// Slide content with link
			if ( $slide['link'] ) {
				$return .= '<a href="' . $slide['link'] . '"' . $atts['target'] . ' title="' . esc_attr( $slide['title'] ) . '"><img src="' . $image['url'] . '" alt="' . esc_attr( $slide['title'] ) . '" width="' . $atts['width'] . '" height="' . $atts['height'] . '" />' . $title . '</a>';
			}
			// Slide content without link
			else {
				$return .= '<a><img src="' . $image['url'] . '" alt="' . esc_attr( $slide['title'] ) . '" width="' . $atts['width'] . '" height="' . $atts['height'] . '" />' . $title . '</a>';
			}
			// Close slide
			$return .= '</div>';
		}
		// Clear floats
		$return .= '<div class="su-clear"></div>';
		// Close gallery
		$return .= '</div>';
		// Add lightbox assets
		if ( 'lightbox' === $atts['link'] ) {
			su_query_asset( 'css', 'magnific-popup' );
			su_query_asset( 'js', 'jquery' );
			su_query_asset( 'js', 'magnific-popup' );
			su_query_asset( 'js', 'su-shortcodes' );
		}
		su_query_asset( 'css', 'su-shortcodes' );
	}
	// Slides not found
	else {
		$return = su_error_message( 'Custom Gallery', __( 'images not found', 'shortcodes-ultimate' ) );
	}
	return $return;
}