Avoid a PHP notice in adjacent_image_link() if no images were found.
props nabil_kadimi. see #28361. git-svn-id: https://develop.svn.wordpress.org/trunk@28584 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4dd4a32cde
commit
06bf55f809
@ -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';
|
||||||
|
Loading…
Reference in New Issue
Block a user