Automattic\WooCommerce\Internal\ProductFeed\Storage
JsonFileFeed::get_upload_dir
Get the upload directory for the feed.
Method of the class: JsonFileFeed{}
No Hooks.
Returns
array. The upload directory for the feed. Both fields end with the right trailing slash.
Usage
// private - for code of main (parent) class only $result = $this->get_upload_dir(): array;
JsonFileFeed::get_upload_dir() JsonFileFeed::get upload dir code WC 11.1.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 = $upload_dir['baseurl'] . '/' . self::UPLOAD_DIR . '/';
// Follow the format, returned by `wp_upload_dir()`.
$this->prepared_upload_dir = array(
'path' => $directory_path,
'url' => $directory_url,
);
return $this->prepared_upload_dir;
}