Automattic\WooCommerce\Internal\ProductFeed\Storage

JsonFileFeed::get_upload_dirprivateWC 1.0

Get the upload directory for the feed.

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

Хуков нет.

Возвращает

Массив. The upload directory for the feed. Both fields end with the right trailing slash.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_upload_dir(): array;

Код JsonFileFeed::get_upload_dir() WC 10.5.2

private function get_upload_dir(): array {
	// Only generate everything once.
	static $prepared;
	if ( isset( $prepared ) ) {
		return $prepared;
	}

	$upload_dir     = wp_upload_dir( null, true );
	$directory_path = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . self::UPLOAD_DIR . DIRECTORY_SEPARATOR;

	// Try to create the directory if it does not exist.
	if ( ! is_dir( $directory_path ) ) {
		FilesystemUtil::mkdir_p_not_indexable( $directory_path );
	}

	// `mkdir_p_not_indexable()` returns `void`, we have to check again.
	if ( ! is_dir( $directory_path ) ) {
		throw new Exception(
			esc_html(
				sprintf(
					/* translators: %s: directory path */
					__( 'Unable to create feed directory: %s', 'woocommerce' ),
					$directory_path
				)
			)
		);
	}

	$directory_url = $upload_dir['baseurl'] . '/' . self::UPLOAD_DIR . '/';

	// Follow the format, returned by `wp_upload_dir()`.
	$prepared = array(
		'path' => $directory_path,
		'url'  => $directory_url,
	);
	return $prepared;
}