Settings API in Multisite – Missing update message

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( $this->option_name, $this->option_values ); And then you have to create the redirect without further help: // redirect to settings … Read more

How can I save a multiple select array with the settings API for a plug-in options page?

So, it looks like two things are going on here: echo “<select id=’$id’ style=”width:15em;height:10em;” class=”select$field_class” name=”” . $buddha_option_name . “[$id]” multiple>”; As noted by @Radek, you could have made the name of the select box an array by using [] – e.g. name=”my_option_name[]” – this will result in the filed $_POST[‘my_option_name’] being an array of … Read more

Trigger custom action when setting button pressed

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 settings page: <form action=”<?php echo admin_url( ‘admin-post.php’ ); ?>”> … Read more

Run function AFTER theme options are saved?

Use the filter update_option_{$option}. It runs after a successful saving. $option is the name of your option, and you get the old and the new value as parameters. From wp-includes/option.php: do_action( “update_option_{$option}”, $oldvalue, $_newvalue ); Use it like this for an option wpse_themesettings: add_action( ‘update_option_wpse_themesettings’, ‘wpse_check_settings’, 10, 2 ); function wpse_check_settings( $old_value, $new_value ) { … Read more

How to pass variable to add_settings_section() callback?

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 example, if … Read more

Is get_option function cached?

When in doubt, look at the source code. Digging in to get_option(), you’ll see (abbreviated): $value = wp_cache_get( $option, ‘options’ ); if ( false === $value ) { $row = $wpdb->get_row( $wpdb->prepare( “SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1”, $option ) ); // Has to be get_row instead of get_var because of … Read more

How to pass arguments from add_settings_field() to the callback function?

Look at the declaration for the function: function add_settings_field( $id, $title, $callback, $page, $section = ‘default’, $args = array() ) { } The last parameter takes your arguments and passes them to the callback function. Example from my plugin Public Contact Data foreach ($this->fields as $type => $desc) { $handle = $this->option_name . “_$type”; $args … Read more

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