Skip to content

Commit aefc0c4

Browse files
committed
Use variables a little more safely
1 parent 4479103 commit aefc0c4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

inc/admin/namespace.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,16 @@ function render_edit_page() {
270270

271271
// Handle form submission
272272
$messages = [];
273-
if ( ! empty( $_POST['submit'] ) ) {
273+
$form_data = [];
274+
if ( ! empty( $_POST['_wpnonce'] ) ) {
275+
if ( empty( $consumer ) ) {
276+
check_admin_referer( 'rest-oauth2-add' );
277+
} else {
278+
check_admin_referer( 'rest-oauth2-edit-' . $consumer->get_post_id() );
279+
}
280+
274281
$messages = handle_edit_submit( $consumer );
282+
$form_data = wp_unslash( $_POST );
275283
}
276284
if ( ! empty( $_GET['did_action'] ) ) {
277285
switch ( $_GET['did_action'] ) {
@@ -291,9 +299,9 @@ function render_edit_page() {
291299

292300
$data = [];
293301

294-
if ( empty( $consumer ) || ! empty( $_POST['_wpnonce'] ) ) {
302+
if ( empty( $consumer ) || ! empty( $form_data ) ) {
295303
foreach ( [ 'name', 'description', 'callback', 'type' ] as $key ) {
296-
$data[ $key ] = empty( $_POST[ $key ] ) ? '' : wp_unslash( $_POST[ $key ] );
304+
$data[ $key ] = empty( $form_data[ $key ] ) ? '' : $form_data[ $key ];
297305
}
298306
} else {
299307
$data['name'] = $consumer->get_name();

0 commit comments

Comments
 (0)