Custom_Image_Header::get_previous_crop()publicWP 4.9.0

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

Method of the class: Custom_Image_Header{}

No Hooks.

Return

Int|false. An attachment ID if one exists. False if none.

Usage

$Custom_Image_Header = new Custom_Image_Header();
$Custom_Image_Header->get_previous_crop( $attachment );
$attachment(array) (required)
An array with a cropped attachment object data.

Changelog

Since 4.9.0 Introduced.

Custom_Image_Header::get_previous_crop() code WP 6.5.4

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;
}