PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.9.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.9.2
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 weeks ago AnalyticsCleanup.php 4 years ago AnalyticsConsent.php 1 week ago AnalyticsEventDto.php 2 weeks ago AnalyticsEventWithTimeDto.php 9 months ago AnalyticsGenericEventHandler.php 2 months ago AnalyticsSender.php 9 months ago WithAnalyticsAPI.php 9 months ago WithAnalyticsSiteInfo.php 4 months ago
WithAnalyticsSiteInfo.php
220 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' => 0,
76 'debug_mode' => !empty($wpstgSettings['debugMode']) ? $wpstgSettings['debugMode'] : false,
77 'remove_data_on_uninstall' => !empty($wpstgSettings['unInstallOnDelete']) ? $wpstgSettings['unInstallOnDelete'] : 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 'php_architecture' => $siteInfo->getPhpArchitecture(),
84 'blog_id' => get_current_blog_id(),
85 'network_id' => WPStaging::make(WpAdapter::class)->getCurrentNetworkId(),
86 'single_or_multi' => is_multisite() ? 'multi' : 'single',
87 'wpstaging_free_or_pro' => WPStaging::isPro() ? 'pro' : 'free',
88 'wpstaging_version' => WPStaging::getVersion(),
89 'operating_system_family' => stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : 'UNIX',
90 'operating_system_family_raw' => PHP_OS,
91 'operating_system_architecture' => $siteInfo->getOsArchitecture(),
92 'active_theme' => get_option('stylesheet') ?: 'UNDEFINED',
93 'wordpress_version' => $wp_version,
94 'wpdb_version' => $wp_db_version,
95 'db_collate' => $wpdb->collate,
96 'db_charset' => $wpdb->charset,
97 'sql_server_version_number' => $mySqlVersionNumber,
98 'sql_server_version_engine' => $engine,
99 'sql_server_version_engine_raw' => $mysqlInfo,
100 'site_active_plugins' => isset($plugins['siteActive']) ? $plugins['siteActive'] : '',
101 'mu_plugins' => isset($plugins['muPlugins']) ? $plugins['muPlugins'] : '',
102 'network_active_plugins' => isset($plugins['networkActive']) ? $plugins['networkActive'] : '',
103 'php_extensions' => $this->getPhpExtensions(),
104 ];
105
106 return $systemInfo;
107 }
108
109 protected function getActivePlugins()
110 {
111 if (!function_exists('get_plugin_data')) {
112 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
113 }
114
115 $plugins = [
116 'siteActive' => [],
117 'muPlugins' => [],
118 'networkActive' => [],
119 ];
120
121 $callback = function () {
122 return [];
123 };
124
125 $undefinedString = 'UNDEFINED';
126
127 $wpPluginDir = wp_normalize_path(WP_PLUGIN_DIR);
128 $wpmuPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
129
130 // plugins
131 add_filter('pre_site_option_active_sitewide_plugins', $callback);
132
133 $plugins = $this->getPlugins();
134 foreach ($plugins as $activePlugin) {
135 $pluginFile = WP_PLUGIN_DIR . "/" . $activePlugin;
136 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
137 $name = trim($name, '/\\');
138
139 if (!file_exists($pluginFile)) {
140 $plugins['siteActive'][$name] = $undefinedString;
141 continue;
142 }
143
144 $pluginData = get_plugin_data($pluginFile);
145 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
146 $plugins['siteActive'][$name] = $version;
147 }
148
149 remove_filter('pre_site_option_active_sitewide_plugins', $callback);
150
151 // mu-plugins
152 foreach (get_mu_plugins() ?: [] as $activeMuPlugin => $pluginData) {
153 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
154 $name = str_replace($wpmuPluginDir, '', wp_normalize_path($activeMuPlugin));
155 $name = trim($name, '/\\');
156
157 $plugins['muPlugins'][$name] = $version;
158 }
159
160 // networkwide plugins
161 if (function_exists('wp_get_active_network_plugins')) {
162 foreach (wp_get_active_network_plugins() ?: [] as $activePlugin) {
163 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
164 $name = trim($name, '/\\');
165
166 $pluginFile = WP_PLUGIN_DIR . "/" . $activePlugin;
167 if (!file_exists($pluginFile)) {
168 $plugins['networkActive'][$name] = $undefinedString;
169 continue;
170 }
171
172 $pluginData = get_plugin_data($activePlugin);
173 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : $undefinedString;
174
175 $plugins['networkActive'][$name] = $version;
176 }
177 }
178
179 return $plugins;
180 }
181
182 protected function getPhpExtensions()
183 {
184 // Early bail: Not callable
185 if (!is_callable('get_loaded_extensions')) {
186 return [];
187 }
188
189 $phpExtensions = @get_loaded_extensions();
190
191 // Early bail: Unexpected value
192 if (!is_array($phpExtensions)) {
193 return [];
194 }
195
196 return $phpExtensions;
197 }
198
199 /**
200 * 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
201 * wp_get_active_and_valid_plugins() does not deliver a result because our mu-plugin wp-staging-optimizer.php filters the active plugins.
202 * @return array
203 */
204 protected function getPlugins()
205 {
206 global $wpdb;
207
208 $optionTable = esc_sql($wpdb->prefix) . "options";
209 $result = $wpdb->get_var("SHOW TABLES LIKE '$optionTable'");
210 if ($result != $optionTable) {
211 return [];
212 }
213
214 $sql = "SELECT option_value FROM " . esc_sql($wpdb->prefix) . "options WHERE option_name = 'active_plugins'";
215 $result = $wpdb->get_results($sql, ARRAY_A);
216 $result = isset($result[0]['option_value']) ? unserialize($result[0]['option_value']) : [];
217 return (array)$result;
218 }
219 }
220