PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.9.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.9.2
4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / Service / BackupsDirectoryResolver.php
wp-staging / Backup / Service Last commit date
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