Inventory_Presser_Plugin::change_attachment_urls( string $url, int $post_id = null )

change_attachment_urls


Description Description

Adds a querystring to vehicle attachment photo URLs to fight caching.


Top ↑

Parameters Parameters

$url

(string) (Required)

$post_id

(int) (Optional)

Default value: null


Top ↑

Return Return

(string) The changed URL


Top ↑

Source Source

File: inventory-presser.php

	public function change_attachment_urls( $url, $post_id = null )
	{
		if( empty( $post_id ) )
		{
			$post_id = attachment_url_to_postid( $url );
		}

		if( INVP::POST_TYPE != get_post_type( wp_get_post_parent_id( $post_id ) ) )
		{
			return $url;
		}

		//This could be controversial
		switch( substr( $url, -4 ) )
		{
			case 'jpeg':
			case '.jpg':
			case '.png':
				break;
			default:
				return $url;
		}

		//Add a querystring that contains this photo's hash 
		$hash = get_post_meta( $post_id, apply_filters( 'invp_prefix_meta_key', 'hash' ), true );
		if( empty( $hash ) )
		{
			return $url;
		}

		return $url . '?' . $hash;
	}