Flush rewrite rules on option update with Settings API

I register custom post type on init action and the validate which I’m writing about is set to register_setting inside admin_init action. This is the key to your issue. You’re registering the custom post type, and presumably you’re setting up the rewrite rules in that registration. When you call flush_rewrite_rules(), the rules are rebuilt right … Read more

How is a widget supposed to reference what is added to custom submenu or addmenu fields?

The setting API, which its usage is being demonstrated in that code is meant to be use as a framework to create settings pages which result in update of values in options. Widget settings are is a somewhat more abstract level. They are stored in options, but there is no flexibility how they are stored, … Read more

When should I use register_setting() and add_settings_field()

It seems logic to think that it’s enough to use add_settings_field() Yes, it seems so, but it’s really not enough: register_setting() whitelists the database option for a specific setting which then allows the option to be saved and updated automatically on the wp-admin/options.php page. Note that by “option”, I’m referring to the second parameter for … Read more

Settings API validation callback

If you have an options page (which should be inside one form), then all data is sent from that form, regardless of whether or not the option has been changed. The array received for validation is the data received from (your part of) the form. If the data is ’empty’ it is because the data … Read more

Settings API – getting hidden input / submit button’s name

Using $_POST is too low level. Simply give it the same name as your other options. When you options are displayed they should have the names of the form: my_settings[a_particular_option]. For instance: <input name=”my_settings[some_input_option]”/> Then for your hidden input and submit button: <input type=”hiddden” name=”my_settings[foo]” value=”bar”/> <input name=”my_settings[SubmitButton]” type=”submit” class=”button-primary” value=”<?php _e(‘Save Changes’); ?>”/> In … Read more

How to create a WordPress options page

The first thing that jumps out at me is your use of register_setting(): register_setting( ‘bang-options-group’, ‘joinform_api_url’ ); It is missing a critical, third argument: the sanitization callback. While this parameter programmatically is optional, without it, you cannot validate/sanitize/whitelist the data values passed to the DB via your settings form. Looking further at your code, you … Read more

Settings API – save multiple tabs at once

Don’t initialize defaults, or do an initial save. Just use sane defaults. For example, define an array of defaults: function wpse92323_get_option_defaults() { $defaults = array( ‘slug1’ => ‘default1’, ‘slug2’ => ‘default2’ ); return apply_filters( ‘wpse92323_option_defaults’, $defaults ); } Then, write a function to return an option value, that parses stored options against your defaults: function … Read more

Change the display of Settings API (do_settings_sections)

There are no hooks to modify the output of do_settings_sections(). Hence the only option you have is to write custom versions of the functions do_settings_sections() and do_settings_fields(). They are located in /wp-admin/includes/template.php, lines 1159-1174 and 1190-1207 (wordpress version 3.2.1), respectively (do not modify them there). You could (not saying it is necessarily advisable, consider compatibility … Read more

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