su_get_gallery_slides

The shortcodes-ultimate su get gallery slides function.

Published Date - February 15, 2021

Description

Helper function to get gallery slides.

su_get_gallery_slides( $atts );

Parameters

  1. $atts


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_get_gallery_slides' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/functions-galleries.php';
}

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

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

Defined

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

shortcodes-ultimate/includes/functions-galleries.php

function su_get_gallery_slides( $atts ) {

	$slides = array();
	$posts  = su_get_gallery_slides_posts( $atts );

	if ( ! is_array( $posts ) ) {
		return array();
	}

	foreach ( $posts as $post ) {

		$attachment_id = 'attachment' === $post->post_type
			? $post->ID
			: get_post_thumbnail_id( $post->ID );

		if ( ! su_is_positive_number( $attachment_id ) ) {
			continue;
		}

		$caption = 'attachment' === $post->post_type || 'yes' === $atts['prefer_caption']
			? wp_get_attachment_caption( $attachment_id )
			: get_the_title( $post->ID );

		$slide = array(
			'post_id'       => $post->ID,
			'attachment_id' => intval( $attachment_id ),
			'caption'       => trim( $caption ),
		);

		switch ( $atts['link'] ) {

			case 'image':
			case 'lightbox':
				$slide['link'] = wp_get_attachment_image_src( $attachment_id, 'full', false );
				$slide['link'] = $slide['link'][0];
				break;

			case 'custom':
				$slide['link'] = get_post_meta( $attachment_id, 'su_slide_link', true );
				break;

			case 'post':
				$slide['link'] = get_permalink( $post->ID );
				break;

			case 'attachment':
				$slide['link'] = get_attachment_link( $attachment_id );
				break;

			default:
				$slide['link'] = '';
				break;

		}

		$slides[] = $slide;

	}

	$slides = apply_filters( 'su/get_gallery_slides/slides', $slides, $atts );

	return $slides;

}