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

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