PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 3.0.2
WP STAGING – WordPress Backups, Restore, Migration & Clone v3.0.2
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 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 3 years ago AnalyticsEventDto.php 3 years ago AnalyticsSender.php 4 years ago WithAnalyticsAPI.php 4 years ago WithAnalyticsSiteInfo.php 3 years ago
WithAnalyticsSiteInfo.php
195 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
81 'php_version' => phpversion(),
82 'blog_id' => get_current_blog_id(),
83 'network_id' => WPStaging::make(WpAdapter::class)->getCurrentNetworkId(),
84 'single_or_multi' => is_multisite() ? 'multi' : 'single',
85 'wpstaging_free_or_pro' => WPStaging::isPro() ? 'pro' : 'free',
86 'wpstaging_version' => WPStaging::getVersion(),
87 'operating_system_family' => stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : 'UNIX',
88 'operating_system_family_raw' => PHP_OS,
89 'active_theme' => get_option('stylesheet') ?: 'UNDEFINED',
90 'wordpress_version' => $wp_version,
91 'wpdb_version' => $wp_db_version,
92 'db_collate' => $wpdb->collate,
93 'db_charset' => $wpdb->charset,
94 'sql_server_version_number' => $mySqlVersionNumber,
95 'sql_server_version_engine' => $engine,
96 'sql_server_version_engine_raw' => $mysqlInfo,
97 'site_active_plugins' => isset($plugins['siteActive']) ? $plugins['siteActive'] : '',
98 'mu_plugins' => isset($plugins['muPlugins']) ? $plugins['muPlugins'] : '',
99 'network_active_plugins' => isset($plugins['networkActive']) ? $plugins['networkActive'] : '',
100 'php_extensions' => $this->getPhpExtensions(),
101 ];
102
103 return $systemInfo;
104 }
105
106 protected function getActivePlugins()
107 {
108 if (!function_exists('get_plugin_data')) {
109 include_once(ABSPATH . 'wp-admin/includes/plugin.php');
110 }
111
112 $plugins = [
113 'siteActive' => [],
114 'muPlugins' => [],
115 'networkActive' => [],
116 ];
117
118 $callback = function () {
119 return [];
120 };
121
122 $wpPluginDir = wp_normalize_path(WP_PLUGIN_DIR);
123 $wpmuPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
124
125 // plugins
126 add_filter('pre_site_option_active_sitewide_plugins', $callback);
127
128 $plugins = $this->getPlugins();
129 foreach ($plugins as $activePlugin) {
130 $pluginData = get_plugin_data(WP_PLUGIN_DIR . "/" . $activePlugin);
131 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : 'UNDEFINED';
132 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
133 $name = trim($name, '/\\');
134
135 $plugins['siteActive'][$name] = $version;
136 }
137 remove_filter('pre_site_option_active_sitewide_plugins', $callback);
138
139 // mu-plugins
140 foreach (get_mu_plugins() ?: [] as $activeMuPlugin => $pluginData) {
141 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : 'UNDEFINED';
142 $name = str_replace($wpmuPluginDir, '', wp_normalize_path($activeMuPlugin));
143 $name = trim($name, '/\\');
144
145 $plugins['muPlugins'][$name] = $version;
146 }
147
148 // networkwide plugins
149 if (function_exists('wp_get_active_network_plugins')) {
150 foreach (wp_get_active_network_plugins() ?: [] as $activePlugin) {
151 $pluginData = get_plugin_data($activePlugin);
152 $version = array_key_exists('Version', $pluginData) ? $pluginData['Version'] : 'UNDEFINED';
153 $name = str_replace($wpPluginDir, '', wp_normalize_path($activePlugin));
154 $name = trim($name, '/\\');
155
156 $plugins['networkActive'][$name] = $version;
157 }
158 }
159
160 return $plugins;
161 }
162
163 protected function getPhpExtensions()
164 {
165 // Early bail: Not callable
166 if (!is_callable('get_loaded_extensions')) {
167 return [];
168 }
169
170 $phpExtensions = @get_loaded_extensions();
171
172 // Early bail: Unexpected value
173 if (!is_array($phpExtensions)) {
174 return [];
175 }
176
177 return $phpExtensions;
178 }
179
180 /**
181 * 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
182 * wp_get_active_and_valid_plugins() does not deliver a result because our mu-plugin wp-staging-optimizer.php filters the active plugins.
183 * @return array
184 */
185 protected function getPlugins()
186 {
187 global $wpdb;
188
189 $sql = "SELECT option_value FROM " . esc_sql($wpdb->prefix) . "options WHERE option_name = 'active_plugins'";
190 $result = $wpdb->get_results($sql, ARRAY_A);
191 $result = isset($result[0]['option_value']) ? unserialize($result[0]['option_value']) : [];
192 return (array)$result;
193 }
194 }
195