Configuration API – How to save the checkbox options on the add-ons options page


First of all: I am really a newbie. So I used a template for my options page and tried to customize it (so far it works pretty well).

About my complement:
Create to post types and some meta boxes within them. The meta boxes have some fields and saving fields works quite well so far.

Now I get to the point, where I want my options not only to be shown on the options page, but to save the entered values.

I try it with a "brief excerpt" because all other options work the same way.


  

"; } function field_1_2_callback() { $settings = (array) get_option( 'my-plugin-settings' ); $field = "field_1_2"; $value = esc_attr( $settings($field) ); echo ""; } function field_1_3_callback() { $settings = (array) get_option( 'my-plugin-settings' ); $field = "field_1_3"; $value = esc_attr( $settings($field) ); echo ""; } function field_1_4_callback() { $settings = (array) get_option( 'my-plugin-settings' ); $field = "field_1_4"; $value = esc_attr( $settings($field) ); echo ""; } function my_settings_validate_and_sanitize( $input ) { $settings = (array) get_option( 'my-plugin-settings' ); if ( $some_condition == $input('field_1_1') ) { $output('field_1_1') = $input('field_1_1'); } else { add_settings_error( 'my-plugin-settings', 'invalid-field_1_1', __('Error in Field "Enable Food Post Type"', 'nutriplus'), 'error' ); } if ( $some_condition == $input('field_1_2') ) { $output('field_1_2') = $input('field_1_2'); } else { add_settings_error( 'my-plugin-settings', 'invalid-field_1_2', __('Error in Field "Enable Nutritional Information Meta Box"', 'nutriplus'), 'error' ); } if ( $some_condition == $input('field_1_3') ) { $output('field_1_3') = $input('field_1_3'); } else { add_settings_error( 'my-plugin-settings', 'invalid-field_1_3', __('Error in Field "Enable Additional Information Meta Box"', 'nutriplus'), 'error' ); } if ( $some_condition == $input('field_1_4') ) { $output('field_1_4') = $input('field_1_4'); } else { add_settings_error( 'my-plugin-settings', 'invalid-field_1_4', __('Error in Field "Enable Diet Post Type"', 'nutriplus'), 'error' ); } return $output; }
  1. I don't know if check boxes need sanitze or validate …
  2. I don't know how to save the current value and, of course, load the default value. I found examples with php functions instead of value = "xxx", but I don't know how to include this
  3. And yes … I know … the marked attribute should not be there when the current value should appear 🙂

Maybe someone can help me