PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.0.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.0.2
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 / Framework / Staging / CloneOptions.php
wp-staging / Framework / Staging Last commit date
CloneOptions.php 4 years ago FirstRun.php 3 years ago Sites.php 3 years ago
CloneOptions.php
116 lines
1 <?php
2
3 namespace WPStaging\Framework\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\Framework\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 */
21 const WPSTG_CLONE_SETTINGS_KEY = 'wpstg_clone_settings';
22
23 /**
24 * Get the value of the given option,
25 * If no option given return all settings
26 *
27 * @param string $option
28 *
29 * @return mixed
30 */
31 public function get($option = null)
32 {
33 // Early bail if not a staging site
34 if (!WPStaging::make(SiteInfo::class)->isStagingSite()) {
35 return null;
36 }
37
38 $settings = get_option(self::WPSTG_CLONE_SETTINGS_KEY, null);
39
40 // Return settings if no options given
41 if ($option === null) {
42 return $settings;
43 }
44
45 // Early Bail: if settings is null or if settings isn't object
46 if ($settings === null || !is_object($settings)) {
47 return null;
48 }
49
50 // Early bail if given option not exists
51 if (!property_exists($settings, $option)) {
52 return null;
53 }
54
55 return $settings->{$option};
56 }
57
58 /**
59 * Set the value of given option
60 *
61 * @param string $option
62 * @param mixed $value
63 *
64 * @return bool
65 */
66 public function set($option, $value)
67 {
68 // Early bail if not a staging site
69 if (!WPStaging::make(SiteInfo::class)->isStagingSite()) {
70 return false;
71 }
72
73 $settings = get_option(self::WPSTG_CLONE_SETTINGS_KEY, null);
74
75 // If settings is null or if settings isn't object make settings a object
76 if ($settings === null || !is_object($settings)) {
77 $settings = new stdClass();
78 }
79
80 $settings->{$option} = $value;
81
82 return update_option(self::WPSTG_CLONE_SETTINGS_KEY, $settings);
83 }
84
85 /**
86 * Delete the given option
87 *
88 * @param string $option
89 *
90 * @return bool
91 */
92 public function delete($option)
93 {
94 // Early bail if not a staging site
95 if (!WPStaging::make(SiteInfo::class)->isStagingSite()) {
96 return false;
97 }
98
99 $settings = get_option(self::WPSTG_CLONE_SETTINGS_KEY, null);
100
101 // Early Bail: if settings is null or if settings isn't object
102 if ($settings === null || !is_object($settings)) {
103 return false;
104 }
105
106 // Early bail if given option not exists
107 if (!property_exists($settings, $option)) {
108 return true;
109 }
110
111 unset($settings->{$option});
112
113 return update_option(self::WPSTG_CLONE_SETTINGS_KEY, $settings);
114 }
115 }
116