Inventory_Presser_Photo_Numberer::save_meta_photo_number( int $post_id, int $parent_post_id, int $sequence_number = null )

save_meta_photo_number


Description Description

Saves a sequence number like 1, 2, or 99 in attachment post meta. This number dictates the order in which the photos will be disabled in sliders and galleries.


Top ↑

Parameters Parameters

$post_id

(int) (Required) The post ID of the attachment

$parent_post_id

(int) (Required) The post ID of the vehicle to which $post_id is a child

$sequence_number

(int) (Optional) The sequence number to save. Do not provide to append.

Default value: null


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-photo-numberer.php

	public static function save_meta_photo_number( $post_id, $parent_post_id, $sequence_number = null ) {
		// Does this photo already have a sequence number?
		if ( null == $sequence_number ) {
			if ( ! empty( INVP::get_meta( 'photo_number', $post_id ) ) ) {
				// Yes
				return;
			}

			// Is the number in the slug?
			// photo-5-of-19-of-vinsgsdkdkdkgf
			$number = 0;
			if ( ! empty( $_POST['slug'] ) && preg_match( '/photo\-([0-9]+)\-of\-[0-9]+\-of\-.*/', $_POST['slug'], $matches ) ) {
				$number = intval( $matches[1] );
			} else {
				// Append the photo to the end
				// This hook fires after the attachment is added.
				// How many photos does this vehicle have?
				$number = invp_get_the_photo_count( $parent_post_id );
				if ( 1 == $number ) {
					// This is photo number 1, it should be the featured image
					set_post_thumbnail( $parent_post_id, $post_id );
				}
			}
		} else {
			$number = $sequence_number;
		}

		if ( 0 !== $number ) {
			update_post_meta( $post_id, apply_filters( 'invp_prefix_meta_key', 'photo_number' ), $number );
		}
	}