wp/wp-admin/includes/class-custom-image-header.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   107 			array(
   107 			array(
   108 				'id'      => 'set-header-image',
   108 				'id'      => 'set-header-image',
   109 				'title'   => __( 'Header Image' ),
   109 				'title'   => __( 'Header Image' ),
   110 				'content' =>
   110 				'content' =>
   111 					'<p>' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the &#8220;Choose Image&#8221; button.' ) . '</p>' .
   111 					'<p>' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the &#8220;Choose Image&#8221; button.' ) . '</p>' .
   112 					'<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you&#8217;d like and click the &#8220;Save Changes&#8221; button.' ) . '</p>' .
   112 					'<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you would like and click the &#8220;Save Changes&#8221; button.' ) . '</p>' .
   113 					'<p>' . __( 'If your theme has more than one default header image, or you have uploaded more than one custom header image, you have the option of having WordPress display a randomly different image on each page of your site. Click the &#8220;Random&#8221; radio button next to the Uploaded Images or Default Images section to enable this feature.' ) . '</p>' .
   113 					'<p>' . __( 'If your theme has more than one default header image, or you have uploaded more than one custom header image, you have the option of having WordPress display a randomly different image on each page of your site. Click the &#8220;Random&#8221; radio button next to the Uploaded Images or Default Images section to enable this feature.' ) . '</p>' .
   114 					'<p>' . __( 'If you don&#8217;t want a header image to be displayed on your site at all, click the &#8220;Remove Header Image&#8221; button at the bottom of the Header Image section of this page. If you want to re-enable the header image later, you just have to select one of the other image options and click &#8220;Save Changes&#8221;.' ) . '</p>',
   114 					'<p>' . __( 'If you do not want a header image to be displayed on your site at all, click the &#8220;Remove Header Image&#8221; button at the bottom of the Header Image section of this page. If you want to re-enable the header image later, you just have to select one of the other image options and click &#8220;Save Changes&#8221;.' ) . '</p>',
   115 			)
   115 			)
   116 		);
   116 		);
   117 
   117 
   118 		get_current_screen()->add_help_tab(
   118 		get_current_screen()->add_help_tab(
   119 			array(
   119 			array(
   125 						__( 'For most themes, the header text is your Site Title and Tagline, as defined in the <a href="%s">General Settings</a> section.' ),
   125 						__( 'For most themes, the header text is your Site Title and Tagline, as defined in the <a href="%s">General Settings</a> section.' ),
   126 						admin_url( 'options-general.php' )
   126 						admin_url( 'options-general.php' )
   127 					) .
   127 					) .
   128 					'</p>' .
   128 					'</p>' .
   129 					'<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. &#8220;#ff0000&#8221; for red, or by choosing a color using the color picker.' ) . '</p>' .
   129 					'<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. &#8220;#ff0000&#8221; for red, or by choosing a color using the color picker.' ) . '</p>' .
   130 					'<p>' . __( 'Don&#8217;t forget to click &#8220;Save Changes&#8221; when you&#8217;re done!' ) . '</p>',
   130 					'<p>' . __( 'Do not forget to click &#8220;Save Changes&#8221; when you are done!' ) . '</p>',
   131 			)
   131 			)
   132 		);
   132 		);
   133 
   133 
   134 		get_current_screen()->set_help_sidebar(
   134 		get_current_screen()->set_help_sidebar(
   135 			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   135 			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   391 		} else {
   391 		} else {
   392 			pickColor( text_color.val() );
   392 			pickColor( text_color.val() );
   393 		}
   393 		}
   394 	}
   394 	}
   395 
   395 
   396 	$(document).ready(function() {
   396 	$( function() {
   397 		var text_color = $('#text-color');
   397 		var text_color = $('#text-color');
   398 		header_text_fields = $('.displaying-header-text');
   398 		header_text_fields = $('.displaying-header-text');
   399 		text_color.wpColorPicker({
   399 		text_color.wpColorPicker({
   400 			change: function( event, ui ) {
   400 			change: function( event, ui ) {
   401 				pickColor( text_color.wpColorPicker('color') );
   401 				pickColor( text_color.wpColorPicker('color') );
   406 		});
   406 		});
   407 		$('#display-header-text').click( toggle_text );
   407 		$('#display-header-text').click( toggle_text );
   408 		<?php if ( ! display_header_text() ) : ?>
   408 		<?php if ( ! display_header_text() ) : ?>
   409 		toggle_text();
   409 		toggle_text();
   410 		<?php endif; ?>
   410 		<?php endif; ?>
   411 	});
   411 	} );
   412 })(jQuery);
   412 })(jQuery);
   413 </script>
   413 </script>
   414 		<?php
   414 		<?php
   415 	}
   415 	}
   416 
   416 
   428 		jQuery( '#y1' ).val(coords.y);
   428 		jQuery( '#y1' ).val(coords.y);
   429 		jQuery( '#width' ).val(coords.w);
   429 		jQuery( '#width' ).val(coords.w);
   430 		jQuery( '#height' ).val(coords.h);
   430 		jQuery( '#height' ).val(coords.h);
   431 	}
   431 	}
   432 
   432 
   433 	jQuery(document).ready(function() {
   433 	jQuery( function() {
   434 		var xinit = <?php echo absint( get_theme_support( 'custom-header', 'width' ) ); ?>;
   434 		var xinit = <?php echo absint( get_theme_support( 'custom-header', 'width' ) ); ?>;
   435 		var yinit = <?php echo absint( get_theme_support( 'custom-header', 'height' ) ); ?>;
   435 		var yinit = <?php echo absint( get_theme_support( 'custom-header', 'height' ) ); ?>;
   436 		var ratio = xinit / yinit;
   436 		var ratio = xinit / yinit;
   437 		var ximg = jQuery('img#upload').width();
   437 		var ximg = jQuery('img#upload').width();
   438 		var yimg = jQuery('img#upload').height();
   438 		var yimg = jQuery('img#upload').height();
   483 				jQuery('#y1').val(c.y1);
   483 				jQuery('#y1').val(c.y1);
   484 				jQuery('#width').val(c.width);
   484 				jQuery('#width').val(c.width);
   485 				jQuery('#height').val(c.height);
   485 				jQuery('#height').val(c.height);
   486 			}
   486 			}
   487 		});
   487 		});
   488 	});
   488 	} );
   489 </script>
   489 </script>
   490 		<?php
   490 		<?php
   491 	}
   491 	}
   492 
   492 
   493 	/**
   493 	/**
   649 		<input type="hidden" name="action" value="save" />
   649 		<input type="hidden" name="action" value="save" />
   650 			<?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
   650 			<?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
   651 			<?php submit_button( __( 'Upload' ), '', 'submit', false ); ?>
   651 			<?php submit_button( __( 'Upload' ), '', 'submit', false ); ?>
   652 	</p>
   652 	</p>
   653 			<?php
   653 			<?php
   654 				$modal_update_href = esc_url(
   654 			$modal_update_href = add_query_arg(
   655 					add_query_arg(
   655 				array(
   656 						array(
   656 					'page'                          => 'custom-header',
   657 							'page' => 'custom-header',
   657 					'step'                          => 2,
   658 							'step' => 2,
   658 					'_wpnonce-custom-header-upload' => wp_create_nonce( 'custom-header-upload' ),
   659 							'_wpnonce-custom-header-upload' => wp_create_nonce( 'custom-header-upload' ),
   659 				),
   660 						),
   660 				admin_url( 'themes.php' )
   661 						admin_url( 'themes.php' )
   661 			);
   662 					)
       
   663 				);
       
   664 			?>
   662 			?>
   665 	<p>
   663 	<p>
   666 		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
   664 		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
   667 		<button id="choose-from-library-link" class="button"
   665 		<button id="choose-from-library-link" class="button"
   668 			data-update-link="<?php echo esc_attr( $modal_update_href ); ?>"
   666 			data-update-link="<?php echo esc_url( $modal_update_href ); ?>"
   669 			data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
   667 			data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
   670 			data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></button>
   668 			data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></button>
   671 	</p>
   669 	</p>
   672 	</form>
   670 	</form>
   673 </td>
   671 </td>
   815 		check_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' );
   813 		check_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' );
   816 
   814 
   817 		if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
   815 		if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
   818 			wp_die(
   816 			wp_die(
   819 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
   817 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
   820 				'<p>' . __( 'The current theme does not support uploading a custom header image.' ) . '</p>',
   818 				'<p>' . __( 'The active theme does not support uploading a custom header image.' ) . '</p>',
   821 				403
   819 				403
   822 			);
   820 			);
   823 		}
   821 		}
   824 
   822 
   825 		if ( empty( $_POST ) && isset( $_GET['file'] ) ) {
   823 		if ( empty( $_POST ) && isset( $_GET['file'] ) ) {
   973 		$url      = $file['url'];
   971 		$url      = $file['url'];
   974 		$type     = $file['type'];
   972 		$type     = $file['type'];
   975 		$file     = $file['file'];
   973 		$file     = $file['file'];
   976 		$filename = wp_basename( $file );
   974 		$filename = wp_basename( $file );
   977 
   975 
   978 		// Construct the object array.
   976 		// Construct the attachment array.
   979 		$object = array(
   977 		$attachment = array(
   980 			'post_title'     => $filename,
   978 			'post_title'     => $filename,
   981 			'post_content'   => $url,
   979 			'post_content'   => $url,
   982 			'post_mime_type' => $type,
   980 			'post_mime_type' => $type,
   983 			'guid'           => $url,
   981 			'guid'           => $url,
   984 			'context'        => 'custom-header',
   982 			'context'        => 'custom-header',
   985 		);
   983 		);
   986 
   984 
   987 		// Save the data.
   985 		// Save the data.
   988 		$attachment_id = wp_insert_attachment( $object, $file );
   986 		$attachment_id = wp_insert_attachment( $attachment, $file );
   989 
   987 
   990 		return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
   988 		return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
   991 	}
   989 	}
   992 
   990 
   993 	/**
   991 	/**
  1001 		check_admin_referer( 'custom-header-crop-image' );
   999 		check_admin_referer( 'custom-header-crop-image' );
  1002 
  1000 
  1003 		if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
  1001 		if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
  1004 			wp_die(
  1002 			wp_die(
  1005 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
  1003 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
  1006 				'<p>' . __( 'The current theme does not support uploading a custom header image.' ) . '</p>',
  1004 				'<p>' . __( 'The active theme does not support uploading a custom header image.' ) . '</p>',
  1007 				403
  1005 				403
  1008 			);
  1006 			);
  1009 		}
  1007 		}
  1010 
  1008 
  1011 		if ( ! empty( $_POST['skip-cropping'] )
  1009 		if ( ! empty( $_POST['skip-cropping'] )
  1012 			&& ! current_theme_supports( 'custom-header', 'flex-height' )
  1010 			&& ! current_theme_supports( 'custom-header', 'flex-height' )
  1013 			&& ! current_theme_supports( 'custom-header', 'flex-width' )
  1011 			&& ! current_theme_supports( 'custom-header', 'flex-width' )
  1014 		) {
  1012 		) {
  1015 			wp_die(
  1013 			wp_die(
  1016 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
  1014 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
  1017 				'<p>' . __( 'The current theme does not support a flexible sized header image.' ) . '</p>',
  1015 				'<p>' . __( 'The active theme does not support a flexible sized header image.' ) . '</p>',
  1018 				403
  1016 				403
  1019 			);
  1017 			);
  1020 		}
  1018 		}
  1021 
  1019 
  1022 		if ( $_POST['oitar'] > 1 ) {
  1020 		if ( $_POST['oitar'] > 1 ) {
  1059 		}
  1057 		}
  1060 
  1058 
  1061 		/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
  1059 		/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
  1062 		$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  1060 		$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  1063 
  1061 
  1064 		$object = $this->create_attachment_object( $cropped, $attachment_id );
  1062 		$attachment = $this->create_attachment_object( $cropped, $attachment_id );
  1065 
  1063 
  1066 		if ( ! empty( $_POST['create-new-attachment'] ) ) {
  1064 		if ( ! empty( $_POST['create-new-attachment'] ) ) {
  1067 			unset( $object['ID'] );
  1065 			unset( $attachment['ID'] );
  1068 		}
  1066 		}
  1069 
  1067 
  1070 		// Update the attachment.
  1068 		// Update the attachment.
  1071 		$attachment_id = $this->insert_attachment( $object, $cropped );
  1069 		$attachment_id = $this->insert_attachment( $attachment, $cropped );
  1072 
  1070 
  1073 		$url = wp_get_attachment_url( $attachment_id );
  1071 		$url = wp_get_attachment_url( $attachment_id );
  1074 		$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
  1072 		$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
  1075 
  1073 
  1076 		// Cleanup.
  1074 		// Cleanup.
  1298 	 *
  1296 	 *
  1299 	 * @since 3.9.0
  1297 	 * @since 3.9.0
  1300 	 *
  1298 	 *
  1301 	 * @param string $cropped              Cropped image URL.
  1299 	 * @param string $cropped              Cropped image URL.
  1302 	 * @param int    $parent_attachment_id Attachment ID of parent image.
  1300 	 * @param int    $parent_attachment_id Attachment ID of parent image.
  1303 	 * @return array Attachment object.
  1301 	 * @return array An array with attachment object data.
  1304 	 */
  1302 	 */
  1305 	final public function create_attachment_object( $cropped, $parent_attachment_id ) {
  1303 	final public function create_attachment_object( $cropped, $parent_attachment_id ) {
  1306 		$parent     = get_post( $parent_attachment_id );
  1304 		$parent     = get_post( $parent_attachment_id );
  1307 		$parent_url = wp_get_attachment_url( $parent->ID );
  1305 		$parent_url = wp_get_attachment_url( $parent->ID );
  1308 		$url        = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
  1306 		$url        = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
  1309 
  1307 
  1310 		$size       = wp_getimagesize( $cropped );
  1308 		$size       = wp_getimagesize( $cropped );
  1311 		$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
  1309 		$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
  1312 
  1310 
  1313 		$object = array(
  1311 		$attachment = array(
  1314 			'ID'             => $parent_attachment_id,
  1312 			'ID'             => $parent_attachment_id,
  1315 			'post_title'     => wp_basename( $cropped ),
  1313 			'post_title'     => wp_basename( $cropped ),
  1316 			'post_mime_type' => $image_type,
  1314 			'post_mime_type' => $image_type,
  1317 			'guid'           => $url,
  1315 			'guid'           => $url,
  1318 			'context'        => 'custom-header',
  1316 			'context'        => 'custom-header',
  1319 			'post_parent'    => $parent_attachment_id,
  1317 			'post_parent'    => $parent_attachment_id,
  1320 		);
  1318 		);
  1321 
  1319 
  1322 		return $object;
  1320 		return $attachment;
  1323 	}
  1321 	}
  1324 
  1322 
  1325 	/**
  1323 	/**
  1326 	 * Insert an attachment and its metadata.
  1324 	 * Insert an attachment and its metadata.
  1327 	 *
  1325 	 *
  1328 	 * @since 3.9.0
  1326 	 * @since 3.9.0
  1329 	 *
  1327 	 *
  1330 	 * @param array  $object  Attachment object.
  1328 	 * @param array  $attachment An array with attachment object data.
  1331 	 * @param string $cropped File path to cropped image.
  1329 	 * @param string $cropped    File path to cropped image.
  1332 	 * @return int Attachment ID.
  1330 	 * @return int Attachment ID.
  1333 	 */
  1331 	 */
  1334 	final public function insert_attachment( $object, $cropped ) {
  1332 	final public function insert_attachment( $attachment, $cropped ) {
  1335 		$parent_id = isset( $object['post_parent'] ) ? $object['post_parent'] : null;
  1333 		$parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null;
  1336 		unset( $object['post_parent'] );
  1334 		unset( $attachment['post_parent'] );
  1337 
  1335 
  1338 		$attachment_id = wp_insert_attachment( $object, $cropped );
  1336 		$attachment_id = wp_insert_attachment( $attachment, $cropped );
  1339 		$metadata      = wp_generate_attachment_metadata( $attachment_id, $cropped );
  1337 		$metadata      = wp_generate_attachment_metadata( $attachment_id, $cropped );
  1340 
  1338 
  1341 		// If this is a crop, save the original attachment ID as metadata.
  1339 		// If this is a crop, save the original attachment ID as metadata.
  1342 		if ( $parent_id ) {
  1340 		if ( $parent_id ) {
  1343 			$metadata['attachment_parent'] = $parent_id;
  1341 			$metadata['attachment_parent'] = $parent_id;
  1402 		}
  1400 		}
  1403 
  1401 
  1404 		/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
  1402 		/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
  1405 		$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  1403 		$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  1406 
  1404 
  1407 		$object = $this->create_attachment_object( $cropped, $attachment_id );
  1405 		$attachment = $this->create_attachment_object( $cropped, $attachment_id );
  1408 
  1406 
  1409 		$previous = $this->get_previous_crop( $object );
  1407 		$previous = $this->get_previous_crop( $attachment );
  1410 
  1408 
  1411 		if ( $previous ) {
  1409 		if ( $previous ) {
  1412 			$object['ID'] = $previous;
  1410 			$attachment['ID'] = $previous;
  1413 		} else {
  1411 		} else {
  1414 			unset( $object['ID'] );
  1412 			unset( $attachment['ID'] );
  1415 		}
  1413 		}
  1416 
  1414 
  1417 		$new_attachment_id = $this->insert_attachment( $object, $cropped );
  1415 		$new_attachment_id = $this->insert_attachment( $attachment, $cropped );
  1418 
  1416 
  1419 		$object['attachment_id'] = $new_attachment_id;
  1417 		$attachment['attachment_id'] = $new_attachment_id;
  1420 		$object['url']           = wp_get_attachment_url( $new_attachment_id );
  1418 		$attachment['url']           = wp_get_attachment_url( $new_attachment_id );
  1421 
  1419 
  1422 		$object['width']  = $dimensions['dst_width'];
  1420 		$attachment['width']  = $dimensions['dst_width'];
  1423 		$object['height'] = $dimensions['dst_height'];
  1421 		$attachment['height'] = $dimensions['dst_height'];
  1424 
  1422 
  1425 		wp_send_json_success( $object );
  1423 		wp_send_json_success( $attachment );
  1426 	}
  1424 	}
  1427 
  1425 
  1428 	/**
  1426 	/**
  1429 	 * Given an attachment ID for a header image, updates its "last used"
  1427 	 * Given an attachment ID for a header image, updates its "last used"
  1430 	 * timestamp to now.
  1428 	 * timestamp to now.
  1453 		wp_send_json_success();
  1451 		wp_send_json_success();
  1454 	}
  1452 	}
  1455 
  1453 
  1456 	/**
  1454 	/**
  1457 	 * Given an attachment ID for a header image, unsets it as a user-uploaded
  1455 	 * Given an attachment ID for a header image, unsets it as a user-uploaded
  1458 	 * header image for the current theme.
  1456 	 * header image for the active theme.
  1459 	 *
  1457 	 *
  1460 	 * Triggered when the user clicks the overlay "X" button next to each image
  1458 	 * Triggered when the user clicks the overlay "X" button next to each image
  1461 	 * choice in the Customizer's Header tool.
  1459 	 * choice in the Customizer's Header tool.
  1462 	 *
  1460 	 *
  1463 	 * @since 3.9.0
  1461 	 * @since 3.9.0
  1575 	/**
  1573 	/**
  1576 	 * Get the ID of a previous crop from the same base image.
  1574 	 * Get the ID of a previous crop from the same base image.
  1577 	 *
  1575 	 *
  1578 	 * @since 4.9.0
  1576 	 * @since 4.9.0
  1579 	 *
  1577 	 *
  1580 	 * @param array $object A crop attachment object.
  1578 	 * @param array $attachment An array with a cropped attachment object data.
  1581 	 * @return int|false An attachment ID if one exists. False if none.
  1579 	 * @return int|false An attachment ID if one exists. False if none.
  1582 	 */
  1580 	 */
  1583 	public function get_previous_crop( $object ) {
  1581 	public function get_previous_crop( $attachment ) {
  1584 		$header_images = $this->get_uploaded_header_images();
  1582 		$header_images = $this->get_uploaded_header_images();
  1585 
  1583 
  1586 		// Bail early if there are no header images.
  1584 		// Bail early if there are no header images.
  1587 		if ( empty( $header_images ) ) {
  1585 		if ( empty( $header_images ) ) {
  1588 			return false;
  1586 			return false;
  1589 		}
  1587 		}
  1590 
  1588 
  1591 		$previous = false;
  1589 		$previous = false;
  1592 
  1590 
  1593 		foreach ( $header_images as $image ) {
  1591 		foreach ( $header_images as $image ) {
  1594 			if ( $image['attachment_parent'] === $object['post_parent'] ) {
  1592 			if ( $image['attachment_parent'] === $attachment['post_parent'] ) {
  1595 				$previous = $image['attachment_id'];
  1593 				$previous = $image['attachment_id'];
  1596 				break;
  1594 				break;
  1597 			}
  1595 			}
  1598 		}
  1596 		}
  1599 
  1597