name = 'gallery'; $this->slug = 'gallery'; $this->type = 'extension'; $this->category = 'basic'; $this->public = false; $this->enabled = false; } /** * Initialize module */ public function initialize() { add_action( 'admin_init', array( $this, 'gallery_init' ) ); add_action( 'post_gallery', array( $this, 'change_post_gallery' ), 10, 3 ); add_filter( 'jetpack_gallery_types', array( $this, 'jetpack_gallery_types' ) ); // Force Jetpack compatibility with our galleries. add_filter( 'jp_carousel_force_enable', '__return_true' ); } /** * Gallery Shortcode Function * * @param string $output The current output. * @param array $attr Attributes from the gallery shortcode. * @param int $instance Numeric ID of the gallery shortcode instance. */ public function change_post_gallery( $output, $attr, $instance ) { // Make sure we're overwriting only galleries with either layout or type attributes. if ( ! ( isset( $attr['layout'] ) || isset( $attr['type'] ) ) ) { return; } // Support for the deprecated layout attribute. if ( isset( $attr['layout'] ) ) { if ( 'grid' === $attr['layout'] ) { $attr['type'] = 'default'; } else { $attr['type'] = $attr['layout']; } } if ( ! isset( $attr['type'] ) ) { return; } // Return if type is neither justified nor slider. $gallery_types = apply_filters( 'powerkit_gallery_types', array() ); if ( ! array_key_exists( $attr['type'], (array) $gallery_types ) ) { return ''; } global $post; $atts = shortcode_atts( array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'itemtag' => 'figure', 'icontag' => 'div', 'captiontag' => 'figcaption', 'columns' => 3, 'type' => 'default', 'size' => 'thumbnail', 'include' => '', 'exclude' => '', 'link' => '', ), $attr, 'gallery' ); $settings = array( 'custom_class' => '', 'custom_attrs' => '', ); $settings = apply_filters( 'powerkit_gallery_settings', $settings, $attr ); $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'], ) ); $attachments = array(); foreach ( $_attachments as $key => $val ) { $attachments[ $val->ID ] = $_attachments[ $key ]; } } 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'], ) ); } else { $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'], ) ); } if ( empty( $attachments ) ) { return ''; } if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) { $output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n"; } return $output; } $itemtag = tag_escape( $atts['itemtag'] ); $captiontag = tag_escape( $atts['captiontag'] ); $custom_class = $settings['custom_class']; $custom_attrs = $settings['custom_attrs']; if ( 'justified' === $atts['type'] ) { $captiontag = 'div'; } $type = esc_attr( $atts['type'] ); $float = is_rtl() ? 'right' : 'left'; $selector = "gallery-{$instance}"; $size_class = sanitize_html_class( $atts['size'] ); $gallery_div = "