From d18eba93107c6677ba3685ba602db17520347132 Mon Sep 17 00:00:00 2001 From: Atarime Date: Mon, 2 Dec 2024 14:07:23 +0900 Subject: [PATCH] Remove duplicate sanitization process --- admin/class-datasources.php | 17 ++++++----------- admin/class-settings.php | 12 ++++-------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/admin/class-datasources.php b/admin/class-datasources.php index b3e7e98..1a3f64e 100644 --- a/admin/class-datasources.php +++ b/admin/class-datasources.php @@ -293,12 +293,9 @@ private function save_post_meta( $post_id, $field_name ) { } if ( isset( $_POST[ $field_name ] ) ) { - $sanitized = sanitize_text_field( wp_unslash( $_POST[ $field_name ] ) ); - update_post_meta( $post_id, $field_name, $sanitized ); - } else { - if ( isset( $post_id ) ) { - delete_post_meta( $post_id, $field_name ); - } + update_post_meta( $post_id, $field_name, $_POST[ $field_name ] ); + } elseif ( isset( $post_id ) ) { + delete_post_meta( $post_id, $field_name ); } } @@ -375,7 +372,7 @@ private function save_post_meta_password( $post_id, $field_name ) { $form_value = ''; if ( isset( $_POST[ $field_name ] ) ) { - $form_value = sanitize_text_field( wp_unslash( $_POST[ $field_name ] ) ); + $form_value = $_POST[ $field_name ]; } else { return; } @@ -397,10 +394,8 @@ private function save_post_meta_password( $post_id, $field_name ) { // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions update_post_meta( $post_id, $field_name, base64_encode( $ciphertext ) ); - } else { - if ( isset( $post_id ) ) { - delete_post_meta( $post_id, $field_name ); - } + } elseif ( isset( $post_id ) ) { + delete_post_meta( $post_id, $field_name ); } } diff --git a/admin/class-settings.php b/admin/class-settings.php index 5051bfc..5d9d244 100644 --- a/admin/class-settings.php +++ b/admin/class-settings.php @@ -151,12 +151,9 @@ private function save_post_meta( $post_id, $field_name ) { } if ( isset( $_POST[ $field_name ] ) ) { - $sanitized = sanitize_text_field( wp_unslash( $_POST[ $field_name ] ) ); - update_post_meta( $post_id, $field_name, $sanitized ); - } else { - if ( isset( $post->ID ) ) { - delete_post_meta( $post->ID, $field_name ); - } + update_post_meta( $post_id, $field_name, $_POST[ $field_name ] ); + } elseif ( isset( $post->ID ) ) { + delete_post_meta( $post->ID, $field_name ); } } @@ -173,8 +170,7 @@ private function save_post_meta_checkbox( $post_id, $field_name ) { } if ( isset( $_POST[ $field_name ] ) ) { - $sanitized = sanitize_text_field( wp_unslash( $_POST[ $field_name ] ) ); - update_post_meta( $post_id, $sanitized, 1 ); + update_post_meta( $post_id, $_POST[ $field_name ], 1 ); } else { update_post_meta( $post_id, $field_name, 0 ); }