@@ -42,6 +42,9 @@ public static function init() {
42
42
return ;
43
43
}
44
44
45
+ // Check if user can edit the widget.
46
+ $ can_edit = apply_filters ( 'statify__user_can_see_stats ' , current_user_can ( 'edit_dashboard ' ) );
47
+
45
48
// Load textdomain.
46
49
load_plugin_textdomain (
47
50
'statify ' ,
@@ -57,7 +60,7 @@ public static function init() {
57
60
'statify_dashboard ' ,
58
61
'Statify ' ,
59
62
array ( __CLASS__ , 'print_frontview ' ),
60
- array ( __CLASS__ , 'print_backview ' )
63
+ $ can_edit ? array ( __CLASS__ , 'print_backview ' ) : null
61
64
);
62
65
63
66
// Init CSS.
@@ -183,7 +186,7 @@ public static function print_backview() {
183
186
if ( ! empty ( $ _POST ['statify ' ] ) ) {
184
187
check_admin_referer ( 'statify-dashboard ' );
185
188
186
- self ::_save_options ();
189
+ self ::_save_widget_options ();
187
190
}
188
191
189
192
// Load view.
@@ -194,36 +197,35 @@ public static function print_backview() {
194
197
195
198
196
199
/**
197
- * Save plugin options
200
+ * Save dashboard widget options.
198
201
*
199
202
* @since 1.4.0
200
- * @version 2017-01-10
203
+ * @sicnce 1.7.0 Renamed to _save_widget_options()
204
+ *
205
+ * @return void
201
206
*/
202
- private static function _save_options () {
207
+ private static function _save_widget_options () {
203
208
// Check the nonce field from the dashboard form.
204
209
if ( ! check_admin_referer ( 'statify-dashboard ' ) ) {
205
210
return ;
206
211
}
207
212
208
- // Get numeric values from POST variables.
209
- $ options = array ();
210
- foreach ( array ( 'days ' , 'limit ' ) as $ option_name ) {
211
- $ options [ $ option_name ] = Statify::$ _options [ $ option_name ];
212
- if ( isset ( $ _POST ['statify ' ][ $ option_name ] ) && (int ) $ _POST ['statify ' ][ $ option_name ] > 0 ) {
213
- $ options [ $ option_name ] = (int ) $ _POST ['statify ' ][ $ option_name ];
214
- }
213
+ // We only do a partial update, so initialize with current values.
214
+ $ options = Statify::$ _options ;
215
+
216
+ // Parse numeric "limit" value.
217
+ if ( isset ( $ _POST ['statify ' ]['limit ' ] ) && (int ) $ _POST ['statify ' ]['limit ' ] > 0 ) {
218
+ $ options ['limit ' ] = (int ) $ _POST ['statify ' ]['limit ' ];
215
219
}
216
- if ( ( int ) $ options ['limit ' ] > 100 ) {
220
+ if ( $ options ['limit ' ] > 100 ) {
217
221
$ options ['limit ' ] = 100 ;
218
222
}
219
223
220
- // Get checkbox values from POST variables.
221
- foreach ( array ( 'today ' , 'snippet ' , 'blacklist ' ) as $ option_name ) {
222
- if ( isset ( $ _POST ['statify ' ][ $ option_name ] ) && 1 === (int ) $ _POST ['statify ' ][ $ option_name ] ) {
223
- $ options [ $ option_name ] = 1 ;
224
- } else {
225
- $ options [ $ option_name ] = 0 ;
226
- }
224
+ // Parse "today" checkbox.
225
+ if ( isset ( $ _POST ['statify ' ]['today ' ] ) && 1 === (int ) $ _POST ['statify ' ]['today ' ] ) {
226
+ $ options ['today ' ] = 1 ;
227
+ } else {
228
+ $ options ['today ' ] = 0 ;
227
229
}
228
230
229
231
// Update values.
0 commit comments