PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.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 2 years ago AnalyticsEventDto.php 2 years ago AnalyticsSender.php 2 years ago WithAnalyticsAPI.php 4 years ago WithAnalyticsSiteInfo.php 2 years ago
WithAnalyticsSiteInfo.php
218 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
59 $systemInfo = [
60 'is_staging_site' => (int)WPStaging::make(SiteInfo::class)->isStagingSite(),
61
62 'db_copy_query_limit' => !empty($wpstgSettings['queryLimit']) ? $wpstgSettings['queryLimit'] : null,
63 'db_sr_limit' => !empty($wpstgSettings['querySRLimit']) ? $wpstgSettings['querySRLimit'] : null,
64 'file_copy_limit' => !empty($wpstgSettings['fileLimit']) ? $wpstgSettings['fileLimit'] : null,
65 'cpu_priority' => !empty($wpstgSettings['cpuLoad']) ? $wpstgSettings['cpuLoad'] : null,
66 'file_copy_batch_size' => !empty($wpstgSettings['batchSize']) ? $wpstgSettings['batchSize'] : null,
67 'max_file_size' => !empty($wpstgSettings['maxFileSize']) ? $wpstgSettings['maxFileSize'] : null,
68 'optimizer' => !empty($wpstgSettings['optimizer']) ? $wpstgSettings['optimizer'] : null,
69
70 // WP STAGING Settings that are null by default, if they are not present, they are evaluated as FALSY/EMPTY:
71 'keep_permalinks' => !empty($wpstgSettings['keepPermalinks']) ? $wpstgSettings['keepPermalinks'] : false,
72 'disable_admin_login' => !empty($wpstgSettings['disableAdminLogin']) ? $wpstgSettings['disableAdminLogin'] : false,
73 //'delay_between_requests' => !empty($wpstgSettings['delayRequests']) ? $wpstgSettings['delayRequests'] : 0,
74 'delay_between_requests' => 0,
75 'debug_mode' => !empty($wpstgSettings['debugMode']) ? $wpstgSettings['debugMode'] : false,
76 'remove_data_on_uninstall' => !empty($wpstgSettings['unInstallOnDelete']) ? $wpstgSettings['unInstallOnDelete'] : false,
77 'check_directory_size' => !empty($wpstgSettings['checkDirectorySize']) ? $wpstgSettings['checkDirectorySize'] : false,
78 'access_permission' => !empty($wpstgSettings['userRoles']) ? $wpstgSettings['userRoles'] : [],
79 'users_with_staging_access' => !empty($wpstgSettings['usersWithStagingAccess']) ? $wpstgSettings['usersWithStagingAccess'] : '',
80 'enable_compression' => !empty($wpstgSettings['enableCompression']) ? $wpstgSettings['enableCompression'] : false,
81
82 'php_version' => phpversion(),
83 'blog_id' => get_current_blog_id(),
84 'network_id' => WPStaging::make(WpAdapter::class)->getCurrentNetworkId(),
85 'single_or_multi' => is_multisite() ? 'multi' : 'single',
86 'wpstaging_free_or_pro' => WPStaging::isPro() ? 'pro' : 'free',
87 'wpstaging_version' => WPStaging::getVersion(),
88 'operating_system_family' => stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : 'UNIX',
89 'operating_system_family_raw' => PHP_OS,
90 'active_theme' => get_option('stylesheet') ?: 'UNDEFINED',
91 'wordpress_version' => $wp_version,
92 'wpdb_version' => $wp_db_version,
93 'db_collate' => $wpdb->collate,
94 'db_charset' => $wpdb->charset,
95 'sql_server_version_number' => $mySqlVersionNumber,
96 'sql_server_version_engine' => $engine,
97 'sql_server_version_engine_raw' => $mysqlInfo,
98 'site_active_plugins' => isset($plugins['siteActive']) ? $plugins['siteActive'] : '',
99 'mu_plugins' => isset($plugins['muPlugins']) ? $plugins['muPlugins'] : '',
100 'network_active_plugins' => isset($plugins['networkActive']) ? $plugins['networkActive'] : '',
101 'php_extensions' => $this->getPhpExtensions(),
102 ];
103
104 return $systemInfo;
105 }
106
107 protected function getActivePlugins()
108 {
109 if (!function_exists('get_plugin_data')) {
110 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
111 }
112
113 $plugins = [
114 'siteActive' => [],
115 'muPlugins' => [],
116 'networkActive' => [],
117 ];
118
119 $callback = function () {
120 return [];
121 };
122
123 $undefinedString = 'UNDEFINED';
124
125 $wpPluginDir = wp_normalize_path(WP_PLUGIN_DIR);
126 $wpmuPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
127
128 // plugins
129 add_filter('pre_site_option_active_sitewide_plugins', $callback);
130
131 $plugins = $this->getPlugins();
132 foreach ($plugins as $activePlugin) {
133 $pluginFile = WP_PLUGIN_DIR . "/" . $activePlugin;
134 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
135 $name = trim($name, '/\\');
136
137 if (!file_exists($pluginFile)) {
138 $plugins['siteActive'][$name] = $undefinedString;
139 continue;
140 }
141
142 $pluginData = get_plugin_data($pluginFile);
143 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
144 $plugins['siteActive'][$name] = $version;
145 }
146
147 remove_filter('pre_site_option_active_sitewide_plugins', $callback);
148
149 // mu-plugins
150 foreach (get_mu_plugins() ?: [] as $activeMuPlugin => $pluginData) {
151 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
152 $name = str_replace($wpmuPluginDir, '', wp_normalize_path($activeMuPlugin));
153 $name = trim($name, '/\\');
154
155 $plugins['muPlugins'][$name] = $version;
156 }
157
158 // networkwide plugins
159 if (function_exists('wp_get_active_network_plugins')) {
160 foreach (wp_get_active_network_plugins() ?: [] as $activePlugin) {
161 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
162 $name = trim($name, '/\\');
163
164 $pluginFile = WP_PLUGIN_DIR . "/" . $activePlugin;
165 if (!file_exists($pluginFile)) {
166 $plugins['networkActive'][$name] = $undefinedString;
167 continue;
168 }
169
170 $pluginData = get_plugin_data($activePlugin);
171 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
172
173 $plugins['networkActive'][$name] = $version;
174 }
175 }
176
177 return $plugins;
178 }
179
180 protected function getPhpExtensions()
181 {
182 // Early bail: Not callable
183 if (!is_callable('get_loaded_extensions')) {
184 return [];
185 }
186
187 $phpExtensions = @get_loaded_extensions();
188
189 // Early bail: Unexpected value
190 if (!is_array($phpExtensions)) {
191 return [];
192 }
193
194 return $phpExtensions;
195 }
196
197 /**
198 * 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
199 * wp_get_active_and_valid_plugins() does not deliver a result because our mu-plugin wp-staging-optimizer.php filters the active plugins.
200 * @return array
201 */
202 protected function getPlugins()
203 {
204 global $wpdb;
205
206 $optionTable = esc_sql($wpdb->prefix) . "options";
207 $result = $wpdb->get_var("SHOW TABLES LIKE '$optionTable'");
208 if ($result != $optionTable) {
209 return [];
210 }
211
212 $sql = "SELECT option_value FROM " . esc_sql($wpdb->prefix) . "options WHERE option_name = 'active_plugins'";
213 $result = $wpdb->get_results($sql, ARRAY_A);
214 $result = isset($result[0]['option_value']) ? unserialize($result[0]['option_value']) : [];
215 return (array)$result;
216 }
217 }
218