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