@@ -126,18 +126,21 @@ public function form( $instance )
126
126
'title ' => $ this ->get_field_id ( 'title ' ),
127
127
'title_plural ' => $ this ->get_field_id ( 'title_plural ' ),
128
128
'layout ' => $ this ->get_field_id ( 'layout ' ),
129
+ 'nonce ' => $ this ->get_field_id ( 'nonce ' ),
129
130
),
130
131
'names ' => array (
131
132
'title ' => $ this ->get_field_name ( 'title ' ),
132
133
'title_plural ' => $ this ->get_field_name ( 'title_plural ' ),
133
134
'layout ' => $ this ->get_field_name ( 'layout ' ),
135
+ 'nonce ' => $ this ->get_field_name ( 'nonce ' ),
134
136
),
135
137
'values ' => array (
136
138
'title ' => $ titleSingle ,
137
139
'title_plural ' => $ titlePlural ,
138
140
'layout ' => $ layout ,
139
- ),
140
- 'layouts ' => apply_filters ( 'pp_multiple_authors_author_layouts ' , array () ),
141
+ 'nonce ' => wp_create_nonce ('pp_multiple_authors_widget_form ' ),
142
+ ),
143
+ 'layouts ' => apply_filters ( 'pp_multiple_authors_author_layouts ' , array () ),
141
144
);
142
145
143
146
$ container = Factory::get_container ();
@@ -151,19 +154,23 @@ public function form( $instance )
151
154
* @param array $new_instance The new options
152
155
* @param array $old_instance The previous options
153
156
*/
154
- public function update ( $ new_instance , $ old_instance )
157
+ public function update ($ new_instance , $ old_instance )
155
158
{
159
+ if (! isset ($ new_instance ['nonce ' ]) || ! wp_verify_nonce ($ new_instance ['nonce ' ], 'pp_multiple_authors_widget_form ' )) {
160
+ return $ old_instance ;
161
+ }
162
+
156
163
$ legacyPlugin = Factory::getLegacyPlugin ();
157
164
158
- $ instance = array () ;
165
+ $ instance = [] ;
159
166
160
167
$ instance ['title ' ] = sanitize_text_field ($ new_instance ['title ' ]);
161
168
$ instance ['title_plural ' ] = isset ($ new_instance ['title_plural ' ]) ? sanitize_text_field ($ new_instance ['title_plural ' ]) : '' ;
162
169
$ instance ['layout ' ] = sanitize_text_field ($ new_instance ['layout ' ]);
163
170
164
- $ layouts = apply_filters ( 'pp_multiple_authors_author_layouts ' , array () );
171
+ $ layouts = apply_filters ('pp_multiple_authors_author_layouts ' , [] );
165
172
166
- if ( ! array_key_exists ( $ instance ['layout ' ], $ layouts ) ) {
173
+ if (! array_key_exists ($ instance ['layout ' ], $ layouts) ) {
167
174
$ instance ['layout ' ] = $ legacyPlugin ->modules ->multiple_authors ->options ->layout ;
168
175
}
169
176
0 commit comments