Skip to content

Commit

Permalink
Merge pull request #19 from atarime/remove-duplicate-sanitization-pro…
Browse files Browse the repository at this point in the history
…cess

Remove duplicate sanitization process
  • Loading branch information
kznakata authored Dec 5, 2024
2 parents 5ee5e96 + d18eba9 commit 78aea34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
17 changes: 6 additions & 11 deletions admin/class-datasources.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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 );
}
}

Expand Down
12 changes: 4 additions & 8 deletions admin/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand All @@ -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 );
}
Expand Down

0 comments on commit 78aea34

Please sign in to comment.