PluginProbe
Force Refresh / 2.12.0
Force Refresh v2.12.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 / services / classes / class-options-storage-service.php

class-options-storage-service.php in Force Refresh 2.12.0, at includes/services/classes/class-options-storage-service.php

97 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Our class responsible for options 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 Options_Storage_Service {
14
15 /**
16 * The option for showing the Force Refresh button in the WordPress Admin Bar.
17 *
18 * @var string
19 */
20 const OPTION_SHOW_IN_WP_ADMIN_BAR = 'force_refresh_show_in_wp_admin_bar';
21
22 /**
23 * The option for the refresh interval (how often the site should check for a new version).
24 *
25 * @var string
26 */
27 const OPTION_REFRESH_INTERVAL_IN_SECONDS = 'force_refresh_refresh_interval';
28
29 /**
30 * Th=ge default refresh interval.
31 *
32 * @var int
33 */
34 const OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT = 120;
35
36 /**
37 * Method for getting the current refresh interval.
38 *
39 * @return int The refresh interval in seconds.
40 */
41 public static function get_refresh_interval(): int {
42 $refresh_interval = (string) get_option(
43 self::OPTION_REFRESH_INTERVAL_IN_SECONDS,
44 self::OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT
45 );
46
47 return $refresh_interval;
48 }
49
50 /**
51 * Method for getting the current set option for showing Force Refresh in admin bar.
52 *
53 * @return bool True if the option is active.
54 */
55 public static function get_show_in_admin_bar(): bool {
56 $show_in_admin_bar = get_option(
57 self::OPTION_SHOW_IN_WP_ADMIN_BAR,
58 'false'
59 );
60
61 // For previous versions of Force Refresh where options were stored as strings.
62 if ( in_array( $show_in_admin_bar, array( 'true', 'false' ), true ) ) {
63 return 'true' === $show_in_admin_bar;
64 }
65
66 return $show_in_admin_bar;
67 }
68
69 /**
70 * Function used to save options for showing the refresh button in the admin bar.
71 *
72 * @param string $show_refresh_in_admin_bar True if we should show refresh in admin bar.
73 *
74 * @return void
75 */
76 public static function set_option_show_in_admin_bar( string $show_refresh_in_admin_bar ): void {
77 update_option(
78 self::OPTION_SHOW_IN_WP_ADMIN_BAR,
79 $show_refresh_in_admin_bar
80 );
81 }
82
83 /**
84 * Function used to save options for the refresh interval.
85 *
86 * @param string $refresh_interval_in_seconds The updated refresh interval in seconds.
87 *
88 * @return void
89 */
90 public static function set_option_refresh_interval( string $refresh_interval_in_seconds ): void {
91 update_option(
92 self::OPTION_REFRESH_INTERVAL_IN_SECONDS,
93 $refresh_interval_in_seconds
94 );
95 }
96 }
97