Automattic\WooCommerce\Internal\ProductFeed\Storage

JsonFileFeed::get_upload_dir │ private │ WC 1.0

Get the upload directory for the feed.

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

Хуков нет.

Возвращает

array. 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 11.2.2

private function get_upload_dir(): array {
	// Resolve once per feed instance.
	if ( null !== $this->prepared_upload_dir ) {
		return $this->prepared_upload_dir;
	}

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

	// Create the directory if it does not exist, allowing file access so the generated feed
	// files can be served by URL while directory listing stays disabled. If the directory
	// already exists, refresh its .htaccess in place so installs created before file access
	// was enabled also serve feeds correctly.
	if ( ! is_dir( $directory_path ) ) {
		FilesystemUtil::mkdir_p_not_indexable( $directory_path, true );
	} else {
		$this->ensure_feed_dir_file_access( $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 = self::build_directory_url( $upload_dir['baseurl'] );

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