| 1 |
<?php |
| 2 |
/** |
| 3 |
* Our action for saving options from the admin page. |
| 4 |
* |
| 5 |
* @package ForceRefresh |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace JordanLeven\Plugins\ForceRefresh; |
| 9 |
|
| 10 |
/** |
| 11 |
* Hook used to save admin actions for Force Refresh. |
| 12 |
*/ |
| 13 |
add_action( |
| 14 |
'admin_init', |
| 15 |
function () { |
| 16 |
// If we are saving data from the Force Refresh options. |
| 17 |
if ( |
| 18 |
isset( $_POST['force-refresh-admin-options-save'] ) && |
| 19 |
'true' === $_POST['force-refresh-admin-options-save'] |
| 20 |
) { |
| 21 |
check_admin_referer( WP_FORCE_REFRESH_ACTION, 'nonce' ); |
| 22 |
// Get updated options for viewing the refresh button in the WP Admin bar. |
| 23 |
$show_in_admin_bar = isset( $_POST['show-in-wp-admin-bar'] ) |
| 24 |
? sanitize_text_field( |
| 25 |
wp_unslash( $_POST['show-in-wp-admin-bar'] ) |
| 26 |
) : false; |
| 27 |
// Update the show in Admin Bar option. |
| 28 |
update_option( WP_FORCE_REFRESH_OPTION_SHOW_IN_WP_ADMIN_BAR, $show_in_admin_bar ); |
| 29 |
// Get updated options for the refresh interval. |
| 30 |
$refresh_interval = isset( $_POST['refresh-interval'] ) |
| 31 |
? sanitize_text_field( wp_unslash( $_POST['refresh-interval'] ) ) : null; |
| 32 |
// If the new refresh interval option came through all right. |
| 33 |
if ( $refresh_interval ) { |
| 34 |
// Update the refresh interval. |
| 35 |
update_option( |
| 36 |
WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS, |
| 37 |
$refresh_interval |
| 38 |
); |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
); |
| 43 |
|