Ticket #24688: media.patch
File media.patch, 3.0 KB (added by , 8 years ago) |
---|
-
wp-includes/media.php
2673 2673 * 2674 2674 * @since 2.5.0 2675 2675 * 2676 * @uses _previous_image_post_where_filter_once() 2677 * @uses _next_image_post_where_filter_once() 2678 * 2676 2679 * @param bool $prev Optional. Whether to display the next (false) or previous (true) link. Default true. 2677 2680 * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width and height 2678 2681 * values in pixels (in that order). Default 'thumbnail'. … … 2679 2682 * @param bool $text Optional. Link text. Default false. 2680 2683 */ 2681 2684 function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) { 2685 $adjacent = $prev ? 'previous' : 'next'; 2686 $order = $prev ? 'DESC' : 'ASC'; 2682 2687 $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' ) ) );2684 2688 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" ); 2690 2690 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 2691 2701 $output = ''; 2692 2702 $attachment_id = 0; 2693 2703 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 ); 2701 2707 } 2702 2708 2703 $adjacent = $prev ? 'previous' : 'next';2704 2705 2709 /** 2706 2710 * Filters the adjacent image link. 2707 2711 * … … 2718 2722 echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text ); 2719 2723 } 2720 2724 2725 /** 2726 * Append to WHERE clause for selecting only the previous image. 2727 */ 2728 function _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 */ 2737 function _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 2721 2743 /** 2722 2744 * Retrieves taxonomies attached to given the attachment. 2723 2745 *