Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When I use the settings API in a multisite installation and the options page sits at the network level, posting the options to options.php does not work, because the administration page sits at wp-admin/network and WP expects the page to be at wp-admin.

I added a function that checks whether this WP installation is a multsite installation (via the constant) and if it is, it changes the form's action value to ../option.php. This saves the options OK, but the default message "Settings saved." is missing (however, the query string does include settings-updated=true).

Any thoughts on how to get the message to appear?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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 page in network
wp_redirect(
    add_query_arg(
        array( 'page' => 'your_options_page_slug', 'updated' => 'true' ),
        (is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ))
    )
);
exit;

On the options page check $_GET['updated'], and add an admin notice if you found that parameter.

share|improve this answer
    
So the Settings API is not available on network admin pages? And what @NightHawk had originally done, was actually saving options to the main blog of the network and not saving them site-wide, right? –  Parham Jan 14 at 21:45
    
@Parham I haven’t seen his code, but I know most parts of the Settings API are either not available on network pages, or they behave in strange ways. There is no need to use that. –  toscho Jan 14 at 21:50
    
Can you please explain that network_admin_edit_XXX action? and the edit.php?action=XXX ? I do not understand it and don't see this anywhere documented. What is the reason for this? Can't I just register a page on network_admin_menu action and then do the saving and form output on the callback for that page/menu? Thanks! –  Parham Jan 14 at 22:00
    
@Parham Read the source code of wp-admin/network/edit.php or ask a new question. Comments are not made for that, and I will clean them up soon. –  toscho Jan 14 at 22:11

protected by Community Oct 6 at 9:27

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.