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 10.8.1
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;
}