PluginProbe
Force Refresh / 2.8.0
Force Refresh v2.8.0
3.2.1 3.2.0 3.1.2 3.1.1 3.1.0 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.12.0 All 54 releases
force-refresh / includes / api / admin / inc.save-debug.php

inc.save-debug.php in Force Refresh 2.8.0, at includes/api/admin/inc.save-debug.php

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Our API calls responsible for handling requests from admins to update the debug mode.
4 *
5 * @package ForceRefresh
6 */
7
8 namespace JordanLeven\Plugins\ForceRefresh;
9
10 define(
11 'MESSAGE_SUCCESS_SAVE_DEBUG',
12 "You've successfully updated the debugging mode."
13 );
14
15 /**
16 * Function used to save the debug mode.
17 *
18 * @return void
19 */
20 function save_option_set_debug_mode() {
21 // This function returns the post id after the nonce has already been validated.
22 // phpcs:disable WordPress.Security.NonceVerification
23 $refresh_option_debug_mode = isset( $_REQUEST['debug'] )
24 ? sanitize_text_field( wp_unslash( $_REQUEST['debug'] ) )
25 : null;
26 // phpcs:enable WordPress.Security.NonceVerification
27
28 if ( 'true' === $refresh_option_debug_mode ) {
29 $time = current_time( 'mysql' );
30 update_option(
31 WP_FORCE_REFRESH_OPTION_DEBUG_ACTIVE_DATE,
32 $time
33 );
34 } else {
35 delete_option( WP_FORCE_REFRESH_OPTION_DEBUG_ACTIVE_DATE );
36 }
37 };
38
39 /**
40 * Function used by administrators to update the current debug settings.
41 *
42 * @return void
43 */
44 function request_save_debug_settings() {
45 if ( ! is_user_authorized_to_request_refresh() ) {
46 return_api_response(
47 401,
48 MESSAGE_ERROR_UNAUTHORIZED
49 );
50 } else {
51 save_option_set_debug_mode();
52
53 return_api_response(
54 200,
55 MESSAGE_SUCCESS_SAVE_DEBUG
56 );
57 }
58 }
59
60 // Register the action used by administrators to update the debug settings.
61 add_action(
62 'wp_ajax_force_refresh_update_debug_settings',
63 __NAMESPACE__ . '\\request_save_debug_settings'
64 );
65