Tag Info

Hot answers tagged

16

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 ...


14

if you look at the do_settings_sections function more specifically the line 1164 where the callback function is being executed : call_user_func($section['callback'], $section); you can see that the $section array is being passed to the callback function, so you can identify the callback by the $section['id'] hope this make since. Update here is an ...


12

The premise of the question is flawed. The Customizer API is not an options API, but rather an options preview API. The Customizer API relies on either the Settings API or the Theme Mods API to register controls for existing settings added via either of the two APIs. The Customizer does not - and cannot - define/register new settings that have not already ...


7

You're absolutely right that you can pass reusable form field markup to add_settings_field(). The trick is to define the data type for each setting, and then pass the same callback to each call to add_settings_field(). Within that callback, you simply add a switch that includes cases for each data type. Here's how I do it in Oenology: First, I dynamically ...


7

WordPress will not do any data sanitization for you. It does do sanitization/validation of the default options. You have to pass in the third argument of register_setting and either role your own validation callback or or use one of the builtins. If your options is only going to contain a string, you could do something like this, for instance. <?php ...


6

For network option pages the correct form action URL is: wp-admin/network/edit.php?action=your_option_name Then you have to register a callback: add_action( 'network_admin_edit_your_option_name', 'your_save_network_options_function' ); In that callback function inspect the $_POST data, prepare the values, then save them: update_site_option( ...


6

If there is problem only with html markup you should check example from official jQuery UI site here: http://jqueryui.com/tabs/ It looks like yours, but for work you must check if your site include stuff like jquery and jquery ui script, jquery css is important too. After that you should have script with: $( "#tabs" ).tabs(); And everything should work ...


6

That's because your options are stored as a serialised array, in one row with name XX_theme_settings. To update one option, you would still need to retrieve the existing settings, ammend the appropriate value and update all options in your array together. For example: $my_options= get_option('XX_theme_settings');//retrieve all options ...


6

There are several components to error/notice creation and display process: add_settings_error() call to add item to stack (global $wp_settings_errors variable). settings_errors transient that keeps the errors so they survive move from page to page. settings_errors() function get_settings_errors() to retrieve errors from memory or transient and then ...


6

If you wrote your code correctly, then delete_option would be the correct way. The question isn't how to clear the option; the question is how to structure your code such that the "option does not exist" case is a valid case. Think about it. The first time you start this code, that option isn't going to exist at all, right? Your code should be perfectly ...


6

My point of view is that main purpose and benefit of Settings API is structure. It helps to keep complex settings setups: orderly (logic of registration and sections); secure (nonces, validation callbacks); extensible (hooking into another page or allowing to be hooked into). As with any such structural overhead it benefits more complex use cases and ...


5

If you use callbacks properly, there's no need for all the redundant code. Here's how I implement the Settings API, in a way that is completely scalable. Advantages (among other things): The Settings API forces sanitization of untrusted user data. The Settings API forces options to be registered as an options array, resulting in a single wp_options DB ...


5

Why does the Settings API send those parameters when submitting the settings form? Quite frankly, it doesn't. As you already mentioned, your form simply POST's to options.php, which in turn handles the request, updates the database, and then redirects back to the referer. How the referer is fetched is down to the function wp_get_referer(); function ...


5

You need to add a name attribute to your editors. The name attribute needs to be set to the value of of your option, so like this: function us_partners_cb() { $us_partners_desc = get_option( 'us_partners_desc' ); echo wp_editor( $us_partners_desc, 'uspartnersdesc', array('textarea_name' => 'us_partners_desc') ); }


5

You have to call add_settings_section() first, pass a unique ID and assign it to the page (poor name) discussion: add_settings_section( 'ads_id', 'Extra Settings', 'ads_description', 'discussion' ); Then register a callback to save your field(s) … // Register a callback register_setting( 'discussion', 'ads', 'trim' ); … and then register ...


4

As simple as things can sometimes be: The Settings API is not the Theme Customizer. Both are different things for different tasks. Settings API You're either writing a plugin or have a theme that doesn't have options that won't need any visual feedback? Go with this option. Theme Customizer You need to have options that have a visual impact that the user ...


4

You need to pass last parameter $args, if you want add_settings_field to output <label> use `label_for' argument, see code snippet below <?php add_settings_field( 'my-id', 'Test Filed', 'mamaduka_test_field', 'general', 'my-section', array( 'label_for' => 'my-test-field' ) ); ?>


4

The reason is that if you are on page 1, the data that is posted to be saved is an array of the form: XX_theme_settings=array('XX_Option1' =>'input1','XX_Option2'=>'input2',...) and contains no data from page 2. This is because the input from page 2 is not posted with it (since it wasn't in the same <form> - it's not on the page). Thus when ...


4

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]" ...


3

I wrote a tutorial for Incorporating the Settings API in WordPress Themes. The only real difference for Plugins is that you'll use add_settings_page() instead of add_theme_page(). The rest should pretty much be the same.


3

There is an other good tutorial at WPTuts+: Using The Settings API. Part 1 – Create A Theme Options Page If you create your own themes you will, sooner or later, want to allow your theme users have some control over certain appearance and/or functional elements of your theme. When this time comes you will want to use the powerful WordPress Settings ...


3

If the setting in question is $setting, and is a checkbox type, you validate it like so: <?php $valid_input[$setting] = ( isset( $input[$setting] ) && true == $input[$setting] ? true : false ); ?> In this case, $input is the form data passed to the validation callback, where $input is an array-of-arrays. The validation method is known as ...


3

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 wasn't sent. Normally this would be because the user has deliberately ...


3

I know this is an old question but I'll throw my two cents in, just in case someone else comes along; a simpler way to do so would be do write you own modification of the add_settings_section() function, which would only add a callback args parameter at the end of it. This would look like this ( or something like it ) function my_add_settings_section($id, ...


3

On your tccl_settings_option_validate function you need to: get an array of all existing options. update only the changed. return that array. so something like: function tccl_settings_option_validate( $input ) { //do regular validation stuff //... //... //get all options $options = get_option(THEMENAME . '_settings'); //update only the neede options ...


3

You don’t. You would have to keep your new page in sync with the core file each time WordPress is updated … that would not be very pragmatic. Hook into the do_settings_sections('general'); with register_setting() and add your code here. There is a third parameter for register_setting(): you can register a callback function here which used before the value ...


3

What you need to do is build your own data validation function. Ozh wrote a great tutorial about this earlier, but here's the gist of it ... Assume your options array is called $my_options and it contains three fields, 'text', 'age', and 'isauthorized'. You would still register it the same way: register_setting( 'my_setting', 'my_options', ...


3

Do you want to unset just one option, or do you want to unset every option in the array? If it's the former: $tccl_domains = get_option( 'tccl_settings_domains' ); $tccl_domains['option_to_unset'] = false; update_option( 'tccl_settings_domains', $tccl_domains ); If it's the latter: $tccl_domains = get_option( 'tccl_settings_domains' ); foreach( ...


3

You need a second form with admin_url('admin-post.php') as form action. Then you can hook into admin_post_custom_action to execute your action. Sample code: add_action( 'admin_post_wpse_79898', 'wpse_79898_test' ); function wpse_79898_test() { if ( isset ( $_GET['test'] ) ) echo esc_html( $_GET['test'] ); die( __FUNCTION__ ); } In your ...


3

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 ...



Only top voted, non community-wiki answers of a minimum length are eligible