PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.0.0
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.0.0
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 / Analytics / WithAnalyticsSiteInfo.php
wp-staging / Framework / Analytics Last commit date
Actions 2 years ago AnalyticsCleanup.php 4 years ago AnalyticsConsent.php 1 year ago AnalyticsEventDto.php 2 years ago AnalyticsSender.php 1 year ago WithAnalyticsAPI.php 1 year ago WithAnalyticsSiteInfo.php 1 year ago
WithAnalyticsSiteInfo.php
222 lines
1 <?php
2
3 namespace WPStaging\Framework\Analytics;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Framework\Adapter\WpAdapter;
7 use WPStaging\Framework\SiteInfo;
8
9 trait WithAnalyticsSiteInfo
10 {
11 public function getAnalyticsSiteInfo()
12 {
13 global $wpdb, $wp_version, $wp_db_version;
14
15 /**
16 * @var string $wp_version
17 * @var int $wp_db_version
18 */
19 include ABSPATH . WPINC . '/version.php';
20
21 // eg: 10.4.19-MariaDB-1:10.4.19+maria~focal
22 $mysqlInfo = $wpdb->get_var('SELECT VERSION();');
23
24 preg_match('/^[0-9.]+/', $mysqlInfo, $mySqlVersionNumber);
25
26 if (!empty($mySqlVersionNumber)) {
27 $mySqlVersionNumber = array_shift($mySqlVersionNumber);
28 } else {
29 $mySqlVersionNumber = 'UNDEFINED';
30 }
31
32 // Normalized engine name, allows us to query them regardless of the raw format.
33 if (stripos($mysqlInfo, 'mysql')) {
34 $engine = 'MYSQL';
35 } elseif (stripos($mysqlInfo, 'mariadb')) {
36 $engine = 'MARIADB';
37 } elseif (stripos($mysqlInfo, 'azure')) {
38 $engine = 'AZURE';
39 } elseif (stripos($mysqlInfo, 'postgre')) {
40 $engine = 'POSTGRE';
41 } elseif (stripos(preg_replace('[^\w]', '', $mysqlInfo), 'microsoftsqlserver')) {
42 $engine = 'MICROSOFTSQLSERVER';
43 } elseif (stripos($mysqlInfo, 'percona')) {
44 $engine = 'PERCONA';
45 } elseif (stripos($mysqlInfo, 'oracle')) {
46 $engine = 'ORACLE';
47 } else {
48 $engine = 'UNDEFINED';
49 }
50
51 $wpstgSettings = get_option('wpstg_settings', []);
52
53 if (!is_array($wpstgSettings)) {
54 $wpstgSettings = [];
55 }
56
57 $plugins = $this->getActivePlugins();
58 /** @var SiteInfo */
59 $siteInfo = WPStaging::make(SiteInfo::class);
60
61 $systemInfo = [
62 'is_staging_site' => (int)$siteInfo->isStagingSite(),
63
64 'db_copy_query_limit' => !empty($wpstgSettings['queryLimit']) ? $wpstgSettings['queryLimit'] : null,
65 'db_sr_limit' => !empty($wpstgSettings['querySRLimit']) ? $wpstgSettings['querySRLimit'] : null,
66 'file_copy_limit' => !empty($wpstgSettings['fileLimit']) ? $wpstgSettings['fileLimit'] : null,
67 'cpu_priority' => !empty($wpstgSettings['cpuLoad']) ? $wpstgSettings['cpuLoad'] : null,
68 'file_copy_batch_size' => !empty($wpstgSettings['batchSize']) ? $wpstgSettings['batchSize'] : null,
69 'max_file_size' => !empty($wpstgSettings['maxFileSize']) ? $wpstgSettings['maxFileSize'] : null,
70 'optimizer' => !empty($wpstgSettings['optimizer']) ? $wpstgSettings['optimizer'] : null,
71
72 // WP STAGING Settings that are null by default, if they are not present, they are evaluated as FALSY/EMPTY:
73 'keep_permalinks' => !empty($wpstgSettings['keepPermalinks']) ? $wpstgSettings['keepPermalinks'] : false,
74 'disable_admin_login' => !empty($wpstgSettings['disableAdminLogin']) ? $wpstgSettings['disableAdminLogin'] : false,
75 //'delay_between_requests' => !empty($wpstgSettings['delayRequests']) ? $wpstgSettings['delayRequests'] : 0,
76 'delay_between_requests' => 0,
77 'debug_mode' => !empty($wpstgSettings['debugMode']) ? $wpstgSettings['debugMode'] : false,
78 'remove_data_on_uninstall' => !empty($wpstgSettings['unInstallOnDelete']) ? $wpstgSettings['unInstallOnDelete'] : false,
79 'check_directory_size' => !empty($wpstgSettings['checkDirectorySize']) ? $wpstgSettings['checkDirectorySize'] : false,
80 'access_permission' => !empty($wpstgSettings['userRoles']) ? $wpstgSettings['userRoles'] : [],
81 'users_with_staging_access' => !empty($wpstgSettings['usersWithStagingAccess']) ? $wpstgSettings['usersWithStagingAccess'] : '',
82 'enable_compression' => !empty($wpstgSettings['enableCompression']) ? $wpstgSettings['enableCompression'] : false,
83
84 'php_version' => phpversion(),
85 'php_architecture' => $siteInfo->getPhpArchitecture(),
86 'blog_id' => get_current_blog_id(),
87 'network_id' => WPStaging::make(WpAdapter::class)->getCurrentNetworkId(),
88 'single_or_multi' => is_multisite() ? 'multi' : 'single',
89 'wpstaging_free_or_pro' => WPStaging::isPro() ? 'pro' : 'free',
90 'wpstaging_version' => WPStaging::getVersion(),
91 'operating_system_family' => stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : 'UNIX',
92 'operating_system_family_raw' => PHP_OS,
93 'operating_system_architecture' => $siteInfo->getOsArchitecture(),
94 'active_theme' => get_option('stylesheet') ?: 'UNDEFINED',
95 'wordpress_version' => $wp_version,
96 'wpdb_version' => $wp_db_version,
97 'db_collate' => $wpdb->collate,
98 'db_charset' => $wpdb->charset,
99 'sql_server_version_number' => $mySqlVersionNumber,
100 'sql_server_version_engine' => $engine,
101 'sql_server_version_engine_raw' => $mysqlInfo,
102 'site_active_plugins' => isset($plugins['siteActive']) ? $plugins['siteActive'] : '',
103 'mu_plugins' => isset($plugins['muPlugins']) ? $plugins['muPlugins'] : '',
104 'network_active_plugins' => isset($plugins['networkActive']) ? $plugins['networkActive'] : '',
105 'php_extensions' => $this->getPhpExtensions(),
106 ];
107
108 return $systemInfo;
109 }
110
111 protected function getActivePlugins()
112 {
113 if (!function_exists('get_plugin_data')) {
114 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
115 }
116
117 $plugins = [
118 'siteActive' => [],
119 'muPlugins' => [],
120 'networkActive' => [],
121 ];
122
123 $callback = function () {
124 return [];
125 };
126
127 $undefinedString = 'UNDEFINED';
128
129 $wpPluginDir = wp_normalize_path(WP_PLUGIN_DIR);
130 $wpmuPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
131
132 // plugins
133 add_filter('pre_site_option_active_sitewide_plugins', $callback);
134
135 $plugins = $this->getPlugins();
136 foreach ($plugins as $activePlugin) {
137 $pluginFile = WP_PLUGIN_DIR . "/" . $activePlugin;
138 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
139 $name = trim($name, '/\\');
140
141 if (!file_exists($pluginFile)) {
142 $plugins['siteActive'][$name] = $undefinedString;
143 continue;
144 }
145
146 $pluginData = get_plugin_data($pluginFile);
147 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
148 $plugins['siteActive'][$name] = $version;
149 }
150
151 remove_filter('pre_site_option_active_sitewide_plugins', $callback);
152
153 // mu-plugins
154 foreach (get_mu_plugins() ?: [] as $activeMuPlugin => $pluginData) {
155 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
156 $name = str_replace($wpmuPluginDir, '', wp_normalize_path($activeMuPlugin));
157 $name = trim($name, '/\\');
158
159 $plugins['muPlugins'][$name] = $version;
160 }
161
162 // networkwide plugins
163 if (function_exists('wp_get_active_network_plugins')) {
164 foreach (wp_get_active_network_plugins() ?: [] as $activePlugin) {
165 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
166 $name = trim($name, '/\\');
167
168 $pluginFile = WP_PLUGIN_DIR . "/" . $activePlugin;
169 if (!file_exists($pluginFile)) {
170 $plugins['networkActive'][$name] = $undefinedString;
171 continue;
172 }
173
174 $pluginData = get_plugin_data($activePlugin);
175 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
176
177 $plugins['networkActive'][$name] = $version;
178 }
179 }
180
181 return $plugins;
182 }
183
184 protected function getPhpExtensions()
185 {
186 // Early bail: Not callable
187 if (!is_callable('get_loaded_extensions')) {
188 return [];
189 }
190
191 $phpExtensions = @get_loaded_extensions();
192
193 // Early bail: Unexpected value
194 if (!is_array($phpExtensions)) {
195 return [];
196 }
197
198 return $phpExtensions;
199 }
200
201 /**
202 * Use this special method to get the list of active plugins, instead of using a core method like wp_get_active_and_valid_plugins() because
203 * wp_get_active_and_valid_plugins() does not deliver a result because our mu-plugin wp-staging-optimizer.php filters the active plugins.
204 * @return array
205 */
206 protected function getPlugins()
207 {
208 global $wpdb;
209
210 $optionTable = esc_sql($wpdb->prefix) . "options";
211 $result = $wpdb->get_var("SHOW TABLES LIKE '$optionTable'");
212 if ($result != $optionTable) {
213 return [];
214 }
215
216 $sql = "SELECT option_value FROM " . esc_sql($wpdb->prefix) . "options WHERE option_name = 'active_plugins'";
217 $result = $wpdb->get_results($sql, ARRAY_A);
218 $result = isset($result[0]['option_value']) ? unserialize($result[0]['option_value']) : [];
219 return (array)$result;
220 }
221 }
222