First, template_redirect
is a front end hook. It never fires on your backend save. You need to choose a backend hook such as admin_init
to hook your function.
Secondly, based on your pastebin from you other question, your code has the checked
attribute hard-coded for both of your radio boxes, thus causing it to default to the last one all the time. You are going to want to edit your form like so:
<input type="radio" <?php checked($this->data, 1); ?> value="1" name="selection" >
Third, you need to make sure that both of your radio buttons have a value
attribute.
Fourth, you need to update the option when you save so…
public function on_admin_form_submit() {
if ( isset( $_POST['selection'] ) ) {
if ($_POST['selection'] == 1){
update_option( 'where_to_log_to', 1 );
} else {
update_option( 'where_to_log_to', 2 );
}
}
$this->data = get_option( 'where_to_log_to', 1 );
}
Notice that I explicitly saved the values 1 and 2.
I think that’s got it.