Avoid a PHP notice in adjacent_image_link() if no images were found.

props nabil_kadimi.
see #28361.
Built from https://develop.svn.wordpress.org/trunk@28584


git-svn-id: http://core.svn.wordpress.org/trunk@28409 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2014-05-27 10:55:16 +00:00
parent 8653099a83
commit 2b6c8462b3
1 changed files with 13 additions and 7 deletions

View File

@ -1902,16 +1902,22 @@ function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {
$post = get_post(); $post = get_post();
$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' ) ) ); $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' ) ) );
foreach ( $attachments as $k => $attachment ) foreach ( $attachments as $k => $attachment ) {
if ( $attachment->ID == $post->ID ) if ( $attachment->ID == $post->ID ) {
break; break;
}
}
$k = $prev ? $k - 1 : $k + 1; $output = '';
$attachment_id = 0;
$output = $attachment_id = null; if ( $attachments ) {
if ( isset( $attachments[ $k ] ) ) { $k = $prev ? $k - 1 : $k + 1;
$attachment_id = $attachments[ $k ]->ID;
$output = wp_get_attachment_link( $attachment_id, $size, true, false, $text ); if ( isset( $attachments[ $k ] ) ) {
$attachment_id = $attachments[ $k ]->ID;
$output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
}
} }
$adjacent = $prev ? 'previous' : 'next'; $adjacent = $prev ? 'previous' : 'next';