| 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 |
|