| 1 |
<?php |
| 2 |
/** |
| 3 |
* Our class responsible for debug storage services. |
| 4 |
* |
| 5 |
* @package ForceRefresh |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace JordanLeven\Plugins\ForceRefresh\Services; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class for debug storage services. |
| 12 |
*/ |
| 13 |
class Debug_Storage_Service { |
| 14 |
|
| 15 |
const OPTION_DEBUG_ACTIVE_DATE = 'force_refresh_debug_active_date'; |
| 16 |
|
| 17 |
const DEBUG_MODE_ACTIVE_IN_HOURS = 48; |
| 18 |
|
| 19 |
/** |
| 20 |
* Method for getting the current debug mode. |
| 21 |
* |
| 22 |
* @return bool True if debug is active. |
| 23 |
*/ |
| 24 |
public static function debug_mode_is_active(): bool { |
| 25 |
$debug_active_date = (string) get_option( self::OPTION_DEBUG_ACTIVE_DATE, '' ); |
| 26 |
|
| 27 |
if ( ! $debug_active_date ) { |
| 28 |
return false; |
| 29 |
} |
| 30 |
|
| 31 |
$time_current = strtotime( current_time( 'mysql' ) ); |
| 32 |
$time_debug = strtotime( $debug_active_date ); |
| 33 |
|
| 34 |
$difference_in_hours = abs( $time_current - $time_debug ) / 3600; |
| 35 |
return $difference_in_hours < self::DEBUG_MODE_ACTIVE_IN_HOURS; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Method for saving the debug mode. |
| 40 |
* |
| 41 |
* @param bool $debug_mode True if debug mode should be turned on. |
| 42 |
* |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public static function set_debug_mode( bool $debug_mode ): void { |
| 46 |
if ( $debug_mode ) { |
| 47 |
$time = current_time( 'mysql' ); |
| 48 |
update_option( |
| 49 |
self::OPTION_DEBUG_ACTIVE_DATE, |
| 50 |
$time |
| 51 |
); |
| 52 |
} else { |
| 53 |
delete_option( self::OPTION_DEBUG_ACTIVE_DATE ); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|