Automattic\WooCommerce\Internal\ProductFeed\Storage

JsonFileFeed::startpublicWC 1.0

Start the feed.

Метод класса: JsonFileFeed{}

Хуки из метода

Возвращает

null. Ничего (null).

Использование

$JsonFileFeed = new JsonFileFeed();
$JsonFileFeed->start(): void;

Код JsonFileFeed::start() WC 10.5.2

public function start(): void {
	/**
	 * Allows the current time to be overridden before a feed is stored.
	 *
	 * @param int           $time The current time.
	 * @param FeedInterface $feed The feed instance.
	 * @return int The current time.
	 * @since 10.5.0
	 */
	$current_time    = apply_filters( 'woocommerce_product_feed_time', time(), $this );
	$hash_data       = $this->base_name . gmdate( 'r', $current_time );
	$this->file_name = sprintf(
		'%s-%s-%s.json',
		$this->base_name,
		gmdate( 'Y-m-d', $current_time ),
		wp_hash( $hash_data )
	);

	// Start by trying to use a temp directory to generate the feed.
	$this->file_path   = get_temp_dir() . DIRECTORY_SEPARATOR . $this->file_name;
	$this->file_handle = fopen( $this->file_path, 'w' );
	if ( false === $this->file_handle ) {
		// Fall back to immediately using the upload directory for generation.
		$upload_dir        = $this->get_upload_dir();
		$this->file_path   = $upload_dir['path'] . $this->file_name;
		$this->file_handle = fopen( $this->file_path, 'w' );
	} else {
		$this->is_temp_filepath = true;
	}

	if ( false === $this->file_handle ) {
		throw new Exception(
			esc_html(
				sprintf(
					/* translators: %s: directory path */
					__( 'Unable to open feed file for writing: %s', 'woocommerce' ),
					$this->file_path
				)
			)
		);
	}

	// Open the array.
	fwrite( $this->file_handle, '[' );
}