Prevent invalid or empty values from being saved to the database and retain the form field values upon error

You’d do it something like this: function sanitize_number_callback ($input){ if( !preg_match( ‘/…regex for valid here…/’, $input ) ){ add_settings_error( ‘my_option’, esc_attr( ‘my_option’ ), //becomes part of id attribute of error message __( ‘Number must be a positive integer’, ‘wordpress’ ), //default text zone ‘error’ ); $input = get_option( ‘my_option’ ); //keep old value } return … Read more

Checkbox conflict in my custom plugin admin page

you are registering two separate settings groups for setting fields & the problem might be here. function set_options() { register_setting( ‘checkbox-1-settings’, ‘my_checkbox_1_name’ ); register_setting( ‘checkbox-2-settings’, ‘my_checkbox_2_name’ ); } so use only one settings group for both fields to see if it works. function set_options() { register_setting( ‘checkbox-settings’, ‘my_checkbox_1_name’ ); register_setting( ‘checkbox-settings’, ‘my_checkbox_2_name’ ); } Update … Read more

Settings API with arrays example

Short answer: your name attribute values must use the schema option_name[array_key]. So, when you use … <input name=”option_name[key1]”> <input name=”option_name[key2]”> … you get an array as option value in your validation function: array ( ‘key1’ => ‘some value’, ‘key2’ => ‘some other value’ ) PHP does that for you, this is not a WordPress feature. … Read more

Cannot display settings field

Modifying form code with echo do_settings_sections(‘rma’) ? ‘something’ : ‘nothing’; renders nothing, so do_settings_sections(‘rma’) is empty. With that in mind, I dont see you adding a section in your posted code. If you add a section to your register_rma_settings() function, and than add this section to your add_settings_field(), than the input will show. function register_rma_settings() … Read more

Sections and tabs DRY – WordPress settings API

Well you could do something like this: Create an associative array for settings, then loop through them to create settings and sections for each field. $settings = array( ‘setting_1_id’ => array( ‘title’=>’First Box Settings’, ‘page’=>’first_box_option’, ‘fields’=> array( array( ‘id’=> ‘box_first_title’, ‘title’=>’Title’, ‘callback’=> ‘text_callback’ ), array( ‘id’=> ‘box_first_desc’, ‘title’=>’Description’, ‘callback’=> ‘textarea_callback’ ), array( ‘id’=> ‘box_first_link’, ‘title’=>’Link’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)