From 6a67582e42c56cbdd5237175b81a819ae64298c2 Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Thu, 22 Jun 2023 23:44:14 +0300 Subject: [PATCH] - wpcs for `load_field_order()`; --- includes/admin/core/class-admin-dragdrop.php | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/includes/admin/core/class-admin-dragdrop.php b/includes/admin/core/class-admin-dragdrop.php index b135b91c..b6614b70 100644 --- a/includes/admin/core/class-admin-dragdrop.php +++ b/includes/admin/core/class-admin-dragdrop.php @@ -35,18 +35,19 @@ if ( ! class_exists( 'um\admin\core\Admin_DragDrop' ) ) { */ public function update_order() { UM()->admin()->check_ajax_nonce(); + // phpcs:disable WordPress.Security.NonceVerification -- already verified here if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) { wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) ); } - /** - * @var $form_id - */ - extract( $_POST ); + if ( empty( $_POST['form_id'] ) ) { + wp_send_json_error( __( 'Invalid form ID.', 'ultimate-member' ) ); + } - if ( isset( $form_id ) ) { - $form_id = absint( $form_id ); + $form_id = absint( $_POST['form_id'] ); + if ( empty( $form_id ) ) { + wp_send_json_error( __( 'Invalid form ID.', 'ultimate-member' ) ); } $fields = UM()->query()->get_attr( 'custom_fields', $form_id ); @@ -71,12 +72,11 @@ if ( ! class_exists( 'um\admin\core\Admin_DragDrop' ) ) { // adding rows if ( 0 === strpos( $key, '_um_row_' ) ) { - $update_args = null; $row_id = str_replace( '_um_row_', '', $key ); - if ( strstr( $_POST[ '_um_rowcols_' . $row_id . '_cols' ], ':' ) ) { + if ( false !== strpos( $_POST[ '_um_rowcols_' . $row_id . '_cols' ], ':' ) ) { $cols = sanitize_text_field( $_POST[ '_um_rowcols_' . $row_id . '_cols' ] ); } else { $cols = absint( $_POST[ '_um_rowcols_' . $row_id . '_cols' ] ); @@ -105,7 +105,6 @@ if ( ! class_exists( 'um\admin\core\Admin_DragDrop' ) ) { } $fields[ $key ] = $row_args; - } // change field position @@ -160,16 +159,16 @@ if ( ! class_exists( 'um\admin\core\Admin_DragDrop' ) ) { update_option( 'um_form_rowdata_' . $form_id, $this->row_data ); UM()->query()->update_attr( 'custom_fields', $form_id, $fields ); + // phpcs:enable WordPress.Security.NonceVerification -- already verified here } /** * Load form to maintain form order. */ public function load_field_order() { - $screen = get_current_screen(); - if ( ! isset( $screen->id ) || 'um_form' !== $screen->id ) { + if ( ! isset( $screen, $screen->id ) || 'um_form' !== $screen->id ) { return; } ?>