Make WordPress Core

Ticket #24688: media.patch

File media.patch, 3.0 KB (added by dllh, 8 years ago)

Updated patch

  • wp-includes/media.php

     
    26732673 *
    26742674 * @since 2.5.0
    26752675 *
     2676 * @uses _previous_image_post_where_filter_once()
     2677 * @uses _next_image_post_where_filter_once()
     2678 *
    26762679 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
    26772680 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width and height
    26782681 *                           values in pixels (in that order). Default 'thumbnail'.
     
    26792682 * @param bool         $text Optional. Link text. Default false.
    26802683 */
    26812684function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
     2685        $adjacent = $prev ? 'previous' : 'next';
     2686        $order = $prev ? 'DESC' : 'ASC';
    26822687        $post = get_post();
    2683         $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
    26842688
    2685         foreach ( $attachments as $k => $attachment ) {
    2686                 if ( $attachment->ID == $post->ID ) {
    2687                         break;
    2688                 }
    2689         }
     2689        add_filter( 'posts_where', "_{$adjacent}_image_posts_where_filter_once" );
    26902690
     2691        $attachment = array_pop( get_children( array(
     2692                'post_parent'      => $post->post_parent,
     2693                'post_status'      => 'inherit',
     2694                'post_type'        => 'attachment',
     2695                'post_mime_type'   => 'image',
     2696                'orderby'          => "menu_order $order, ID $order",
     2697                'posts_per_page'   => 1,
     2698                'suppress_filters' => false,
     2699        ) ) );
     2700
    26912701        $output = '';
    26922702        $attachment_id = 0;
    26932703
    2694         if ( $attachments ) {
    2695                 $k = $prev ? $k - 1 : $k + 1;
    2696 
    2697                 if ( isset( $attachments[ $k ] ) ) {
    2698                         $attachment_id = $attachments[ $k ]->ID;
    2699                         $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
    2700                 }
     2704        if ( $attachment ) {
     2705                $attachment_id = $attachment->ID;
     2706                $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
    27012707        }
    27022708
    2703         $adjacent = $prev ? 'previous' : 'next';
    2704 
    27052709        /**
    27062710         * Filters the adjacent image link.
    27072711         *
     
    27182722        echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );
    27192723}
    27202724
     2725/**
     2726 * Append to WHERE clause for selecting only the previous image.
     2727 */
     2728function _previous_image_posts_where_filter_once( $where ) {
     2729        remove_filter( 'posts_where', __FUNCTION__ );
     2730        $post = get_post();
     2731        return "$where AND (menu_order < $post->menu_order OR (menu_order = $post->menu_order AND ID < $post->ID))";
     2732}
     2733
     2734/**
     2735 * Append to WHERE clause for selecting only the next image.
     2736 */
     2737function _next_image_posts_where_filter_once( $where ) {
     2738        remove_filter( 'posts_where', __FUNCTION__ );
     2739        $post = get_post();
     2740        return "$where AND (menu_order > $post->menu_order OR (menu_order = $post->menu_order AND ID > $post->ID))";
     2741}
     2742
    27212743/**
    27222744 * Retrieves taxonomies attached to given the attachment.
    27232745 *