did_convert_elements ) { return array(); } return array( self::$script_slug => self::$script_src ); } public function shortcode( $attr ) { $post = get_post(); if ( ! empty( $attr['ids'] ) ) { // 'ids' is explicitly ordered, unless you specify otherwise. if ( empty( $attr['orderby'] ) ) { $attr['orderby'] = 'post__in'; } $attr['include'] = $attr['ids']; } $atts = shortcode_atts( array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'include' => '', 'exclude' => '', 'size' => array( $this->args['width'], $this->args['height'] ), ), $attr, 'gallery' ); $id = intval( $atts['id'] ); if ( ! empty( $atts['include'] ) ) { $attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', ) ); } elseif ( ! empty( $atts['exclude'] ) ) { $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', ) ); } else { $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], 'fields' => 'ids', ) ); } if ( empty( $attachments ) ) { return ''; } $urls = array(); foreach ( $attachments as $attachment_id ) { list( $url, $width, $height ) = wp_get_attachment_image_src( $attachment_id, $atts['size'], true ); if ( ! $url ) { continue; } $urls[] = apply_filters('amp_gallery_image_params', array( 'url' => $url, 'width' => $width, 'height' => $height, ),$attachment_id); } return $this->render( array( 'images' => $urls, ) ); } public function render( $args ) { $this->did_convert_elements = true; $args = wp_parse_args( $args, array( 'images' => false, ) ); if ( empty( $args['images'] ) ) { return ''; } $images = array(); foreach ( $args['images'] as $key => $image ) { $images[$key] = AMP_HTML_Utils::build_tag( 'amp-img', array( 'src' => $image['url'], 'width' => $image['width'], 'height' => $image['height'], 'layout' => 'fill', 'class' => 'amp-carousel-img', ) ); $images[$key] = apply_filters('amp_gallery_images', $images[$key], $image); } return AMP_HTML_Utils::build_tag( 'amp-carousel', array( 'width' => $this->args['width'], 'height' => $this->args['height'], 'type' => 'slides', 'layout' => 'responsive', 'class' => 'collapsible-captions', ), implode( PHP_EOL, $images ) ); } }