Inventory_Presser_Photo_Numberer::add_sequence_number_to_titles( $title,  $id = null )

On This Page


Source Source

File: includes/class-photo-numberer.php

	public function add_sequence_number_to_titles( $title, $id = null ) {
		// Don't double dip during REST API requests.
		if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
			return;
		}

		// What post?
		if ( empty( $id ) ) {
			return $title;
		}

		if ( ! is_admin() ) {
			return $title;
		}

		// Is this the Media Library upload.php?
		if ( ! function_exists( 'get_current_screen' ) ) {
			return $title;
		}
		$screen = get_current_screen();
		if ( empty( $screen->parent_file ) || 'upload.php' !== $screen->parent_file ) {
			// No.
			return $title;
		}

		if ( 'attachment' !== get_post_type( $id ) ) {
			// No.
			return $title;
		}

		$parent = get_post_parent( $id );
		if ( empty( $parent ) || INVP::POST_TYPE !== $parent->post_type ) {
			// No.
			return $title;
		}

		// Get the photo count.
		return sprintf(
			'%s (%s %s %s %s)',
			$title,
			__( 'Photo', 'inventory-presser' ),
			INVP::get_meta( 'photo_number', $id ),
			__( 'of', 'inventory-presser' ),
			invp_get_the_photo_count( $parent->ID )
		);
	}