| 1 |
<?php |
| 2 |
namespace Averta\WordPress\File; |
| 3 |
|
| 4 |
|
| 5 |
class UploadsDirectory |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Array of information about the upload directory. |
| 9 |
* |
| 10 |
* @var array |
| 11 |
*/ |
| 12 |
private $uploads_directory; |
| 13 |
|
| 14 |
/** |
| 15 |
* UploadsDirectory constructor. |
| 16 |
* |
| 17 |
* @param string|null $time (Optional) Time formatted in 'yyyy/mm'. Default value: null |
| 18 |
* @param bool $create_dir (Optional) Whether to check and create the uploads directory. Default true for backward compatibility.Default value: true |
| 19 |
* @param bool $refresh_cache (Optional) Whether to refresh the cache. Default value: false |
| 20 |
*/ |
| 21 |
public function __construct( $time = null, $create_dir = true, $refresh_cache = false ) |
| 22 |
{ |
| 23 |
$this->uploads_directory = wp_upload_dir( $time, $create_dir, $refresh_cache ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Base directory and sub directory or full path to upload directory. |
| 28 |
* @example C:\path\to\wordpress\wp-content\uploads\2010\05 |
| 29 |
* |
| 30 |
* @return mixed |
| 31 |
*/ |
| 32 |
public function getPath(){ |
| 33 |
return $this->uploads_directory['path']; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Base url and sub directory or absolute URL to upload directory. |
| 38 |
* @example http://example.com/wp-content/uploads/2010/05 |
| 39 |
* |
| 40 |
* @return mixed |
| 41 |
*/ |
| 42 |
public function getUrl(){ |
| 43 |
return $this->uploads_directory['url']; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Path without subdir. |
| 48 |
* @example C:\path\to\wordpress\wp-content\uploads |
| 49 |
* |
| 50 |
* @return mixed |
| 51 |
*/ |
| 52 |
public function getBaseDirectory(){ |
| 53 |
return $this->uploads_directory['basedir']; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* URL path without subdir. |
| 58 |
* @example http://example.com/wp-content/uploads |
| 59 |
* |
| 60 |
* @return mixed |
| 61 |
*/ |
| 62 |
public function getBaseUrl(){ |
| 63 |
return $this->uploads_directory['baseurl']; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Sub directory if uploads use year/month folders option is on. |
| 68 |
* @example /2010/05 |
| 69 |
* |
| 70 |
* @return mixed |
| 71 |
*/ |
| 72 |
public function getSubDirectory(){ |
| 73 |
return $this->uploads_directory['subdir']; |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|