PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.2
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.2
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 1.0.22 1.0.23 All 172 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.2.2, at includes/class-status.php

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