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

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

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

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

    Cheers,
    Florian

    Reply

Leave a Reply

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