I think you’ve way over-complicated things. Assuming private
is a checkbox, just check for it being set, and act accordingly. With form $_POST
data, a checkbox will send its value if checked, and will send nothing if not checked:
if ( isset( $_POST['private'] ) ) {
update_comment_meta( $comment_id, 'private', 'private' );
} else {
delete_comment_meta( $comment_id, 'private', 'private' );
}
Note that, since a checkbox is binary (checked/unchecked), you can hard-code the value into your update_comment_meta()
call, thereby inherently sanitizing the user input.