Using the WordPress Settings API with Network Admin pages

The other day I was googling up information about coding options pages in the network administration dashboard of a WordPress multisite installation and I noticed that some people think they cannot use the Settings API with those pages. I also noticed there was no article showing how to do it, so here it is.

Following is the documented code you need to create a network options page using the WordPress Settings API. You can also go to GitHub and download a fully functional plugin that demonstrates that code, I added a normal options page in the plugin so that you can compare the code.

If you have any remark or question just use the comment section.

Image Credits: Antonio Ruiz García

13 thoughts on “Using the WordPress Settings API with Network Admin pages

      1. Asu

        BTW, you don’t need to call apply_filters('sanitize_option_' . $option_name, $_POST[$option]);, because when calling update_site_option(), this filter will also be called.

  1. Alex Georgiou

    Thank you so much, your code worked perfectly!

    I just want to say for the benefit of anyone else reading this that I am using WordPress 4.8 and I had to change the redirect target from settings.php to admin.php.

  2. Pingback: The wacky world of network activated WordPress plugins in multisite

  3. Florian

    Hi Claude,

    thanks for the really helpful post! :)

    Regarding the redirect target: For me it works great with settings.php also in 4.8.


  4. Patrick

    Your `add_filter(‘network_admin_menu’, ‘post3872_network_admin_menu’);` line should probably be `add_action(‘network_admin_menu’, ‘post3872_network_admin_menu’);` (since you’re not filtering anything).

  5. Nick

    Still working through trying to get this working. So far, it doesn’t seem that the options are saving.

    Side note: As part of working through this, I noticed that core changed `$new_whitelist_options` to `$new_allowed_options` here:

    Anyway, is this code working for others? I’ve hit a bit of a wall.

    1. Nick

      EDIT: Correction. This is working as-is. When trying to change the checkbox field to a text field, it doesn’t save.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.