Custom_Image_Header::get_previous_crop() WordPress Method

The Custom_Image_Header::get_previous_crop() method is used to get the crop settings for the previous image in the WordPress media library. This is useful for making sure that the image is cropped correctly when switching between images in the library.

Custom_Image_Header::get_previous_crop( array $attachment ) #

Get the ID of a previous crop from the same base image.


Parameters

$attachment

(array)(Required)An array with a cropped attachment object data.


Top ↑

Return

(int|false) An attachment ID if one exists. False if none.


Top ↑

Source

File: wp-admin/includes/class-custom-image-header.php

	public function get_previous_crop( $attachment ) {
		$header_images = $this->get_uploaded_header_images();

		// Bail early if there are no header images.
		if ( empty( $header_images ) ) {
			return false;
		}

		$previous = false;

		foreach ( $header_images as $image ) {
			if ( $image['attachment_parent'] === $attachment['post_parent'] ) {
				$previous = $image['attachment_id'];
				break;
			}
		}

		return $previous;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.