Make WordPress Core

Ticket #12799: 12799-2.diff

File 12799-2.diff, 3.1 KB (added by antpb, 9 years ago)
  • src/wp-includes/media.php

     
    13931393 *     @type string       $ids        A comma-separated list of IDs of attachments to display. Default empty.
    13941394 *     @type string       $include    A comma-separated list of IDs of attachments to include. Default empty.
    13951395 *     @type string       $exclude    A comma-separated list of IDs of attachments to exclude. Default empty.
     1396 *     @type string       $maxdisp    Sets a maxiumum list of attachments to display.
    13961397 *     @type string       $link       What to link each image to. Default empty (links to the attachment page).
    13971398 *                                    Accepts 'file', 'none'.
    13981399 * }
     
    14441445                'size'       => 'thumbnail',
    14451446                'include'    => '',
    14461447                'exclude'    => '',
     1448                'maxdisp'    => 0,
    14471449                'link'       => ''
    14481450        ), $attr, 'gallery' );
    14491451
    14501452        $id = intval( $atts['id'] );
    14511453
     1454        $maxdisp = intval( $atts['maxdisp'] );
     1455        if ( $maxdisp <= 0 )
     1456                $maxdisp = -1;
     1457
    14521458        if ( ! empty( $atts['include'] ) ) {
    1453                 $_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
     1459                $_attachments = get_posts( array( 'include' => $atts['include'], 'numberposts' => $maxdisp, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
    14541460
    14551461                $attachments = array();
    14561462                foreach ( $_attachments as $key => $val ) {
     
    14571463                        $attachments[$val->ID] = $_attachments[$key];
    14581464                }
    14591465        } elseif ( ! empty( $atts['exclude'] ) ) {
    1460                 $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'] ) );
     1466                $attachments = get_children( array( 'numberposts' => $maxdisp, 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
    14611467        } else {
    1462                 $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
     1468                $attachments = get_children( array( 'numberposts' => $maxdisp, 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
    14631469        }
    14641470
    14651471        if ( empty( $attachments ) ) {
    14661472                return '';
     1473       
    14671474        }
     1475       
     1476         // Necessary because in get_posts(), when specifying include="", the numberposts parameter is ignored (it's set to match the number if items in include="")   
     1477        if ( $maxdisp > 0 )
     1478        $attachments = array_slice( $attachments, 0, $maxdisp, true );
    14681479
    14691480        if ( is_feed() ) {
    14701481                $output = "\n";