Make WordPress Core

Ticket #42548: 42548.2.diff

File 42548.2.diff, 2.2 KB (added by bobbingwide, 7 years ago)

Change gallery_shortcode to not display unattached images when used in a Text or Custom HTML widget. Support id=0 when this is required.

  • src/wp-includes/media.php

     
    16661666        $atts = shortcode_atts( array(
    16671667                'order'      => 'ASC',
    16681668                'orderby'    => 'menu_order ID',
    1669                 'id'         => $post ? $post->ID : 0,
     1669                'id'         => null,
    16701670                'itemtag'    => $html5 ? 'figure'     : 'dl',
    16711671                'icontag'    => $html5 ? 'div'        : 'dt',
    16721672                'captiontag' => $html5 ? 'figcaption' : 'dd',
     
    16761676                'exclude'    => '',
    16771677                'link'       => ''
    16781678        ), $attr, 'gallery' );
     1679       
     1680        if ( null !== $atts['id'] ) {
     1681                $id = intval( $atts['id'] );
     1682        } else {
     1683                $id = $post ? intval( $post->ID ) : null;
     1684        }
    16791685
    1680         $id = intval( $atts['id'] );
    1681 
    16821686        if ( ! empty( $atts['include'] ) ) {
    16831687                $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
    16841688
     
    16861690                foreach ( $_attachments as $key => $val ) {
    16871691                        $attachments[$val->ID] = $_attachments[$key];
    16881692                }
    1689         } elseif ( ! empty( $atts['exclude'] ) ) {
    1690                 $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'] ) );
    1691         } else {
    1692                 $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
     1693        } elseif ( $id !== null  ) {
     1694                if ( ! empty( $atts['exclude'] ) ) {
     1695                        $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'] ) );
     1696                } else {
     1697                        $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
     1698                }
    16931699        }
    16941700
    16951701        if ( empty( $attachments ) ) {