*/ /** * Retrieves the IDs for images in a gallery. * * Uses Hybrid Media Grabber to get the gallery shortcode. * * @return array List of image IDs from the post gallery. */ function canuck_get_gallery_images() { global $content_width; $args = array( 'post_id' => get_the_ID(), // post ID (assumes within The Loop by default). 'type' => 'gallery', // audio|video. 'before' => '', // HTML before the output. 'after' => '', // HTML after the output. 'split_media' => true, // Splits the media from the post content...KA note...original false. 'width' => $content_width, // Custom width. Defaults to the theme's content width. ); $gallery_string = canuck_media_grabber_gallery( $args ); if ( '' !== $gallery_string ) { $images = array(); $pattern = get_shortcode_regex(); // Note: leave as double quotes, or the preg match will not work. preg_match( "/$pattern/s", $gallery_string, $match );// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ( $match ) { $atts = shortcode_parse_atts( $match[3] ); } else { $atts = false; } if ( false !== $atts && isset( $atts['ids'] ) ) { $images = explode( ',', $atts['ids'] ); } else { $images = false; } } else { $images = false; } if ( false === $images ) { $images = get_posts( array( 'fields' => 'ids', 'numberposts' => 20, 'order' => 'ASC', 'orderby' => 'menu_order', 'post_mime_type' => 'image', 'post_parent' => get_the_ID(), 'post_type' => 'attachment', ) ); } if ( '' === $images || false === $images || empty( $images ) ) { $pattern = "/\