PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.3.0
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.3.0
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 / Staging / CloneOptions.php
wp-staging / Staging Last commit date
Ajax 11 months ago Dto 11 months ago Interfaces 11 months ago Jobs 11 months ago Service 11 months ago Tasks 10 months ago Traits 11 months ago CloneOptions.php 1 year ago FirstRun.php 10 months ago Sites.php 1 year ago StagingServiceProvider.php 11 months ago
CloneOptions.php
117 lines
1 <?php
2
3 namespace WPStaging\Staging;
4
5 use stdClass;
6 use WPStaging\Core\WPStaging;
7 use WPStaging\Framework\SiteInfo;
8
9 /**
10 * Class CloneOptions
11 *
12 * This is used to manage settings on the staging site
13 *
14 * @package WPStaging\Staging
15 */
16 class CloneOptions
17 {
18 /**
19 * The option_name that is stored in the database to check first run is executed or not
20 * @var string
21 */
22 const WPSTG_CLONE_SETTINGS_KEY = 'wpstg_clone_settings';
23
24 /**
25 * Get the value of the given option,
26 * If no option given return all settings
27 *
28 * @param string|null $option
29 *
30 * @return mixed
31 */
32 public function get($option = null, $default = null)
33 {
34 // Early bail if not a staging site
35 if (!WPStaging::make(SiteInfo::class)->isStagingSite()) {
36 return $default;
37 }
38
39 $settings = get_option(self::WPSTG_CLONE_SETTINGS_KEY, null);
40
41 // Return settings if no options given
42 if ($option === null) {
43 return $settings;
44 }
45
46 // Early Bail: if settings is null or if settings isn't object
47 if ($settings === null || !is_object($settings)) {
48 return $default;
49 }
50
51 // Early bail if given option not exists
52 if (!property_exists($settings, $option)) {
53 return $default;
54 }
55
56 return $settings->{$option};
57 }
58
59 /**
60 * Set the value of given option
61 *
62 * @param string $option
63 * @param mixed $value
64 *
65 * @return bool
66 */
67 public function set(string $option, $value): bool
68 {
69 // Early bail if not a staging site
70 if (!WPStaging::make(SiteInfo::class)->isStagingSite()) {
71 return false;
72 }
73
74 $settings = get_option(self::WPSTG_CLONE_SETTINGS_KEY, null);
75
76 // If settings is null or if settings isn't object make settings a object
77 if ($settings === null || !is_object($settings)) {
78 $settings = new stdClass();
79 }
80
81 $settings->{$option} = $value;
82
83 return update_option(self::WPSTG_CLONE_SETTINGS_KEY, $settings);
84 }
85
86 /**
87 * Delete the given option
88 *
89 * @param string $option
90 *
91 * @return bool
92 */
93 public function delete(string $option): bool
94 {
95 // Early bail if not a staging site
96 if (!WPStaging::make(SiteInfo::class)->isStagingSite()) {
97 return false;
98 }
99
100 $settings = get_option(self::WPSTG_CLONE_SETTINGS_KEY, null);
101
102 // Early Bail: if settings is null or if settings isn't object
103 if ($settings === null || !is_object($settings)) {
104 return false;
105 }
106
107 // Early bail if given option not exists
108 if (!property_exists($settings, $option)) {
109 return true;
110 }
111
112 unset($settings->{$option});
113
114 return update_option(self::WPSTG_CLONE_SETTINGS_KEY, $settings);
115 }
116 }
117