WordPress.org

Make WordPress Core

Ticket #24688: 24688-2.diff

File 24688-2.diff, 3.3 KB (added by iCaleb, 14 months ago)

Updated patch w/ previously mentioned changes.

  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index ec50703b33..ae6d15b311 100644
    a b function next_image_link( $size = 'thumbnail', $text = false ) { 
    27932793 *
    27942794 * @since 2.5.0
    27952795 *
     2796 * @uses _previous_image_post_where_filter_once()
     2797 * @uses _next_image_post_where_filter_once()
     2798 *
    27962799 * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
    27972800 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width and height
    27982801 *                           values in pixels (in that order). Default 'thumbnail'.
    27992802 * @param bool         $text Optional. Link text. Default false.
    28002803 */
    28012804function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
    2802         $post        = get_post();
    2803         $attachments = array_values(
     2805        $adjacent = $prev ? 'previous' : 'next';
     2806        $order    = $prev ? 'DESC' : 'ASC';
     2807        $post     = get_post();
     2808
     2809        add_filter( 'posts_where', "_{$adjacent}_image_posts_where_filter_once" );
     2810
     2811        $attachment = array_values(
    28042812                get_children(
    28052813                        array(
    2806                                 'post_parent'    => $post->post_parent,
    2807                                 'post_status'    => 'inherit',
    2808                                 'post_type'      => 'attachment',
    2809                                 'post_mime_type' => 'image',
    2810                                 'order'          => 'ASC',
    2811                                 'orderby'        => 'menu_order ID',
     2814                                'post_parent'      => $post->post_parent,
     2815                                'post_status'      => 'inherit',
     2816                                'post_type'        => 'attachment',
     2817                                'post_mime_type'   => 'image',
     2818                                'orderby'          => array(
     2819                                        'menu_order' => $order,
     2820                                        'ID'         => $order,
     2821                                ),
     2822                                'posts_per_page'   => 1,
     2823                                'suppress_filters' => false,
    28122824                        )
    28132825                )
    28142826        );
    28152827
    2816         foreach ( $attachments as $k => $attachment ) {
    2817                 if ( $attachment->ID == $post->ID ) {
    2818                         break;
    2819                 }
    2820         }
    2821 
    28222828        $output        = '';
    28232829        $attachment_id = 0;
    28242830
    2825         if ( $attachments ) {
    2826                 $k = $prev ? $k - 1 : $k + 1;
    2827 
    2828                 if ( isset( $attachments[ $k ] ) ) {
    2829                         $attachment_id = $attachments[ $k ]->ID;
    2830                         $output        = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
    2831                 }
     2831        if ( ! empty( $attachment ) ) {
     2832                $attachment_id = $attachment[0]->ID;
     2833                $output        = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
    28322834        }
    28332835
    2834         $adjacent = $prev ? 'previous' : 'next';
    2835 
    28362836        /**
    28372837         * Filters the adjacent image link.
    28382838         *
    function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) 
    28492849        echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );
    28502850}
    28512851
     2852/**
     2853 * Append to WHERE clause for selecting only the previous image.
     2854 *
     2855 * @param string $where The WHERE clause of the query.
     2856 */
     2857function _previous_image_posts_where_filter_once( $where ) {
     2858        remove_filter( 'posts_where', __FUNCTION__ );
     2859        $post = get_post();
     2860        return "$where AND (menu_order < $post->menu_order OR (menu_order = $post->menu_order AND ID < $post->ID))";
     2861}
     2862
     2863/**
     2864 * Append to WHERE clause for selecting only the next image.
     2865 *
     2866 * @param string $where The WHERE clause of the query.
     2867 */
     2868function _next_image_posts_where_filter_once( $where ) {
     2869        remove_filter( 'posts_where', __FUNCTION__ );
     2870        $post = get_post();
     2871        return "$where AND (menu_order > $post->menu_order OR (menu_order = $post->menu_order AND ID > $post->ID))";
     2872}
     2873
    28522874/**
    28532875 * Retrieves taxonomies attached to given the attachment.
    28542876 *