PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.1
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.1
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 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 / ZlibCompressor.php
wp-staging / Backup / Service Last commit date
Compression 1 week ago Database 1 week ago DirectoryExplorer 1 week ago AbstractBackgroundBackupRequest.php 1 week ago AbstractBackupsFinder.php 1 week ago AbstractExtractor.php 1 week ago AbstractServiceProvider.php 1 week ago Archiver.php 1 week ago BackupAssets.php 1 week ago BackupContent.php 1 week ago BackupMetadataEditor.php 1 week ago BackupMetadataReader.php 1 week ago BackupSigner.php 1 week ago BackupsDirectoryResolver.php 1 week ago BackupsFinder.php 1 week ago BeforeUpdateBackupRequest.php 1 week ago BeforeUpdateBackupsService.php 1 week ago Extractor.php 1 week ago FileBackupService.php 1 week ago FileBackupServiceProvider.php 1 week ago ServiceInterface.php 1 week ago TmpBackupCleaner.php 1 week ago UpdateProtectionHealth.php 1 week ago UpdateProtectionSettings.php 1 week ago ZlibCompressor.php 1 week ago
ZlibCompressor.php
83 lines
1 <?php
2
3 namespace WPStaging\Backup\Service;
4
5 use WPStaging\Backup\Service\Compression\CompressionInterface;
6 use WPStaging\Core\WPStaging;
7 use WPStaging\Framework\Facades\Hooks;
8 use WPStaging\Framework\Job\Dto\JobDataDto;
9
10 class ZlibCompressor
11 {
12
13 const FILTER_ZLIB_COMPRESSION_ENABLED = 'wpstg.backup.compression.zlib.enabled';
14
15
16 const HOOK_CAN_USE_COMPRESSION = 'wpstg.can_use_compression';
17
18
19 protected $service;
20
21 public function __construct(CompressionInterface $service)
22 {
23 $this->service = $service;
24 }
25
26
27
28
29 public function supportsCompression(): bool
30 {
31 return function_exists('gzcompress') && function_exists('gzuncompress');
32 }
33
34
35
36
37
38 public function canUseCompression(): bool
39 {
40 static $canUseCompression = null;
41
42 if (!is_null($canUseCompression)) {
43 return $canUseCompression;
44 }
45
46
47 if (WPStaging::isBasic()) {
48 return false;
49 }
50
51 $canUseCompression = $this->supportsCompression() && Hooks::callInternalHook(self::HOOK_CAN_USE_COMPRESSION, [], false);
52
53 return $canUseCompression;
54 }
55
56
57
58
59 public function isCompressionEnabled(): bool
60 {
61
62 if (Hooks::applyFilters(JobDataDto::FILTER_IS_MULTIPART_BACKUP, false)) {
63 return false;
64 }
65
66 static $isEnabled = null;
67
68 if (is_null($isEnabled)) {
69 $settings = (object)get_option('wpstg_settings', []);
70 $isEnabled = $settings->enableCompression ?? false;
71 }
72
73 $canUseCompression = $this->canUseCompression();
74
75 return Hooks::applyFilters(self::FILTER_ZLIB_COMPRESSION_ENABLED, $isEnabled && $canUseCompression);
76 }
77
78 public function getService(): CompressionInterface
79 {
80 return $this->service;
81 }
82 }
83