Inventory_Presser_Photo_Numberer::maybe_number_photo( int $post_id )

Filter callback on add_attachment. Decides whether to write meta values on attachments if they are uploaded to vehicles. If this method determines the photo sequence number to be 1, the attachment is also set as the featured image.


Parameters Parameters

$post_id

(int) (Required) Attachment ID.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-photo-numberer.php

	public static function maybe_number_photo( $post_id ) {
		// Is this new attachment even attached to a post?
		$attachment = get_post( $post_id );
		if ( empty( $attachment->post_parent ) ) {
			// No.
			return;
		}

		$parent = get_post( $attachment->post_parent );

		// Is this even attached to a vehicle?
		if ( empty( $parent ) || INVP::POST_TYPE !== $parent->post_type ) {
			// No.
			return;
		}

		// Save the VIN in the photo meta.
		self::save_meta_vin( $post_id, $attachment->post_parent );

		// Save a md5 hash checksum of the attachment in meta.
		self::save_meta_hash( $post_id );

		// Assign and save a sequence number for the photo like 1, 2, 3, etc.
		self::save_meta_photo_number( $post_id, $attachment->post_parent );

		// Delete the transients that hold this vehicle's photos.
		delete_transient( 'invp_get_the_photos_images_' . $post_id );
		delete_transient( 'invp_get_the_photos_image_urls_' . $post_id );
	}