PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.3.3
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.3.3
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 3 years ago AnalyticsCleanup.php 4 years ago AnalyticsConsent.php 2 years ago AnalyticsEventDto.php 3 years ago AnalyticsSender.php 2 years ago WithAnalyticsAPI.php 4 years ago WithAnalyticsSiteInfo.php 2 years ago
WithAnalyticsSiteInfo.php
197 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 $wpPluginDir = wp_normalize_path(WP_PLUGIN_DIR);
124 $wpmuPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
125
126 // plugins
127 add_filter('pre_site_option_active_sitewide_plugins', $callback);
128
129 $plugins = $this->getPlugins();
130 foreach ($plugins as $activePlugin) {
131 $pluginData = get_plugin_data(WP_PLUGIN_DIR . "/" . $activePlugin);
132 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : 'UNDEFINED';
133 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
134 $name = trim($name, '/\\');
135
136 $plugins['siteActive'][$name] = $version;
137 }
138
139 remove_filter('pre_site_option_active_sitewide_plugins', $callback);
140
141 // mu-plugins
142 foreach (get_mu_plugins() ?: [] as $activeMuPlugin => $pluginData) {
143 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : 'UNDEFINED';
144 $name = str_replace($wpmuPluginDir, '', wp_normalize_path($activeMuPlugin));
145 $name = trim($name, '/\\');
146
147 $plugins['muPlugins'][$name] = $version;
148 }
149
150 // networkwide plugins
151 if (function_exists('wp_get_active_network_plugins')) {
152 foreach (wp_get_active_network_plugins() ?: [] as $activePlugin) {
153 $pluginData = get_plugin_data($activePlugin);
154 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : 'UNDEFINED';
155 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
156 $name = trim($name, '/\\');
157
158 $plugins['networkActive'][$name] = $version;
159 }
160 }
161
162 return $plugins;
163 }
164
165 protected function getPhpExtensions()
166 {
167 // Early bail: Not callable
168 if (!is_callable('get_loaded_extensions')) {
169 return [];
170 }
171
172 $phpExtensions = @get_loaded_extensions();
173
174 // Early bail: Unexpected value
175 if (!is_array($phpExtensions)) {
176 return [];
177 }
178
179 return $phpExtensions;
180 }
181
182 /**
183 * 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
184 * wp_get_active_and_valid_plugins() does not deliver a result because our mu-plugin wp-staging-optimizer.php filters the active plugins.
185 * @return array
186 */
187 protected function getPlugins()
188 {
189 global $wpdb;
190
191 $sql = "SELECT option_value FROM " . esc_sql($wpdb->prefix) . "options WHERE option_name = 'active_plugins'";
192 $result = $wpdb->get_results($sql, ARRAY_A);
193 $result = isset($result[0]['option_value']) ? unserialize($result[0]['option_value']) : [];
194 return (array)$result;
195 }
196 }
197