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 ) { |
| 2793 | 2793 | * |
| 2794 | 2794 | * @since 2.5.0 |
| 2795 | 2795 | * |
| | 2796 | * @uses _previous_image_post_where_filter_once() |
| | 2797 | * @uses _next_image_post_where_filter_once() |
| | 2798 | * |
| 2796 | 2799 | * @param bool $prev Optional. Whether to display the next (false) or previous (true) link. Default true. |
| 2797 | 2800 | * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width and height |
| 2798 | 2801 | * values in pixels (in that order). Default 'thumbnail'. |
| 2799 | 2802 | * @param bool $text Optional. Link text. Default false. |
| 2800 | 2803 | */ |
| 2801 | 2804 | function 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( |
| 2804 | 2812 | get_children( |
| 2805 | 2813 | 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, |
| 2812 | 2824 | ) |
| 2813 | 2825 | ) |
| 2814 | 2826 | ); |
| 2815 | 2827 | |
| 2816 | | foreach ( $attachments as $k => $attachment ) { |
| 2817 | | if ( $attachment->ID == $post->ID ) { |
| 2818 | | break; |
| 2819 | | } |
| 2820 | | } |
| 2821 | | |
| 2822 | 2828 | $output = ''; |
| 2823 | 2829 | $attachment_id = 0; |
| 2824 | 2830 | |
| 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 ); |
| 2832 | 2834 | } |
| 2833 | 2835 | |
| 2834 | | $adjacent = $prev ? 'previous' : 'next'; |
| 2835 | | |
| 2836 | 2836 | /** |
| 2837 | 2837 | * Filters the adjacent image link. |
| 2838 | 2838 | * |
| … |
… |
function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) |
| 2849 | 2849 | echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text ); |
| 2850 | 2850 | } |
| 2851 | 2851 | |
| | 2852 | /** |
| | 2853 | * Append to WHERE clause for selecting only the previous image. |
| | 2854 | * |
| | 2855 | * @param string $where The WHERE clause of the query. |
| | 2856 | */ |
| | 2857 | function _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 | */ |
| | 2868 | function _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 | |
| 2852 | 2874 | /** |
| 2853 | 2875 | * Retrieves taxonomies attached to given the attachment. |
| 2854 | 2876 | * |