PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.0.20
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.0.20
1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 All 174 releases
userswp / includes / class-status.php

class-status.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.0.20, at includes/class-status.php

1,130 lines 52.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UsersWP status functions
4 *
5 * All UsersWP status related functions can be found here.
6 *
7 * @since 1.0.20
8 */
9 class UsersWP_Status {
10
11 public function uwp_status_wrap_error_message($message, $class) {
12 ob_start();
13 ?>
14 <div class="notice inline notice-<?php echo $class; ?> notice-alt">
15 <p><?php echo $message; ?></p>
16 </div>
17 <?php
18 $html = ob_get_clean();
19 return $html;
20 }
21
22 /**
23 * Adds the status settings page menu as submenu.
24 *
25 * @since 1.0.20
26 * @package userswp
27 *
28 * @param callable $settings_page The function to be called to output the content for this page.
29 *
30 * @return void
31 */
32 public function uwp_add_admin_status_sub_menu($settings_page) {
33
34 add_submenu_page(
35 "userswp",
36 __('Status', 'userswp'),
37 __('Status', 'userswp'),
38 'manage_options',
39 'uwp_status',
40 $settings_page
41 );
42
43 }
44
45 public function uwp_status_main_tab_content() {
46 global $wpdb;
47 $environment = $this->uwp_get_environment_info();
48 $database = $this->uwp_get_database_info();
49 $active_plugins = $this->uwp_get_active_plugins();
50 $theme = $this->uwp_get_theme_info();
51 $security = $this->uwp_get_security_info();
52 $pages = $this->uwp_get_pages();
53 ?>
54 <style type="text/css">
55 table.uwp-status-table {
56 margin-bottom: 1em;
57 }
58 table.uwp-status-table th {
59 font-weight: 700;
60 padding: 9px;
61 }
62 table.uwp-status-table td,
63 table.uwp-status-table th {
64 font-size: 1.1em;
65 font-weight: 400;
66 }
67 table.uwp-status-table h2 {
68 font-size: 14px;
69 margin: 0;
70 }
71 table.uwp-status-table td:first-child {
72 width: 33%;
73 }
74 table.uwp-status-table td mark,
75 table.uwp-status-table th mark {
76 background: transparent none;
77 }
78 table.uwp-status-table td mark.yes,
79 table.uwp-status-table th mark.yes {
80 color: #7ad03a;
81 }
82 p.submit {
83 margin: .5em 0;
84 padding: 2px;
85 }
86 #debug-report {
87 display: none;
88 margin: 10px 0;
89 padding: 0;
90 position: relative;
91 }
92 #debug-report textarea {
93 font-family: monospace;
94 width: 100%;
95 margin: 0;
96 height: 300px;
97 padding: 20px;
98 border-radius: 0;
99 resize: none;
100 font-size: 12px;
101 line-height: 20px;
102 outline: 0;
103 }
104 </style>
105 <div class="notice">
106 <p><?php _e( 'Please copy and paste this information in your ticket when contacting support:', 'userswp' ); ?> </p>
107 <p class="submit"><a href="javascript:void" class="button-primary debug-report"><?php _e( 'Get system report', 'userswp' ); ?></a></p>
108 <div id="debug-report">
109 <textarea readonly="readonly"></textarea>
110 <p class="submit"><button id="copy-for-support" class="button-primary" href="javascript:void"><?php _e( 'Copy for Support', 'userswp' ); ?></button></p>
111 <p class="copy-error hidden"><?php _e( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'userswp' ); ?></p>
112 </div>
113 </div>
114 <table class="uwp-status-table widefat">
115 <thead>
116 <tr>
117 <th colspan="3" data-export-label="WordPress Environment"><h2><?php _e( 'WordPress Environment', 'userswp' ); ?></h2></th>
118 </tr>
119 </thead>
120 <tbody>
121 <tr>
122 <td data-export-label="Home URL"><?php _e( 'Home URL', 'userswp' ); ?>:</td>
123 <td><?php echo esc_html( $environment['home_url'] ) ?></td>
124 </tr>
125 <tr>
126 <td data-export-label="Site URL"><?php _e( 'Site URL', 'userswp' ); ?>:</td>
127 <td><?php echo esc_html( $environment['site_url'] ) ?></td>
128 </tr>
129 <tr>
130 <td data-export-label="UWP Version"><?php _e( 'UWP version', 'userswp' ); ?>:</td>
131 <td><?php echo esc_html( $environment['version'] ) ?></td>
132 </tr>
133 <tr>
134 <td data-export-label="WP Version"><?php _e( 'WP version', 'userswp' ); ?>:</td>
135 <td><?php echo esc_html( $environment['wp_version'] ) ?></td>
136 </tr>
137 <tr>
138 <td data-export-label="WP Multisite"><?php _e( 'WP multisite', 'userswp' ); ?>:</td>
139 <td><?php echo ( $environment['wp_multisite'] ) ? '<span class="dashicons dashicons-yes"></span>' : '&ndash;'; ?></td>
140 </tr>
141 <tr>
142 <td data-export-label="WP Memory Limit"><?php _e( 'WP memory limit', 'userswp' ); ?>:</td>
143 <td><?php
144 if ( $environment['wp_memory_limit'] < 67108864 ) {
145 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( '%1$s - We recommend setting memory to at least 64MB. See: %2$s', 'userswp' ), size_format( $environment['wp_memory_limit'] ), '<a href="https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP" target="_blank">' . __( 'Increasing memory allocated to PHP', 'userswp' ) . '</a>' ) . '</mark>';
146 } else {
147 echo '<mark class="yes">' . size_format( $environment['wp_memory_limit'] ) . '</mark>';
148 }
149 ?></td>
150 </tr>
151 <tr>
152 <td data-export-label="WP Debug Mode"><?php _e( 'WP debug mode', 'userswp' ); ?>:</td>
153 <td>
154 <?php if ( $environment['wp_debug_mode'] ) : ?>
155 <mark class="yes"><span class="dashicons dashicons-yes"></span></mark>
156 <?php else : ?>
157 <mark class="no">&ndash;</mark>
158 <?php endif; ?>
159 </td>
160 </tr>
161 <tr>
162 <td data-export-label="WP Cron"><?php _e( 'WP cron', 'userswp' ); ?>:</td>
163 <td>
164 <?php if ( $environment['wp_cron'] ) : ?>
165 <mark class="yes"><span class="dashicons dashicons-yes"></span></mark>
166 <?php else : ?>
167 <mark class="no">&ndash;</mark>
168 <?php endif; ?>
169 </td>
170 </tr>
171 <tr>
172 <td data-export-label="Language"><?php _e( 'Language', 'userswp' ); ?>:</td>
173 <td><?php echo esc_html( $environment['language'] ) ?></td>
174 </tr>
175 </tbody>
176 </table>
177
178 <table class="uwp-status-table widefat" cellspacing="0">
179 <thead>
180 <tr>
181 <th colspan="3" data-export-label="Server Environment"><h2><?php _e( 'Server Environment', 'userswp' ); ?></h2></th>
182 </tr>
183 </thead>
184 <tbody>
185 <tr>
186 <td data-export-label="Server Info"><?php _e( 'Server info', 'userswp' ); ?>:</td>
187 <td><?php echo esc_html( $environment['server_info'] ); ?></td>
188 </tr>
189 <tr>
190 <td data-export-label="PHP Version"><?php _e( 'PHP version', 'userswp' ); ?>:</td>
191 <td><?php
192 if ( version_compare( $environment['php_version'], '5.6', '<' ) ) {
193 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( '%1$s - We recommend a minimum PHP version of 5.6.', 'userswp' ), esc_html( $environment['php_version'] ) ) . '</mark>';
194 } else {
195 echo '<mark class="yes">' . esc_html( $environment['php_version'] ) . '</mark>';
196 }
197 ?></td>
198 </tr>
199 <?php if ( function_exists( 'ini_get' ) ) : ?>
200 <tr>
201 <td data-export-label="PHP Post Max Size"><?php _e( 'PHP post max size', 'userswp' ); ?>:</td>
202 <td><?php echo esc_html( size_format( $environment['php_post_max_size'] ) ) ?></td>
203 </tr>
204 <tr>
205 <td data-export-label="PHP Time Limit"><?php _e( 'PHP time limit', 'userswp' ); ?>:</td>
206 <td><?php echo esc_html( $environment['php_max_execution_time'] ) ?></td>
207 </tr>
208 <tr>
209 <td data-export-label="PHP Max Input Vars"><?php _e( 'PHP max input vars', 'userswp' ); ?>:</td>
210 <td><?php echo esc_html( $environment['php_max_input_vars'] ) ?></td>
211 </tr>
212 <tr>
213 <td data-export-label="cURL Version"><?php _e( 'cURL version', 'userswp' ); ?>:</td>
214 <td><?php echo esc_html( $environment['curl_version'] ) ?></td>
215 </tr>
216 <tr>
217 <td data-export-label="SUHOSIN Installed"><?php _e( 'SUHOSIN installed', 'userswp' ); ?>:</td>
218 <td><?php echo $environment['suhosin_installed'] ? '<span class="dashicons dashicons-yes"></span>' : '&ndash;'; ?></td>
219 </tr>
220 <?php endif;
221 if ( $wpdb->use_mysqli ) {
222 $ver = mysqli_get_server_info( $wpdb->dbh );
223 } else {
224 $ver = mysql_get_server_info();
225 }
226 if ( ! empty( $wpdb->is_mysql ) && ! stristr( $ver, 'MariaDB' ) ) : ?>
227 <tr>
228 <td data-export-label="MySQL Version"><?php _e( 'MySQL version', 'userswp' ); ?>:</td>
229 <td>
230 <?php
231 if ( version_compare( $environment['mysql_version'], '5.6', '<' ) ) {
232 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( '%1$s - We recommend a minimum MySQL version of 5.6. See: %2$s', 'userswp' ), esc_html( $environment['mysql_version'] ), '<a href="https://wordpress.org/about/requirements/" target="_blank">' . __( 'WordPress requirements', 'userswp' ) . '</a>' ) . '</mark>';
233 } else {
234 echo '<mark class="yes">' . esc_html( $environment['mysql_version'] ) . '</mark>';
235 }
236 ?>
237 </td>
238 </tr>
239 <?php endif; ?>
240 <tr>
241 <td data-export-label="Max Upload Size"><?php _e( 'Max upload size', 'userswp' ); ?>:</td>
242 <td><?php echo size_format( $environment['max_upload_size'] ) ?></td>
243 </tr>
244 <tr>
245 <td data-export-label="Default Timezone is UTC"><?php _e( 'Default timezone is UTC', 'userswp' ); ?>:</td>
246 <td><?php
247 if ( 'UTC' !== $environment['default_timezone'] ) {
248 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Default timezone is %s - it should be UTC', 'userswp' ), $environment['default_timezone'] ) . '</mark>';
249 } else {
250 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
251 } ?>
252 </td>
253 </tr>
254 <tr>
255 <td data-export-label="fsockopen/cURL"><?php _e( 'fsockopen/cURL', 'userswp' ); ?>:</td>
256 <td><?php
257 if ( $environment['fsockopen_or_curl_enabled'] ) {
258 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
259 } else {
260 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . __( 'Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'userswp' ) . '</mark>';
261 } ?>
262 </td>
263 </tr>
264 <tr>
265 <td data-export-label="SoapClient"><?php _e( 'SoapClient', 'userswp' ); ?>:</td>
266 <td><?php
267 if ( $environment['soapclient_enabled'] ) {
268 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
269 } else {
270 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Your server does not have the %s class enabled - some gateway plugins which use SOAP may not work as expected.', 'userswp' ), '<a href="https://php.net/manual/en/class.soapclient.php">SoapClient</a>' ) . '</mark>';
271 } ?>
272 </td>
273 </tr>
274 <tr>
275 <td data-export-label="DOMDocument"><?php _e( 'DOMDocument', 'userswp' ); ?>:</td>
276 <td><?php
277 if ( $environment['domdocument_enabled'] ) {
278 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
279 } else {
280 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Your server does not have the %s class enabled - HTML/Multipart emails, and also some extensions, will not work without DOMDocument.', 'userswp' ), '<a href="https://php.net/manual/en/class.domdocument.php">DOMDocument</a>' ) . '</mark>';
281 } ?>
282 </td>
283 </tr>
284 <tr>
285 <td data-export-label="GZip"><?php _e( 'GZip', 'userswp' ); ?>:</td>
286 <td><?php
287 if ( $environment['gzip_enabled'] ) {
288 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
289 } else {
290 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Your server does not support the %s function - this is required to use the GeoIP database from MaxMind.', 'userswp' ), '<a href="https://php.net/manual/en/zlib.installation.php">gzopen</a>' ) . '</mark>';
291 } ?>
292 </td>
293 </tr>
294 <tr>
295 <td data-export-label="GD Library"><?php _e( 'GD Library', 'userswp' ); ?>:</td>
296 <td><?php
297 if ( $environment['gd_library'] ) {
298 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
299 } else {
300 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Your server does not have enabled %s - this is required for image processing.', 'userswp' ), '<a href="https://secure.php.net/manual/en/image.installation.php">GD Library</a>' ) . '</mark>';
301 } ?>
302 </td>
303 </tr>
304 <tr>
305 <td data-export-label="Multibyte String"><?php _e( 'Multibyte string', 'userswp' ); ?>:</td>
306 <td><?php
307 if ( $environment['mbstring_enabled'] ) {
308 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
309 } else {
310 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Your server does not support the %s functions - this is required for better character encoding. Some fallbacks will be used instead for it.', 'userswp' ), '<a href="https://php.net/manual/en/mbstring.installation.php">mbstring</a>' ) . '</mark>';
311 } ?>
312 </td>
313 </tr>
314 <tr>
315 <td data-export-label="Remote Post"><?php _e( 'Remote POST', 'userswp' ); ?>:</td>
316 <td><?php
317 if ( $environment['remote_post_successful'] ) {
318 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
319 } else {
320 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( '%s failed. Contact your hosting provider.', 'userswp' ), 'wp_remote_post()' ) . ' ' . esc_html( $environment['remote_post_response'] ) . '</mark>';
321 } ?>
322 </td>
323 </tr>
324 <tr>
325 <td data-export-label="Remote Get"><?php _e( 'Remote GET', 'userswp' ); ?>:</td>
326 <td><?php
327 if ( $environment['remote_get_successful'] ) {
328 echo '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>';
329 } else {
330 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( '%s failed. Contact your hosting provider.', 'userswp' ), 'wp_remote_get()' ) . ' ' . esc_html( $environment['remote_get_response'] ) . '</mark>';
331 } ?>
332 </td>
333 </tr>
334 <?php
335 $rows = apply_filters( 'uwp_system_status_environment_rows', array() );
336 if(count($rows) > 0) {
337 foreach ($rows as $row) {
338 if (!empty($row['success'])) {
339 $css_class = 'yes';
340 $icon = '<span class="dashicons dashicons-yes"></span>';
341 } else {
342 $css_class = 'error';
343 $icon = '<span class="dashicons dashicons-no-alt"></span>';
344 }
345 ?>
346 <tr>
347 <td data-export-label="<?php echo esc_attr($row['name']); ?>"><?php echo esc_html($row['name']); ?>
348 :
349 </td>
350 <td>
351 <mark class="<?php echo esc_attr($css_class); ?>">
352 <?php echo $icon; ?><?php echo !empty($row['note']) ? wp_kses_data($row['note']) : ''; ?>
353 </mark>
354 </td>
355 </tr><?php
356 }
357 }?>
358 </tbody>
359 </table>
360 <table class="widefat" cellspacing="0">
361 <thead>
362 <tr>
363 <th colspan="3" data-export-label="User Platform"><h2><?php _e( 'User Platform', 'userswp' ); ?></h2></th>
364 </tr>
365 </thead>
366 <tbody>
367 <tr>
368 <td data-export-label="Platform"><?php _e( 'Platform', 'userswp' ); ?>:</td>
369 <td><?php echo esc_html( $environment['platform'] ); ?></td>
370 </tr>
371 <tr>
372 <td data-export-label="Browser name"><?php _e( 'Browser name', 'userswp' ); ?>:</td>
373 <td><?php echo esc_html( $environment['browser_name'] ); ?></td>
374 </tr>
375 <tr>
376 <td data-export-label="Browser version"><?php _e( 'Browser version', 'userswp' ); ?>:</td>
377 <td><?php echo esc_html( $environment['browser_version'] ); ?></td>
378 </tr>
379 <tr>
380 <td data-export-label="User agent"><?php _e( 'User agent', 'userswp' ); ?>:</td>
381 <td><?php echo esc_html( $environment['user_agent'] ); ?></td>
382 </tr>
383 </tbody>
384 </table>
385 <table class="uwp-status-table widefat" cellspacing="0">
386 <thead>
387 <tr>
388 <th colspan="3" data-export-label="Database"><h2><?php _e( 'Database', 'userswp' ); ?></h2></th>
389 </tr>
390 </thead>
391 <tbody>
392 <tr>
393 <td data-export-label="UWP Database Version"><?php _e( 'UWP database version', 'userswp' ); ?>:</td>
394 <td><?php echo esc_html( $database['uwp_db_version'] ); ?></td>
395 </tr>
396 <tr>
397 <td data-export-label="UWP Database Prefix"><?php _e( 'Database Prefix', 'userswp' ); ?></td>
398 <td><?php
399 if ( strlen( $database['database_prefix'] ) > 20 ) {
400 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( '%1$s - We recommend using a prefix with less than 20 characters.', 'userswp' ), esc_html( $database['database_prefix'] ) ) . '</mark>';
401 } else {
402 echo '<mark class="yes">' . esc_html( $database['database_prefix'] ) . '</mark>';
403 }
404 ?>
405 </td>
406 </tr>
407 <tr>
408 <td><?php _e( 'Total Database Size', 'userswp' ); ?></td>
409 <td><?php printf( '%.2fMB', $database['database_size']['data'] + $database['database_size']['index'] ); ?></td>
410 </tr>
411
412 <tr>
413 <td><?php _e( 'Database Data Size', 'userswp' ); ?></td>
414 <td><?php printf( '%.2fMB', $database['database_size']['data'] ); ?></td>
415 </tr>
416
417 <tr>
418 <td><?php _e( 'Database Index Size', 'userswp' ); ?></td>
419 <td><?php printf( '%.2fMB', $database['database_size']['index'] ); ?></td>
420 </tr>
421
422 <?php foreach ( $database['database_tables']['userswp'] as $table => $table_data ) { ?>
423 <tr>
424 <td><?php echo esc_html( $table ); ?></td>
425 <td>
426 <?php if( ! $table_data ) {
427 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . __( 'Table does not exist', 'userswp' ) . '</mark>';
428 } else {
429 printf( __( 'Data: %.2fMB + Index: %.2fMB', 'userswp' ), uwp_format_decimal( $table_data['data'], 2 ), uwp_format_decimal( $table_data['index'], 2 ) );
430 } ?>
431 </td>
432 </tr>
433 <?php } ?>
434
435 <?php foreach ( $database['database_tables']['other'] as $table => $table_data ) { ?>
436 <tr>
437 <td><?php echo esc_html( $table ); ?></td>
438 <td>
439 <?php printf( __( 'Data: %.2fMB + Index: %.2fMB', 'userswp' ), uwp_format_decimal( $table_data['data'], 2 ), uwp_format_decimal( $table_data['index'], 2 ) ); ?>
440 </td>
441 </tr>
442 <?php } ?>
443 </tbody>
444 </table>
445 <table class="uwp-status-table widefat" cellspacing="0">
446 <thead>
447 <tr>
448 <th colspan="3" data-export-label="Security"><h2><?php _e( 'Security', 'userswp' ); ?></h2></th>
449 </tr>
450 </thead>
451 <tbody>
452 <tr>
453 <td data-export-label="Secure connection (HTTPS)"><?php _e( 'Secure connection (HTTPS)', 'userswp' ); ?>:</td>
454 <td>
455 <?php if ( $security['secure_connection'] ) : ?>
456 <mark class="yes"><span class="dashicons dashicons-yes"></span></mark>
457 <?php else : ?>
458 <mark class="error"><span class="dashicons dashicons-warning"></span><?php echo __( 'Your site is not using HTTPS.', 'userswp' ); ?></mark>
459 <?php endif; ?>
460 </td>
461 </tr>
462 <tr>
463 <td data-export-label="Hide errors from visitors"><?php _e( 'Hide errors from visitors', 'userswp' ); ?></td>
464 <td>
465 <?php if ( $security['hide_errors'] ) : ?>
466 <mark class="yes"><span class="dashicons dashicons-yes"></span></mark>
467 <?php else : ?>
468 <mark class="error"><span class="dashicons dashicons-warning"></span><?php _e( 'Error messages should not be shown to visitors.', 'userswp' ); ?></mark>
469 <?php endif; ?>
470 </td>
471 </tr>
472 </tbody>
473 </table>
474 <table class="uwp-status-table widefat" cellspacing="0">
475 <thead>
476 <tr>
477 <th colspan="3" data-export-label="Active Plugins (<?php echo count( $active_plugins ) ?>)"><h2><?php _e( 'Active Plugins', 'userswp' ); ?> (<?php echo count( $active_plugins ) ?>)</h2></th>
478 </tr>
479 </thead>
480 <tbody>
481 <?php
482 foreach ( $active_plugins as $plugin ) {
483 if ( ! empty( $plugin['name'] ) ) {
484 $dirname = dirname( $plugin['plugin'] );
485
486 // Link the plugin name to the plugin url if available.
487 $plugin_name = esc_html( $plugin['name'] );
488 if ( ! empty( $plugin['url'] ) ) {
489 $plugin_name = '<a href="' . esc_url( $plugin['url'] ) . '" aria-label="' . esc_attr__( 'Visit plugin homepage' , 'userswp' ) . '" target="_blank">' . $plugin_name . '</a>';
490 }
491
492 $version_string = '';
493 $network_string = '';
494 if ( ! empty( $plugin['latest_verison'] ) && version_compare( $plugin['latest_verison'], $plugin['version'], '>' ) ) {
495 /* translators: %s: plugin latest version */
496 $version_string = ' &ndash; <strong style="color:red;">' . sprintf( esc_html__( '%s is available', 'userswp' ), $plugin['latest_verison'] ) . '</strong>';
497 }
498
499 if ( false != $plugin['network_activated'] ) {
500 $network_string = ' &ndash; <strong style="color:black;">' . __( 'Network enabled', 'userswp' ) . '</strong>';
501 }
502 ?>
503 <tr>
504 <td><?php echo $plugin_name; ?></td>
505 <td><?php
506 /* translators: %s: plugin author */
507 printf( __( 'by %s', 'userswp' ), $plugin['author_name'] );
508 echo ' &ndash; ' . esc_html( $plugin['version'] ) . $version_string . $network_string;
509 ?></td>
510 </tr>
511 <?php
512 }
513 }
514 ?>
515 </tbody>
516 </table>
517
518 <table class="uwp-status-table widefat" cellspacing="0">
519 <thead>
520 <tr>
521 <th colspan="3" data-export-label="UWP Pages"><h2><?php _e( 'UWP Pages', 'userswp' ); ?></h2></th>
522 </tr>
523 </thead>
524 <tbody>
525 <?php
526 foreach ( $pages as $page ) {
527 $error = false;
528
529 if ( $page['page_id'] ) {
530 $page_name = '<a href="' . get_edit_post_link( $page['page_id'] ) . '" aria-label="' . sprintf( __( 'Edit %s page', 'userswp' ), esc_html( $page['page_name'] ) ) . '">' . esc_html( $page['page_name'] ) . '</a>';
531 } else {
532 $page_name = esc_html( $page['page_name'] );
533 }
534
535 echo '<tr><td data-export-label="' . esc_attr( $page_name ) . '">' . $page_name . ':</td><td>';
536 // Page ID check.
537 if ( ! $page['page_set'] ) {
538 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . __( 'Page not set', 'userswp' ) . '</mark>';
539 $error = true;
540 } elseif ( ! $page['page_exists'] ) {
541 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . __( 'Page ID is set, but the page does not exist', 'userswp' ) . '</mark>';
542 $error = true;
543 } elseif ( ! $page['page_visible'] ) {
544 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Page visibility should be <a href="%s" target="_blank">public</a>', 'userswp' ), 'https://codex.wordpress.org/Content_Visibility' ) . '</mark>';
545 $error = true;
546 } else {
547 // Shortcode check
548 if ( $page['shortcode_required'] ) {
549 if ( ! $page['shortcode_present'] ) {
550 echo '<mark class="error"><span class="dashicons dashicons-warning"></span> ' . sprintf( __( 'Page does not contains the shortcode.', 'userswp' ), $page['shortcode'] ) . '</mark>';
551 $error = true;
552 }
553 }
554 }
555
556 if ( ! $error ) {
557 echo '<mark class="yes">#' . absint( $page['page_id'] ) . ' - ' . str_replace( home_url(), '', get_permalink( $page['page_id'] ) ) . '</mark>';
558 }
559
560 echo '</td></tr>';
561 }
562 ?>
563 </tbody>
564 </table>
565 <table class="uwp-status-table widefat" cellspacing="0">
566 <thead>
567 <tr>
568 <th colspan="3" data-export-label="Theme"><h2><?php _e( 'Theme', 'userswp' ); ?></h2></th>
569 </tr>
570 </thead>
571 <tbody>
572 <tr>
573 <td data-export-label="Name"><?php _e( 'Name', 'userswp' ); ?>:</td>
574 <td><?php echo esc_html( $theme['name'] ) ?></td>
575 </tr>
576 <tr>
577 <td data-export-label="Version"><?php _e( 'Version', 'userswp' ); ?>:</td>
578 <td><?php
579 echo esc_html( $theme['version'] );
580 if ( version_compare( $theme['version'], $theme['latest_verison'], '<' ) ) {
581 /* translators: %s: theme latest version */
582 echo ' &ndash; <strong style="color:red;">' . sprintf( __( '%s is available', 'userswp' ), esc_html( $theme['latest_verison'] ) ) . '</strong>';
583 }
584 ?></td>
585 </tr>
586 <tr>
587 <td data-export-label="Author URL"><?php _e( 'Author URL', 'userswp' ); ?>:</td>
588 <td><?php echo esc_html( $theme['author_url'] ) ?></td>
589 </tr>
590 <tr>
591 <td data-export-label="Child Theme"><?php _e( 'Child theme', 'userswp' ); ?>:</td>
592 <td><?php
593 echo $theme['is_child_theme'] ? '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>' : '<span class="dashicons dashicons-no-alt"></span> &ndash; ' . sprintf( __( 'If you are modifying userswp on a parent theme that you did not build personally we recommend using a child theme. See: <a href="%s" target="_blank">How to create a child theme</a>', 'userswp' ), 'https://codex.wordpress.org/Child_Themes' );
594 ?></td>
595 </tr>
596 <?php
597 if ( $theme['is_child_theme'] ) :
598 ?>
599 <tr>
600 <td data-export-label="Parent Theme Name"><?php _e( 'Parent theme name', 'userswp' ); ?>:</td>
601 <td><?php echo esc_html( $theme['parent_name'] ); ?></td>
602 </tr>
603 <tr>
604 <td data-export-label="Parent Theme Version"><?php _e( 'Parent theme version', 'userswp' ); ?>:</td>
605 <td><?php
606 echo esc_html( $theme['parent_version'] );
607 if ( version_compare( $theme['parent_version'], $theme['parent_latest_verison'], '<' ) ) {
608 /* translators: %s: parant theme latest version */
609 echo ' &ndash; <strong style="color:red;">' . sprintf( __( '%s is available', 'userswp' ), esc_html( $theme['parent_latest_verison'] ) ) . '</strong>';
610 }
611 ?></td>
612 </tr>
613 <tr>
614 <td data-export-label="Parent Theme Author URL"><?php _e( 'Parent theme author URL', 'userswp' ); ?>:</td>
615 <td><?php echo esc_html( $theme['parent_author_url'] ) ?></td>
616 </tr>
617 <?php endif ?>
618 </tbody>
619 </table>
620 <table class="uwp-status-table widefat" cellspacing="0">
621 <thead>
622 <tr>
623 <th colspan="3" data-export-label="Templates"><h2><?php _e( 'Templates', 'userswp' ); ?></h2></th>
624 </tr>
625 </thead>
626 <tbody>
627 <?php
628 if ( ! empty( $theme['overrides'] ) ) { ?>
629 <tr>
630 <td data-export-label="Overrides"><?php _e( 'Overrides', 'userswp' ); ?></td>
631 <td>
632 <?php
633 $total_overrides = count( $theme['overrides'] );
634 for ( $i = 0; $i < $total_overrides; $i++ ) {
635 $override = $theme['overrides'][ $i ];
636 if ( $override['core_version'] && ( empty( $override['version'] ) || version_compare( $override['version'], $override['core_version'], '<' ) ) ) {
637 $current_version = $override['version'] ? $override['version'] : '-';
638 printf(
639 __( '%1$s version %2$s is out of date. The core version is %3$s', 'userswp' ),
640 '<code>' . $override['file'] . '</code>',
641 '<strong style="color:red">' . $current_version . '</strong>',
642 $override['core_version']
643 );
644 } else {
645 echo esc_html( $override['file'] );
646 }
647 if ( ( count( $theme['overrides'] ) - 1 ) !== $i ) {
648 echo ', ';
649 }
650 echo '<br />';
651 }
652 ?>
653 </td>
654 </tr>
655 <?php
656 } else {
657 ?>
658 <tr>
659 <td data-export-label="Overrides"><?php _e( 'Overrides', 'userswp' ); ?>:</td>
660 <td>&ndash;</td>
661 </tr>
662 <?php
663 }
664
665 if ( true === $theme['has_outdated_templates'] ) {
666 ?>
667 <tr>
668 <td data-export-label="Outdated Templates"><?php _e( 'Outdated templates', 'userswp' ); ?>:</td>
669 <td><mark class="error"><span class="dashicons dashicons-warning"></span></mark></td>
670 </tr>
671 <?php
672 }
673 ?>
674 </tbody>
675 </table>
676 <?php
677 }
678
679 /**
680 * Get array of environment information. Includes thing like software
681 * versions, and various server settings.
682 *
683 * @return array
684 */
685 public function uwp_get_environment_info() {
686 global $wpdb;
687
688 // Figure out cURL version, if installed.
689 $curl_version = '';
690 if ( function_exists( 'curl_version' ) ) {
691 $curl_version = curl_version();
692 $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
693 }
694
695 // WP memory limit
696 $wp_memory_limit = uwp_let_to_num( WP_MEMORY_LIMIT );
697 if ( function_exists( 'memory_get_usage' ) ) {
698 $wp_memory_limit = max( $wp_memory_limit, uwp_let_to_num( @ini_get( 'memory_limit' ) ) );
699 }
700
701 // User agent
702 $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
703
704 // Test POST requests
705 $post_response = wp_safe_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', array(
706 'timeout' => 10,
707 'user-agent' => 'WordPress/' . get_bloginfo( 'version' ) . '; ' . home_url(),
708 'httpversion' => '1.1',
709 'body' => array(
710 'useragent' => $user_agent,
711 ),
712 ) );
713
714 $post_response_body = NULL;
715 $post_response_successful = false;
716 if ( ! is_wp_error( $post_response ) && $post_response['response']['code'] >= 200 && $post_response['response']['code'] < 300 ) {
717 $post_response_successful = true;
718 $post_response_body = json_decode( wp_remote_retrieve_body( $post_response ), true );
719 }
720
721 // Test GET requests
722 $get_response = wp_safe_remote_get( 'https://plugins.svn.wordpress.org/userswp/trunk/readme.txt', array(
723 'timeout' => 10,
724 'user-agent' => 'UsersWP/' . USERSWP_VERSION,
725 'httpversion' => '1.1'
726 ) );
727 $get_response_successful = false;
728 if ( ! is_wp_error( $post_response ) && $post_response['response']['code'] >= 200 && $post_response['response']['code'] < 300 ) {
729 $get_response_successful = true;
730 }
731
732 // Return all environment info. Described by JSON Schema.
733 return array(
734 'home_url' => get_option( 'home' ),
735 'site_url' => get_option( 'siteurl' ),
736 'version' => USERSWP_VERSION,
737 'wp_version' => get_bloginfo( 'version' ),
738 'wp_multisite' => is_multisite(),
739 'wp_memory_limit' => $wp_memory_limit,
740 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
741 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
742 'language' => get_locale(),
743 'server_info' => $_SERVER['SERVER_SOFTWARE'],
744 'php_version' => phpversion(),
745 'php_post_max_size' => uwp_let_to_num( ini_get( 'post_max_size' ) ),
746 'php_max_execution_time' => ini_get( 'max_execution_time' ),
747 'php_max_input_vars' => ini_get( 'max_input_vars' ),
748 'curl_version' => $curl_version,
749 'suhosin_installed' => extension_loaded( 'suhosin' ),
750 'max_upload_size' => wp_max_upload_size(),
751 'mysql_version' => ( ! empty( $wpdb->is_mysql ) ? $wpdb->db_version() : '' ),
752 'default_timezone' => date_default_timezone_get(),
753 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),
754 'soapclient_enabled' => class_exists( 'SoapClient' ),
755 'domdocument_enabled' => class_exists( 'DOMDocument' ),
756 'gzip_enabled' => is_callable( 'gzopen' ),
757 'gd_library' => extension_loaded( 'gd' ),
758 'mbstring_enabled' => extension_loaded( 'mbstring' ),
759 'remote_post_successful' => $post_response_successful,
760 'remote_post_response' => ( is_wp_error( $post_response ) ? $post_response->get_error_message() : $post_response['response']['code'] ),
761 'remote_get_successful' => $get_response_successful,
762 'remote_get_response' => ( is_wp_error( $get_response ) ? $get_response->get_error_message() : $get_response['response']['code'] ),
763 'platform' => ! empty( $post_response_body['platform'] ) ? $post_response_body['platform'] : '-',
764 'browser_name' => ! empty( $post_response_body['name'] ) ? $post_response_body['name'] : '-',
765 'browser_version' => ! empty( $post_response_body['version'] ) ? $post_response_body['version'] : '-',
766 'user_agent' => $user_agent
767 );
768 }
769
770 public function uwp_get_database_info(){
771 global $wpdb;
772
773 $database_table_sizes = $wpdb->get_results( $wpdb->prepare( "
774 SELECT
775 table_name AS 'name',
776 round( ( data_length / 1024 / 1024 ), 2 ) 'data',
777 round( ( index_length / 1024 / 1024 ), 2 ) 'index'
778 FROM information_schema.TABLES
779 WHERE table_schema = %s
780 ORDER BY name ASC;
781 ", DB_NAME ) );
782
783 $core_tables = array(
784 'uwp_usermeta',
785 'uwp_form_fields',
786 'uwp_form_extras',
787 'uwp_activity',
788 'uwp_followers',
789 'uwp_friends',
790 );
791
792 $core_tables = apply_filters( 'uwp_database_tables', $core_tables );
793
794 /**
795 * Adding the prefix to the tables array, for backwards compatibility.
796 *
797 * If we changed the tables above to include the prefix, then any filters against that table could break.
798 */
799 $core_tables = array_map( array( $this, 'uwp_add_db_table_prefix' ), $core_tables );
800
801 /**
802 * Organize UWP and non-UWP tables separately for display purposes later.
803 *
804 * To ensure we include all UWP tables, even if they do not exist, pre-populate the UWP array with all the tables.
805 */
806 $tables = array(
807 'userswp' => array_fill_keys( $core_tables, false ),
808 'other' => array()
809 );
810
811 $database_size = array(
812 'data' => 0,
813 'index' => 0
814 );
815
816 foreach ( $database_table_sizes as $table ) {
817 $table_type = in_array( $table->name, $core_tables ) ? 'userswp' : 'other';
818
819 $tables[ $table_type ][ $table->name ] = array(
820 'data' => $table->data,
821 'index' => $table->index
822 );
823
824 $database_size[ 'data' ] += $table->data;
825 $database_size[ 'index' ] += $table->index;
826 }
827
828 // Return all database info. Described by JSON Schema.
829 return array(
830 'uwp_db_version' => get_option( 'uwp_db_version' ),
831 'database_prefix' => $wpdb->prefix,
832 'database_tables' => $tables,
833 'database_size' => $database_size,
834 );
835 }
836
837 public function uwp_get_active_plugins(){
838 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
839 require_once( ABSPATH . 'wp-admin/includes/update.php' );
840
841 if ( ! function_exists( 'get_plugin_updates' ) ) {
842 return array();
843 }
844
845 // Get both site plugins and network plugins
846 $active_plugins = (array) get_option( 'active_plugins', array() );
847 if ( is_multisite() ) {
848 $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) );
849 $active_plugins = array_merge( $active_plugins, $network_activated_plugins );
850 }
851
852 $active_plugins_data = array();
853 $available_updates = get_plugin_updates();
854
855 foreach ( $active_plugins as $plugin ) {
856 $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
857
858 // convert plugin data to json response format.
859 $active_plugins_data[] = array(
860 'plugin' => $plugin,
861 'name' => $data['Name'],
862 'version' => $data['Version'],
863 'url' => $data['PluginURI'],
864 'author_name' => $data['AuthorName'],
865 'author_url' => esc_url_raw( $data['AuthorURI'] ),
866 'network_activated' => $data['Network'],
867 'latest_verison' => ( array_key_exists( $plugin, $available_updates ) ) ? $available_updates[$plugin]->update->new_version : $data['Version']
868 );
869 }
870
871 return $active_plugins_data;
872 }
873
874 public function uwp_get_theme_info(){
875 $active_theme = wp_get_theme();
876
877 // Get parent theme info if this theme is a child theme, otherwise
878 // pass empty info in the response.
879 if ( is_child_theme() ) {
880 $parent_theme = wp_get_theme( $active_theme->Template );
881 $parent_theme_info = array(
882 'parent_name' => $parent_theme->Name,
883 'parent_version' => $parent_theme->Version,
884 'parent_latest_verison' => $this->get_latest_theme_version( $parent_theme ),
885 'parent_author_url' => $parent_theme->{'Author URI'},
886 );
887 } else {
888 $parent_theme_info = array( 'parent_name' => '', 'parent_version' => '', 'parent_latest_verison' => '', 'parent_author_url' => '' );
889 }
890
891 /**
892 * Scan the theme directory for all UWP templates to see if our theme
893 * overrides any of them.
894 */
895 $override_files = array();
896 $outdated_templates = false;
897 $scan_files = $this->scan_template_files( USERSWP_PATH . 'templates/' );
898
899 foreach ( $scan_files as $file ) {
900 if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
901 $theme_file = get_stylesheet_directory() . '/' . $file;
902 } elseif ( file_exists( get_stylesheet_directory() . '/userswp/' . $file ) ) {
903 $theme_file = get_stylesheet_directory() . '/userswp/' . $file;
904 } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
905 $theme_file = get_template_directory() . '/' . $file;
906 } elseif ( file_exists( get_template_directory() . '/userswp/' . $file ) ) {
907 $theme_file = get_template_directory() . '/userswp/' . $file;
908 } else {
909 $theme_file = false;
910 }
911
912 if ( ! empty( $theme_file ) ) {
913 $core_version = $this->get_file_version( USERSWP_PATH . '/templates/' . $file );
914 $theme_version = $this->get_file_version( $theme_file );
915 if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) {
916 if ( ! $outdated_templates ) {
917 $outdated_templates = true;
918 }
919 }
920 $override_files[] = array(
921 'file' => str_replace( WP_CONTENT_DIR . '/themes/', '', $theme_file ),
922 'version' => $theme_version,
923 'core_version' => $core_version,
924 );
925 }
926 }
927
928 $active_theme_info = array(
929 'name' => $active_theme->Name,
930 'version' => $active_theme->Version,
931 'latest_verison' => $this->get_latest_theme_version( $active_theme ),
932 'author_url' => esc_url_raw( $active_theme->{'Author URI'} ),
933 'is_child_theme' => is_child_theme(),
934 'has_outdated_templates' => $outdated_templates,
935 'overrides' => $override_files,
936 );
937
938 return array_merge( $active_theme_info, $parent_theme_info );
939 }
940
941 public function uwp_get_security_info(){
942 $check_page = get_home_url();
943 return array(
944 'secure_connection' => 'https' === substr( $check_page, 0, 5 ),
945 'hide_errors' => ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ),
946 );
947 }
948
949 public function uwp_get_pages(){
950 $check_pages = array(
951 _x( 'Profile Page', 'Page setting', 'userswp' ) => array(
952 'option' => 'profile_page',
953 'shortcode' => '[uwp_profile]',
954 ),
955 _x( 'Register Page', 'Page setting', 'userswp' ) => array(
956 'option' => 'register_page',
957 'shortcode' => '[uwp_register]',
958 ),
959 _x( 'Login Page', 'Page setting', 'userswp' ) => array(
960 'option' => 'login_page',
961 'shortcode' => '[uwp_login]',
962 ),
963 _x( 'Account Page', 'Page setting', 'userswp' ) => array(
964 'option' => 'account_page',
965 'shortcode' => '[uwp_account]',
966 ),
967 _x( 'Change Password Page', 'Page setting', 'userswp' ) => array(
968 'option' => 'change_page',
969 'shortcode' => '[uwp_change]',
970 ),
971 _x( 'Forgot Password Page', 'Page setting', 'userswp' ) => array(
972 'option' => 'forgot_page',
973 'shortcode' => '[uwp_forgot]',
974 ),
975 _x( 'Reset Password Page', 'Page setting', 'userswp' ) => array(
976 'option' => 'reset_page',
977 'shortcode' => '[uwp_reset]',
978 ),
979 _x( 'Users List Page', 'Page setting', 'userswp' ) => array(
980 'option' => 'users_page',
981 'shortcode' => '[uwp_users]',
982 ),
983 );
984
985 $check_pages = apply_filters('uwp_status_check_pages', $check_pages);
986
987 $pages_output = array();
988 foreach ( $check_pages as $page_name => $values ) {
989 $page_id = uwp_get_page_id( $values['option'], '' );
990 $page_set = $page_exists = $page_visible = false;
991 $shortcode_present = $shortcode_required = false;
992 $page = get_post( $page_id );
993 // Page checks
994 if ( $page_id ) {
995 $page_set = true;
996 }
997 if ( $page ) {
998 $page_exists = true;
999 }
1000 if ( 'publish' === get_post_status( $page_id ) ) {
1001 $page_visible = true;
1002 }
1003
1004 // Shortcode checks
1005 if ( $values['shortcode'] && $page ) {
1006 $shortcode_required = true;
1007 if ( strstr( $page->post_content, $values['shortcode'] ) ) {
1008 $shortcode_present = true;
1009 }
1010 }
1011
1012 // Wrap up our findings into an output array
1013 $pages_output[] = array(
1014 'page_name' => $page_name,
1015 'page_id' => $page_id,
1016 'page_set' => $page_set,
1017 'page_exists' => $page_exists,
1018 'page_visible' => $page_visible,
1019 'shortcode' => $values['shortcode'],
1020 'shortcode_required' => $shortcode_required,
1021 'shortcode_present' => $shortcode_present,
1022 );
1023 }
1024
1025 return $pages_output;
1026 }
1027
1028 /**
1029 * Add prefix to table.
1030 *
1031 * @param string $table table name
1032 * @return string
1033 */
1034 protected function uwp_add_db_table_prefix( $table ) {
1035 return uwp_get_table_prefix() . $table;
1036 }
1037
1038 /**
1039 * Get latest version of a theme by slug.
1040 *
1041 * @since 2.0.0
1042 *
1043 * @param object $theme WP_Theme object.
1044 * @return string Version number if found.
1045 */
1046 public function get_latest_theme_version( $theme ) {
1047 include_once( ABSPATH . 'wp-admin/includes/theme.php' );
1048
1049 $api = themes_api( 'theme_information', array(
1050 'slug' => $theme->get_stylesheet(),
1051 'fields' => array(
1052 'sections' => false,
1053 'tags' => false,
1054 ),
1055 ) );
1056
1057 $update_theme_version = 0;
1058
1059 // Check .org for updates.
1060 if ( is_object( $api ) && ! is_wp_error( $api ) ) {
1061 $update_theme_version = $api->version;
1062 }
1063
1064 return $update_theme_version;
1065 }
1066
1067 /**
1068 * Scan the template files.
1069 *
1070 * @param string $template_path Path to the template directory.
1071 * @return array
1072 */
1073 public function scan_template_files( $template_path ) {
1074 $files = @scandir( $template_path ); // @codingStandardsIgnoreLine.
1075 $result = array();
1076
1077 if ( ! empty( $files ) ) {
1078
1079 foreach ( $files as $key => $value ) {
1080
1081 if ( ! in_array( $value, array( '.', '..' ), true ) ) {
1082
1083 if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
1084 $sub_files = $this->scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
1085 foreach ( $sub_files as $sub_file ) {
1086 $result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
1087 }
1088 } else {
1089 $result[] = $value;
1090 }
1091 }
1092 }
1093 }
1094 return $result;
1095 }
1096
1097 /**
1098 * Retrieve metadata from a file. Based on WP Core's get_file_data function.
1099 *
1100 * @since 1.0.20
1101 * @param string $file Path to the file.
1102 * @return string
1103 */
1104 public function get_file_version( $file ) {
1105
1106 // Avoid notices if file does not exist.
1107 if ( ! file_exists( $file ) ) {
1108 return '';
1109 }
1110
1111 // We don't need to write to the file, so just open for reading.
1112 $fp = fopen( $file, 'r' ); // @codingStandardsIgnoreLine.
1113
1114 // Pull only the first 8kiB of the file in.
1115 $file_data = fread( $fp, 8192 ); // @codingStandardsIgnoreLine.
1116
1117 // PHP will close file handle, but we are good citizens.
1118 fclose( $fp ); // @codingStandardsIgnoreLine.
1119
1120 // Make sure we catch CR-only line endings.
1121 $file_data = str_replace( "\r", "\n", $file_data );
1122 $version = '';
1123
1124 if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) {
1125 $version = _cleanup_header_comment( $match[1] );
1126 }
1127
1128 return $version;
1129 }
1130 }