Compression
4 months ago
Database
2 weeks ago
AbstractBackupsFinder.php
1 year ago
AbstractExtractor.php
1 day ago
AbstractServiceProvider.php
2 years ago
Archiver.php
2 weeks ago
BackupAssets.php
1 month ago
BackupContent.php
1 year ago
BackupMetadataEditor.php
1 year ago
BackupMetadataReader.php
5 months ago
BackupSigner.php
7 months ago
BackupsDirectoryResolver.php
2 weeks ago
BackupsFinder.php
2 weeks ago
Extractor.php
2 weeks ago
FileBackupService.php
1 day ago
FileBackupServiceProvider.php
2 years ago
ServiceInterface.php
2 years ago
TmpBackupCleaner.php
2 weeks ago
ZlibCompressor.php
11 months ago
BackupsDirectoryResolver.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backup\Service; |
| 4 | |
| 5 | use WPStaging\Framework\Adapter\Directory; |
| 6 | use WPStaging\Framework\Facades\Hooks; |
| 7 | |
| 8 | /** |
| 9 | * Resolves the backup directory after applying backup directory filters |
| 10 | */ |
| 11 | class BackupsDirectoryResolver |
| 12 | { |
| 13 | /** |
| 14 | * Resolve the filtered backup directory from the WordPress uploads directory. |
| 15 | * |
| 16 | * @param string $uploadsDirectory Absolute path to WordPress uploads. |
| 17 | * @return string |
| 18 | */ |
| 19 | public function resolveFromUploadsDirectory(string $uploadsDirectory): string |
| 20 | { |
| 21 | $uploadsDirectory = trim(trailingslashit(wp_normalize_path($uploadsDirectory))); |
| 22 | $pluginUploadsDir = Hooks::applyFilters(Directory::FILTER_GET_UPLOAD_DIR, wp_normalize_path($uploadsDirectory . WPSTG_PLUGIN_DOMAIN)); |
| 23 | $pluginUploadsDir = Hooks::applyFilters(Directory::FILTER_PLUGIN_UPLOADS_DIRECTORY, $pluginUploadsDir); |
| 24 | |
| 25 | return $this->resolveFromPluginUploadsDirectory($pluginUploadsDir); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Resolve the filtered backup directory from the plugin uploads directory. |
| 30 | * |
| 31 | * @param string $pluginUploadsDirectory Absolute path to WP STAGING uploads. |
| 32 | * @return string |
| 33 | */ |
| 34 | public function resolveFromPluginUploadsDirectory(string $pluginUploadsDirectory): string |
| 35 | { |
| 36 | return $this->resolve(trailingslashit($pluginUploadsDirectory) . Archiver::BACKUP_DIR_NAME); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Resolve the filtered backup directory from the default backup directory. |
| 41 | * |
| 42 | * @param string $defaultBackupsDirectory The default path to the directory Backups will be read from and written to. |
| 43 | * @return string |
| 44 | */ |
| 45 | public function resolve(string $defaultBackupsDirectory): string |
| 46 | { |
| 47 | /** |
| 48 | * Allows filtering the path to the directory Backups will be written to and read from. |
| 49 | * |
| 50 | * Note: changing this directory while there are backups in the previous location will, in |
| 51 | * fact, hide those Backups from the plugin. The task of moving the Backups left in the previous |
| 52 | * location(s) is left to the user. |
| 53 | * |
| 54 | * By default it uses the folder ABSPATH/wp-content/uploads/wp-staging/backups |
| 55 | * You can overwrite the path with the filter wpstg.backup.directory. |
| 56 | * The filtered provided path needs to be an absolute path that is inside the WordPress root (ABSPATH) |
| 57 | * E.g. If ABSPATH: '/var/www/example.com' then filtered path can be '/var/www/example.com/backups'. It can not be '/var/www/backups' |
| 58 | * |
| 59 | * @param string $defaultBackupsDirectory The default path to the directory Backups will be read from and |
| 60 | * written to. |
| 61 | */ |
| 62 | $directory = Hooks::applyFilters(BackupsFinder::FILTER_BACKUP_DIRECTORY, $defaultBackupsDirectory); |
| 63 | |
| 64 | return trailingslashit(wp_normalize_path($directory)); |
| 65 | } |
| 66 | } |
| 67 |