wordpress settings API and option array structure

The Settings API generally expects data in the key => value form. I’m sure it is possible to save array data using the Settings API, but it somewhat circumvents the purpose of the API. If I’m understanding your question correctly, you’re trying to take a Plugin Option, and use the value of that option to … Read more

Persist fields with Setting API

This a really good question – my suggestion is to use transients. For instance, in your validation callback: wpse51669_validation_cb($settings){ //Perform validation checks if( $valid ){ //If settings validate return $validate_settings; } //Otherwise add settings error add_settings_error(‘my-plug-in-settings’,’error-with-xyz’, ‘I fell over’,’error’); //And add the failed settings to a transient set_transient( ‘my-plug-in-settings-invalid’, $settings, 60); return false; } Then … Read more

settings API: how to create a multi checkbox with blog categories?

I had the same problem, and here what works for me: function journal_check_cats_callback() { $options = get_option(‘journal_theme_blog_2_col’); $pag = journal_theme_blog_2_col; $_cats = get_terms( ‘category’ ); $html=””; foreach ($_cats as $term) { $checked = in_array($term->term_id, $options) ? ‘checked=”checked”‘ : ”; $html .= sprintf( ‘<input type=”checkbox” id=”%1$s[%2$s]” name=”%1$s[]” value=”%2$s” %3$s />’, $pag, $term->term_id, $checked ); $html .= … Read more

Can I use the different settings sections over different pages using the save options group?

The solution is to merge existing options before saving options in case not all options are presented on the page we are about save. So in the end of $sanitize_callback in register_setting function just before I return the data I call below function where $existing are all existing options saved in database. function merge_options( $existing, … Read more

When should I call add_settings_section and add_settings_field?

You can call add_settings_section and add_settings_field any time before you do_settings_sections: add_action( ‘my_plugin_add_settings_sections’, function() { wp_remote_get( … ); add_settings_section( … ); add_settings_field( … ); }); // On the plugin settings page output do_action( ‘my_plugin_add_settings_sections’ ); do_settings_sections( … ); You’ll still want to register_setting() earlier though because that custom hook won’t be fired when your settings … Read more

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