Featured_Image::sync_handle( array|null $data_source = null )

Process the download of the image from EA, attempt to locate the image first on the media library if a copy of the same ID image is present if any uses that instead of download one from the EA server.


Parameters

$data_source

(array|null) (Optional)

Default value: null


Top ↑

Return

(bool|int|mixed|null)


Top ↑

Source

File: src/Tribe/Import/Featured_Image.php

	public function sync_handle( array $data_source = null ) {
		$data_source = isset( $data_source ) ? $data_source : $_POST;

		if ( empty( $data_source['post_id'] ) || empty( $data_source['image_id'] ) ) {
			return false;
		}

		$licenses    = [];
		$ebt_license = tribe( 'eventbrite.pue' )->pue_instance->get_key();
		if ( ! empty( $ebt_license ) ) {
			$licenses['tribe-eventbrite'] = $ebt_license;
		}

		$image_url   = tribe( 'events-aggregator.service' )->build_url(
			"image/{$data_source['image_id']}",
			[
				'licenses' => $licenses,
				'origin'   => 'eventbrite',
			]
		);

		$attachment_id = $this->find_locally( $data_source['image_id'] );

		if ( $attachment_id ) {
			// Make sure the meta key is updated if found locally.
			update_post_meta( $attachment_id, '_tribe_importer_original_url', $image_url );
		} else {
			$attachment_id = tribe_upload_image( $image_url );
		}

		if ( ! $attachment_id ) {
			do_action(
				'tribe_log',
				'debug',
				__METHOD__,
				[
					'message' => 'Unable to find the image on the media library or to download the image.',
					'data'    => $data_source,
				]
			);

			return false;
		}

		$this->attach( $attachment_id, $data_source['post_id'] );

		return $attachment_id;
	}

Top ↑

Changelog

Changelog
Version Description
4.6.5 Introduced.