PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
booking / core / admin / wpbc-settings-functions.php

wpbc-settings-functions.php in Booking Calendar 10.1.3, at core/admin/wpbc-settings-functions.php

484 lines 17.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @package Booking Calendar
4 * @category Support functions for Settings page
5 * @author wpdevelop
6 *
7 * @web-site https://wpbookingcalendar.com/
8 * @email info@wpbookingcalendar.com
9 *
10 * @modified 2022-02-08
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 /**
17 * Check if show "Settings General" page OR "System Info"
18 *
19 * @return bool
20 */
21 function wpbc_is_show_general_setting_options(){ //FixIn: 8.9.4.11
22
23 if ( ( isset( $_GET['system_info'] ) ) && ( $_GET['system_info'] == 'show' ) ) {
24 $nonce_gen_time = check_admin_referer( 'wpbc_settings_url_nonce' ); //FixIn: 9.2.2.1
25 return false;
26 }
27 return true;
28 }
29
30
31
32 /**
33 * Show system info at Booking > Settings General page
34 */
35 function wpbc_settings__system_info( $page_name ){
36
37 if ( 'general_settings' != $page_name ) { return false; }
38
39 if ( wpbc_is_this_demo() ) { return false; }
40
41 if ( wpbc_is_show_general_setting_options() ) { return false; }
42
43 //////////////////////////////////////////////////////////////////////////////
44
45 echo '<div class="clear" style="height:30px;"></div>';
46
47 echo '<span class="metabox-holder">';
48
49 wpbc_settings__system_info__reset_booking_forms();
50
51 wpbc_settings__system_info__generate_php_from_pot();
52
53 wpbc_settings__system_info__show_system_info();
54
55 wpbc_settings__system_info__restore_dismissed_windows();
56
57 wpbc_settings__system_info__show_translation_status();
58
59 wpbc_settings__system_info__update_translations();
60
61 wpbc_settings__system_info__debug_and_tests();
62
63 echo '</span>';
64 }
65 add_action( 'wpbc_hook_settings_page_footer', 'wpbc_settings__system_info' ,10, 1);
66
67
68 /**
69 * System info section - Reset Custom Booking forms
70 *
71 * Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .' &reset=custom_forms#wpbc_general_settings_system_info_metabox
72 *
73 */
74 function wpbc_settings__system_info__reset_booking_forms() {
75
76 if ( ! current_user_can( 'activate_plugins' ) ) {
77 return;
78 }
79
80 if ( ( isset( $_GET['reset'] ) ) && ( 'custom_forms' == $_GET['reset'] ) ) { //FixIn: 8.1.3.21
81
82 wpbc_open_meta_box_section( 'wpbc_general_settings_system_info', 'System Info' );
83
84 // Reset Custom Booking Forms to NONE
85 update_bk_option( 'booking_forms_extended', serialize( array() ) );
86
87 wpbc_show_message_in_settings( '<strong>Custom forms</strong> has been reseted!', 'info' );
88
89 wpbc_close_meta_box_section();
90 }
91 }
92
93
94
95 /**
96 * System info section - Generate new translation PHP files from POT file
97 *
98 * // Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .' &pot=1#wpbc_general_settings_system_info_metabox
99 *
100 */
101 function wpbc_settings__system_info__generate_php_from_pot() {
102
103 if ( ! current_user_can( 'activate_plugins' ) ) {
104 return;
105 }
106
107 if ( ! empty( $_GET['pot'] ) ) { //FixIn: 8.1.3.21
108
109 wpbc_open_meta_box_section( 'wpbc_general_settings_system_info', 'System Info' );
110
111 if ( '1' == $_GET['pot'] ) {
112 wpbc_pot_to_php();
113 }
114
115 if ( 'erase__wpbc_all_translations' == $_GET['pot'] ) {
116 wpbc_delete_translation_php_files();
117 }
118
119 wpbc_close_meta_box_section();
120 }
121 }
122
123
124 /**
125 * System info section - Update translations
126 *
127 * // Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .' &update_translations=1#wpbc_general_settings_system_info_metabox
128 *
129 */
130 function wpbc_settings__system_info__update_translations() {
131
132 if ( ! current_user_can( 'activate_plugins' ) ) {
133 return;
134 }
135
136 if ( ( isset( $_GET['update_translations'] ) ) && ( '1' == $_GET['update_translations'] ) ) { //FixIn: 8.1.3.21
137
138 wpbc_open_meta_box_section( 'wpbc_general_settings_system_info', 'System Info' );
139
140 wpbc_update_translations__from_wp();
141
142 wpbc_close_meta_box_section();
143 }
144 }
145
146
147 /**
148 * System info section - Show translation status
149 *
150 * // Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .' &show_translation_status=1#wpbc_general_settings_system_info_metabox
151 *
152 */
153 function wpbc_settings__system_info__show_translation_status() {
154
155 if ( ! current_user_can( 'activate_plugins' ) ) {
156 return;
157 }
158
159 if ( isset( $_GET['show_translation_status'] ) ) { //FixIn: 8.1.3.21
160
161 wpbc_open_meta_box_section( 'wpbc_general_settings_system_info', 'System Info' );
162
163 if ( '1' == $_GET['show_translation_status'] ){
164 wpbc_show_translation_status_compare_wpbc_wp();
165 }
166 if ( '2' == $_GET['show_translation_status'] ){
167 wpbc_show_translation_status_from_wp();
168 }
169 if ( '3' == $_GET['show_translation_status'] ){
170 wpbc_show_translation_status_from_wpbc();
171 }
172
173 wpbc_close_meta_box_section();
174 }
175 }
176
177
178 /**
179 * System info section - Showing information about system - php, server, active plugins, etc...
180 *
181 * Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .' #wpbc_general_settings_system_info_metabox
182 */
183 function wpbc_settings__system_info__show_system_info(){
184
185 if ( ( isset( $_GET['booking_system_info'] ) ) && ( $_GET['booking_system_info'] == 'show' ) ) { ?>
186
187 <?php wpbc_open_meta_box_section( 'wpbc_general_settings_system_info', 'System Info' ); ?>
188
189 <?php wpbc_system_info(); ?>
190
191 <?php wpbc_close_meta_box_section();
192 }
193 }
194
195
196 /**
197 * System info section - Restore Dismissed Windows
198 *
199 * // Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .' &restore_dismissed=On#wpbc_general_settings_restore_dismissed_metabox
200 *
201 */
202 function wpbc_settings__system_info__restore_dismissed_windows(){
203
204 if ( ( isset( $_GET['restore_dismissed'] ) ) && ( $_GET['restore_dismissed'] == 'On' ) ) { //FixIn: 8.1.3.10
205
206 update_bk_option( 'booking_is_show_powered_by_notice', 'On' );
207
208 update_bk_option( 'booking_wpdev_copyright_adminpanel', 'On' );
209
210 global $wpdb;
211 // Delete all users booking windows states
212 if ( false === $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%booking_win_%'" ) ) { // All users data
213 debuge_error( 'Error during deleting user meta at DB', __FILE__, __LINE__ );
214 die();
215 } else {
216
217 wpbc_open_meta_box_section( 'wpbc_general_settings_restore_dismissed', 'Info' );
218
219 ?><h2>All dismissed windows has been restored.</h2><?php
220
221 echo '<div class="clear"></div><hr/><center><a class="button button" href="' . wpbc_get_settings_url() . '">'
222 . 'Reload Page'
223 . '</a></center>';
224
225 wpbc_close_meta_box_section();
226 }
227 }
228 }
229
230
231
232 /**
233 * Show System Info (status) at Booking > Settings General page
234 *
235 */
236 function wpbc_system_info() {
237
238
239
240 if ( current_user_can( 'activate_plugins' ) ) { // Only for Administrator or Super admin. More here: https://codex.wordpress.org/Roles_and_Capabilities
241
242
243 global $wpdb, $wp_version;
244
245 $all_plugins = get_plugins();
246 $active_plugins = get_option( 'active_plugins' );
247
248 $mysql_info = $wpdb->get_results( "SHOW VARIABLES LIKE 'sql_mode'" );
249 if ( is_array( $mysql_info ) ) $sql_mode = $mysql_info[0]->Value;
250 if ( empty( $sql_mode ) ) $sql_mode = 'Not set';
251
252 //FixIn: 8.4.7.24
253 $allow_url_fopen = ( ini_get( 'allow_url_fopen' ) ) ? 'On' : 'Off';
254 $upload_max_filesize = ( ini_get( 'upload_max_filesize' ) ) ? ini_get( 'upload_max_filesize' ) : 'N/A';
255 $post_max_size = ( ini_get( 'post_max_size' ) ) ? ini_get( 'post_max_size' ) : 'N/A';
256 $max_execution_time = ( ini_get( 'max_execution_time' ) ) ? ini_get( 'max_execution_time' ) : 'N/A';
257 $memory_limit = ( ini_get( 'memory_limit' ) ) ? ini_get( 'memory_limit' ) : 'N/A';
258 $memory_usage = ( function_exists( 'memory_get_usage' ) ) ? round( memory_get_usage() / 1024 / 1024, 2 ) . ' Mb' : 'N/A';
259 $exif_read_data = ( is_callable( 'exif_read_data' ) ) ? 'Yes' . " ( V" . substr( phpversion( 'exif' ), 0, 4 ) . ")" : 'No';
260 $iptcparse = ( is_callable( 'iptcparse' ) ) ? 'Yes' : 'No';
261 $xml_parser_create = ( is_callable( 'xml_parser_create' ) ) ? 'Yes' : 'No';
262 $theme = ( function_exists( 'wp_get_theme' ) ) ? wp_get_theme() : get_theme( get_current_theme() );
263
264 if ( function_exists( 'is_multisite' ) ) {
265 if ( is_multisite() ) $multisite = 'Yes';
266 else $multisite = 'No';
267 } else { $multisite = 'N/A';
268 }
269
270 $system_info = array(
271 'system_info' => '',
272 'php_info' => '',
273 'active_plugins' => array(), //FixIn: 8.4.4.1
274 'inactive_plugins' => array() //FixIn: 8.4.4.1
275 );
276
277 $ver_small_name = wpbc_get_plugin_version_type();
278 if ( class_exists( 'wpdev_bk_multiuser' ) ) $ver_small_name = 'multiuser';
279
280 $system_info['system_info'] = array(
281 'Plugin Update' => ( defined( 'WPDEV_BK_VERSION' ) ) ? WPDEV_BK_VERSION : 'N/A',
282 'Plugin Version' => ucwords( $ver_small_name ),
283 'Plugin Update Date' => date( "Y-m-d", filemtime( WPBC_FILE ) ),
284
285 'Server Default Timezone' => date_default_timezone_get(),
286 'WordPress Timezone' => wp_timezone()->getName(),
287
288 'WP Version' => $wp_version,
289 'WP DEBUG' => ( ( defined('WP_DEBUG') ) && ( WP_DEBUG ) ) ? 'On' : 'Off',
290 'WP DB Version' => get_option( 'db_version' ),
291 'Operating System' => PHP_OS,
292 'Server' => $_SERVER["SERVER_SOFTWARE"],
293 'PHP Version' => PHP_VERSION,
294 'MYSQL Version' => $wpdb->get_var( "SELECT VERSION() AS version" ),
295 'SQL Mode' => $sql_mode,
296 'Memory usage' => $memory_usage,
297 'Site URL' => get_option( 'siteurl' ),
298 'Home URL' => home_url(),
299 'SERVER[HTTP_HOST]' => $_SERVER['HTTP_HOST'],
300 'SERVER[SERVER_NAME]' => $_SERVER['SERVER_NAME'],
301 'Multisite' => $multisite,
302 'Active Theme' => $theme['Name'] . ' ' . $theme['Version']
303 );
304
305 $system_info['php_info'] = array(
306 'PHP Version' => PHP_VERSION,
307 'PHP Memory Limit' => '<strong>' . $memory_limit . '</strong>',
308 'PHP Max Script Execute Time' => '<strong>' . $max_execution_time . '</strong>',
309
310 'PHP Max Post Size' => '<strong>' . $post_max_size . '</strong>',
311 'PHP MAX Input Vars' => '<strong>' . ( ( ini_get( 'max_input_vars' ) ) ? ini_get( 'max_input_vars' ) : 'N/A' ) . '</strong>', //How many input variables may be accepted (limit is applied to $_GET, $_POST and $_COOKIE superglobal separately).
312
313 'PHP Max Upload Size' => $upload_max_filesize,
314 'PHP Allow URL fopen' => $allow_url_fopen,
315 'PHP Exif support' => $exif_read_data,
316 'PHP IPTC support' => $iptcparse,
317 'PHP XML support' => $xml_parser_create
318 );
319
320 $system_info['php_info']['PHP cURL'] = ( function_exists('curl_init') ) ? 'On' : 'Off';
321 $system_info['php_info']['Max Nesting Level'] = ( ( ini_get( 'max_input_nesting_level' ) ) ? ini_get( 'max_input_nesting_level' ) : 'N/A' );
322 $system_info['php_info']['Max Time 4 script'] = ( ( ini_get( 'max_input_time' ) ) ? ini_get( 'max_input_time' ) : 'N/A' ); //Maximum amount of time each script may spend parsing request data
323 $system_info['php_info']['Log'] = ( ( ini_get( 'error_log' ) ) ? ini_get( 'error_log' ) : 'N/A' );
324
325 if ( ini_get( "suhosin.get.max_value_length" ) ) {
326
327 $system_info['suhosin_info'] = array();
328 $system_info['suhosin_info']['POST max_array_index_length'] = ( ( ini_get( 'suhosin.post.max_array_index_length' ) ) ? ini_get( 'suhosin.post.max_array_index_length' ) : 'N/A' );
329 $system_info['suhosin_info']['REQUEST max_array_index_length'] = ( ( ini_get( 'suhosin.request.max_array_index_length' ) ) ? ini_get( 'suhosin.request.max_array_index_length' ) : 'N/A' );
330
331 $system_info['suhosin_info']['POST max_totalname_length'] = ( ( ini_get( 'suhosin.post.max_totalname_length' ) ) ? ini_get( 'suhosin.post.max_totalname_length' ) : 'N/A' );
332 $system_info['suhosin_info']['REQUEST max_totalname_length'] = ( ( ini_get( 'suhosin.request.max_totalname_length' ) ) ? ini_get( 'suhosin.request.max_totalname_length' ) : 'N/A' );
333
334 $system_info['suhosin_info']['POST max_vars'] = ( ( ini_get( 'suhosin.post.max_vars' ) ) ? ini_get( 'suhosin.post.max_vars' ) : 'N/A' );
335 $system_info['suhosin_info']['REQUEST max_vars'] = ( ( ini_get( 'suhosin.request.max_vars' ) ) ? ini_get( 'suhosin.request.max_vars' ) : 'N/A' );
336
337 $system_info['suhosin_info']['POST max_value_length'] = ( ( ini_get( 'suhosin.post.max_value_length' ) ) ? ini_get( 'suhosin.post.max_value_length' ) : 'N/A' );
338 $system_info['suhosin_info']['REQUEST max_value_length'] = ( ( ini_get( 'suhosin.request.max_value_length' ) ) ? ini_get( 'suhosin.request.max_value_length' ) : 'N/A' );
339
340 $system_info['suhosin_info']['POST max_name_length'] = ( ( ini_get( 'suhosin.post.max_name_length' ) ) ? ini_get( 'suhosin.post.max_name_length' ) : 'N/A' );
341 $system_info['suhosin_info']['REQUEST max_varname_length'] = ( ( ini_get( 'suhosin.request.max_varname_length' ) ) ? ini_get( 'suhosin.request.max_varname_length' ) : 'N/A' );
342
343 $system_info['suhosin_info']['POST max_array_depth'] = ( ( ini_get( 'suhosin.post.max_array_depth' ) ) ? ini_get( 'suhosin.post.max_array_depth' ) : 'N/A' );
344 $system_info['suhosin_info']['REQUEST max_array_depth'] = ( ( ini_get( 'suhosin.request.max_array_depth' ) ) ? ini_get( 'suhosin.request.max_array_depth' ) : 'N/A' );
345 }
346
347
348 if ( function_exists('gd_info') ) {
349 $gd_info = gd_info();
350 if ( isset( $gd_info['GD Version'] ) )
351 $gd_info = $gd_info['GD Version'];
352 else
353 $gd_info = json_encode( $gd_info );
354 } else {
355 $gd_info = 'Off';
356 }
357 $system_info['php_info']['PHP GD'] = $gd_info;
358
359 // More here https://docs.woocommerce.com/document/problems-with-large-amounts-of-data-not-saving-variations-rates-etc/
360
361
362 foreach ( $all_plugins as $path => $plugin ) {
363 if ( is_plugin_active( $path ) ) {
364 $system_info['active_plugins'][ $plugin['Name'] ] = $plugin['Version'];
365 } else {
366 $system_info['inactive_plugins'][ $plugin['Name'] ] = $plugin['Version'];
367 }
368 }
369
370 // Showing
371 foreach ( $system_info as $section_name => $section_values ) {
372 ?>
373 <span class="wpdevelop">
374 <table class="table table-striped table-bordered">
375 <thead><tr><th colspan="2" style="border-bottom: 1px solid #eeeeee;padding: 10px;"><?php echo strtoupper( $section_name ); ?></th></tr></thead>
376 <tbody>
377 <?php
378 if ( !empty( $section_values ) ) {
379 foreach ( $section_values as $key => $value ) {
380 ?>
381 <tr>
382 <td scope="row" style="width:18em;padding:4px 8px;"><?php echo $key; ?></td>
383 <td scope="row" style="padding:4px 8px;"><?php echo $value; ?></td>
384 </tr>
385 <?php
386 }
387 }
388 ?>
389 </tbody>
390 </table>
391 </span>
392 <div class="clear"></div>
393 <?php
394 }
395 ?>
396 <hr>
397 <div style="color:#777;">
398 <h4 style="font-size:1.1em;">Commonly required configuration vars in php.ini file:</h4>
399 <h4>General section:</h4>
400 <pre><code>memory_limit = 256M
401 max_execution_time = 120
402 post_max_size = 8M
403 upload_max_filesize = 8M
404 max_input_vars = 20480
405 post_max_size = 64M</code></pre>
406 <h4>Suhosin section (if installed):</h4>
407 <pre><code>suhosin.post.max_array_index_length = 1024
408 suhosin.post.max_totalname_length = 65535
409 suhosin.post.max_vars = 2048
410 suhosin.post.max_value_length = 1000000
411 suhosin.post.max_name_length = 256
412 suhosin.post.max_array_depth = 1000
413 suhosin.request.max_array_index_length = 1024
414 suhosin.request.max_totalname_length = 65535
415 suhosin.request.max_vars = 2048
416 suhosin.request.max_value_length = 1000000
417 suhosin.request.max_varname_length = 256
418 suhosin.request.max_array_depth = 1000</code></pre>
419 </div>
420 <?php
421 // phpinfo();
422 }
423 }
424
425
426
427 /**
428 * It's for my tests and debugs
429 */
430 function wpbc_settings__system_info__debug_and_tests() {
431
432 if ( 0 ) {
433
434 wpbc_open_meta_box_section( 'wpbc_general_settings_test_debug', 'Test & Debug' );
435
436 //debuge( get_site_transient( 'update_plugins' ) );
437
438 wpbc_close_meta_box_section();
439 }
440
441
442 if (0){
443 /**
444 * Install Plugin.
445 */
446 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
447 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
448 $skin = new WP_Ajax_Upgrader_Skin();
449 $upgrader = new Plugin_Upgrader( $skin );
450 $package = 'https://wpbookingcalendar.com/download/some-plugin.zip';
451 $result = $upgrader->install( $package ); //$package - The full local path or URI of the package
452 }
453
454 if (0) {
455
456 $plugin_slug = 'booking';
457 global $wp_filesystem;
458
459 $plugin_translations = wp_get_installed_translations( 'plugins' );
460
461 $language_updates = wp_get_translation_updates();
462
463 debuge( '$language_updates, $plugin_translations[ $plugin_slug ]', $language_updates, $plugin_translations[ $plugin_slug ] );
464
465 if ( 0 ) {
466 // Remove language files, silently.
467 if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) {
468 $translations = $plugin_translations[ $plugin_slug ];
469
470 foreach ( $translations as $translation => $data ) {
471 $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' );
472 $wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );
473
474 $json_translation_files = glob( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '-*.json' );
475 if ( $json_translation_files ) {
476 array_map( array( $wp_filesystem, 'delete' ), $json_translation_files );
477 }
478 }
479 }
480 }
481 }
482
483 }
484