|
21 | 21 | * @author Stefan Topfstedt <[email protected]>
|
22 | 22 | */
|
23 | 23 | class WpLibCalHours_Admin {
|
24 |
| - |
25 |
| - /** |
26 |
| - * The ID of this plugin. |
27 |
| - * |
28 |
| - * @since 1.0.0 |
29 |
| - * @access private |
30 |
| - * @var string $plugin_name The ID of this plugin. |
31 |
| - */ |
32 |
| - private $plugin_name; |
33 |
| - |
34 |
| - /** |
35 |
| - * The version of this plugin. |
36 |
| - * |
37 |
| - * @since 1.0.0 |
38 |
| - * @access private |
39 |
| - * @var string $version The current version of this plugin. |
40 |
| - */ |
41 |
| - private $version; |
42 |
| - |
43 |
| - /** |
44 |
| - * Initialize the class and set its properties. |
45 |
| - * |
46 |
| - * @since 1.0.0 |
47 |
| - * |
48 |
| - * @param string $plugin_name The name of this plugin. |
49 |
| - * @param string $version The version of this plugin. |
50 |
| - */ |
51 |
| - public function __construct( $plugin_name, $version ) { |
52 |
| - |
53 |
| - $this->plugin_name = $plugin_name; |
54 |
| - $this->version = $version; |
55 |
| - } |
56 |
| - |
57 |
| - /** |
58 |
| - * Add an options page under the Settings submenu |
59 |
| - * |
60 |
| - * @since 1.0.0 |
61 |
| - */ |
62 |
| - public function add_options_page() { |
63 |
| - $this->plugin_screen_hook_suffix = add_options_page( |
64 |
| - __( 'LibCal Hours Settings', 'wplibcalhours' ), |
65 |
| - __( 'LibCal Hours', 'wplibcalhours' ), |
66 |
| - 'manage_options', |
67 |
| - $this->plugin_name, |
68 |
| - array( $this, 'display_options_page' ) |
69 |
| - ); |
70 |
| - } |
71 |
| - |
72 |
| - /** |
73 |
| - * Render the options page for plugin |
74 |
| - * |
75 |
| - * @since 1.0.0 |
76 |
| - */ |
77 |
| - public function display_options_page() { |
78 |
| - include_once 'partials/wplibcalhours-admin-display.php'; |
79 |
| - } |
80 |
| - |
81 |
| - /** |
82 |
| - * Register all related settings of this plugin |
83 |
| - * |
84 |
| - * @since 1.0.0 |
85 |
| - */ |
86 |
| - public function register_setting() { |
87 |
| - $section_name = $this->plugin_name . '_general'; |
88 |
| - add_settings_section( |
89 |
| - $section_name, |
90 |
| - null, |
91 |
| - null, |
92 |
| - $this->plugin_name |
93 |
| - ); |
94 |
| - |
95 |
| - $option_name = $this->plugin_name . '_api_url'; |
96 |
| - add_settings_field( |
97 |
| - $option_name, |
98 |
| - __( 'LibCal API endpoint (URL)', 'wplibcalhours' ), |
99 |
| - array( $this, $option_name . '_cb' ), |
100 |
| - $this->plugin_name, |
101 |
| - $section_name, |
102 |
| - array( 'label_for' => $option_name ) |
103 |
| - ); |
104 |
| - register_setting( $this->plugin_name, $option_name, 'sanitize_text_field' ); |
105 |
| - |
106 |
| - $option_name = $this->plugin_name . '_ignore_cache'; |
107 |
| - add_settings_field( |
108 |
| - $option_name, |
109 |
| - __( 'Ignore Cache', 'wplibcalhours' ), |
110 |
| - array( $this, $option_name . '_cb' ), |
111 |
| - $this->plugin_name, |
112 |
| - $section_name, |
113 |
| - array( 'label_for' => $option_name ) |
114 |
| - ); |
115 |
| - register_setting( $this->plugin_name, $option_name, 'intval' ); |
116 |
| - } |
117 |
| - |
118 |
| - /** |
119 |
| - * Render the LibCal API endpoint input for this plugin |
120 |
| - * |
121 |
| - * @since 1.0.0 |
122 |
| - */ |
123 |
| - public function wplibcalhours_api_url_cb() { |
124 |
| - $option_name = $this->plugin_name . '_api_url'; |
125 |
| - $url = get_option( $option_name ); |
126 |
| - echo '<input type="url" class="regular-text" name="' . $option_name . '" id="' . $option_name . '" value="' . esc_attr( $url ) . '"> '; |
127 |
| - } |
128 |
| - |
129 |
| - /** |
130 |
| - * Render the "Ignore Cache" checkbox field for this plugin. |
131 |
| - * |
132 |
| - * @since 1.0.0 |
133 |
| - */ |
134 |
| - public function wplibcalhours_ignore_cache_cb() { |
135 |
| - $option_name = $this->plugin_name . '_ignore_cache'; |
136 |
| - $ignore_cache = get_option( $option_name ); |
137 |
| - echo '<input type="checkbox" name="' . $option_name . '" value="1" ' . checked( '1', $ignore_cache, false ) . '/>'; |
138 |
| - } |
139 |
| - |
140 |
| - /** |
141 |
| - * Filter-callback function that adds links to the list of links displayed on the plugins page. |
142 |
| - * |
143 |
| - * @param array $actions array List of existing links. |
144 |
| - * |
145 |
| - * @return array The updated list of links. |
146 |
| - * |
147 |
| - * @link https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name) |
148 |
| - * |
149 |
| - * @since 1.0.0 |
150 |
| - */ |
151 |
| - public function add_action_links( $actions ) { |
152 |
| - $settings = '<a href="' . esc_attr( get_admin_url( null, |
153 |
| - 'options-general.php?page=wplibcalhours' ) ) . '">' . __( 'Settings', 'General' ) . '</a>'; |
154 |
| - array_unshift( $actions, $settings ); |
155 |
| - |
156 |
| - return $actions; |
157 |
| - } |
158 |
| - |
159 |
| - /** |
160 |
| - * Update option callback on the "Ignore Cache" setting. |
161 |
| - * Clears out any LibCal data that may be in the transient cache if this option's value changes. |
162 |
| - * |
163 |
| - * @link https://developer.wordpress.org/reference/hooks/update_option_option/ |
164 |
| - * |
165 |
| - * @since 1.0.0 |
166 |
| - */ |
167 |
| - public function update_option_ignore_cache() { |
168 |
| - delete_transient( $this->plugin_name . '_data' ); |
169 |
| - } |
| 24 | + /** |
| 25 | + * The ID of this plugin. |
| 26 | + * @access private |
| 27 | + * @var string $plugin_name The ID of this plugin. |
| 28 | + */ |
| 29 | + private string $plugin_name; |
| 30 | + |
| 31 | + /** |
| 32 | + * The version of this plugin. |
| 33 | + * @access private |
| 34 | + * @var string $version The current version of this plugin. |
| 35 | + */ |
| 36 | + private string $version; |
| 37 | + |
| 38 | + /** |
| 39 | + * Initialize the class and set its properties. |
| 40 | + * @param string $plugin_name The name of this plugin. |
| 41 | + * @param string $version The version of this plugin. |
| 42 | + */ |
| 43 | + public function __construct(string $plugin_name, string $version) { |
| 44 | + $this->plugin_name = $plugin_name; |
| 45 | + $this->version = $version; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Add an options page under the Settings submenu |
| 50 | + */ |
| 51 | + public function add_options_page() { |
| 52 | + $this->plugin_screen_hook_suffix = add_options_page( |
| 53 | + __('LibCal Hours Settings', 'wplibcalhours'), |
| 54 | + __('LibCal Hours', 'wplibcalhours'), |
| 55 | + 'manage_options', |
| 56 | + $this->plugin_name, |
| 57 | + array($this, 'display_options_page') |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Render the options page for plugin |
| 63 | + */ |
| 64 | + public function display_options_page() { |
| 65 | + include_once 'partials/wplibcalhours-admin-display.php'; |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Register all related settings of this plugin |
| 70 | + */ |
| 71 | + public function register_setting() { |
| 72 | + $section_name = $this->plugin_name . '_general'; |
| 73 | + add_settings_section( |
| 74 | + $section_name, |
| 75 | + null, |
| 76 | + null, |
| 77 | + $this->plugin_name |
| 78 | + ); |
| 79 | + |
| 80 | + $option_name = $this->plugin_name . '_api_url'; |
| 81 | + add_settings_field( |
| 82 | + $option_name, |
| 83 | + __('LibCal API endpoint (URL)', 'wplibcalhours'), |
| 84 | + array($this, $option_name . '_cb'), |
| 85 | + $this->plugin_name, |
| 86 | + $section_name, |
| 87 | + array('label_for' => $option_name) |
| 88 | + ); |
| 89 | + register_setting($this->plugin_name, $option_name, 'sanitize_text_field'); |
| 90 | + |
| 91 | + $option_name = $this->plugin_name . '_ignore_cache'; |
| 92 | + add_settings_field( |
| 93 | + $option_name, |
| 94 | + __('Ignore Cache', 'wplibcalhours'), |
| 95 | + array($this, $option_name . '_cb'), |
| 96 | + $this->plugin_name, |
| 97 | + $section_name, |
| 98 | + array('label_for' => $option_name) |
| 99 | + ); |
| 100 | + register_setting($this->plugin_name, $option_name, 'intval'); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Render the LibCal API endpoint input for this plugin |
| 105 | + */ |
| 106 | + public function wplibcalhours_api_url_cb() { |
| 107 | + $option_name = $this->plugin_name . '_api_url'; |
| 108 | + $url = get_option($option_name); |
| 109 | + echo '<input type="url" class="regular-text" name="' . $option_name . '" id="' . $option_name . '" value="' . esc_attr($url) . '"> '; |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Render the "Ignore Cache" checkbox field for this plugin. |
| 114 | + */ |
| 115 | + public function wplibcalhours_ignore_cache_cb() { |
| 116 | + $option_name = $this->plugin_name . '_ignore_cache'; |
| 117 | + $ignore_cache = get_option($option_name); |
| 118 | + echo '<input type="checkbox" name="' . $option_name . '" value="1" ' . checked('1', $ignore_cache, false) . '/>'; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Filter-callback function that adds links to the list of links displayed on the plugins page. |
| 123 | + * |
| 124 | + * @param array $actions array List of existing links. |
| 125 | + * |
| 126 | + * @return array The updated list of links. |
| 127 | + * |
| 128 | + * @link https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name) |
| 129 | + */ |
| 130 | + public function add_action_links(array $actions) { |
| 131 | + $settings = '<a href="' . esc_attr(get_admin_url(null, |
| 132 | + 'options-general.php?page=wplibcalhours')) . '">' . __('Settings', 'General') . '</a>'; |
| 133 | + array_unshift($actions, $settings); |
| 134 | + |
| 135 | + return $actions; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Update option callback on the "Ignore Cache" setting. |
| 140 | + * Clears out any LibCal data that may be in the transient cache if this option's value changes. |
| 141 | + * |
| 142 | + * @link https://developer.wordpress.org/reference/hooks/update_option_option/ |
| 143 | + */ |
| 144 | + public function update_option_ignore_cache() { |
| 145 | + delete_transient($this->plugin_name . '_data'); |
| 146 | + } |
170 | 147 | }
|
0 commit comments