Sanitize and Save metabox values
-
I am learning WordPress Plugin development. How to Sanitize and Save metabox values in WordPress Plugin ?
I am using below code.
//Filtering $fields = [ 'location_input' => FILTER_SANITIZE_STRING, 'temperature' => FILTER_SANITIZE_STRING, ]; // Save values foreach ( $fields as $field_name => $flag ) { if ( !empty( $field = filter_input( INPUT_POST, $field_name, $flag ) ) ) { update_post_meta( $post_id, $field_name, sanitize_text_field( $field ) ); } else { delete_post_meta( $post_id, $field_name ); } }
Is it enough to Sanitize and Save meta box values ?
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Sanitize and Save metabox values’ is closed to new replies.