Make WordPress Core


Ignore:
Timestamp:
05/27/2014 10:54:45 AM (11 years ago)
Author:
SergeyBiryukov
Message:

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

props nabil_kadimi.
see #28361.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r28550 r28584  
    19031903    $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' ) ) );
    19041904
    1905     foreach ( $attachments as $k => $attachment )
    1906         if ( $attachment->ID == $post->ID )
     1905    foreach ( $attachments as $k => $attachment ) {
     1906        if ( $attachment->ID == $post->ID ) {
    19071907            break;
    1908 
    1909     $k = $prev ? $k - 1 : $k + 1;
    1910 
    1911     $output = $attachment_id = null;
    1912     if ( isset( $attachments[ $k ] ) ) {
    1913         $attachment_id = $attachments[ $k ]->ID;
    1914         $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
     1908        }
     1909    }
     1910
     1911    $output = '';
     1912    $attachment_id = 0;
     1913
     1914    if ( $attachments ) {
     1915        $k = $prev ? $k - 1 : $k + 1;
     1916
     1917        if ( isset( $attachments[ $k ] ) ) {
     1918            $attachment_id = $attachments[ $k ]->ID;
     1919            $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
     1920        }
    19151921    }
    19161922
Note: See TracChangeset for help on using the changeset viewer.