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.
Thank you! You saved my life.
Very nice explanation.
You’re welcome :)
BTW, you don’t need to call
apply_filters('sanitize_option_' . $option_name, $_POST[$option]);
, because when callingupdate_site_option()
, this filter will also be called.you’re right, thanks :)
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.
Thanks for the info Alex, I will update the code when I have 5mn :)
Pingback: The wacky world of network activated WordPress plugins in multisite
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
Thanks Florian,
I think anything works, it just depends where you want to send people after they submitted the form :)
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).
correct, thanks :)
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: https://core.trac.wordpress.org/changeset/48477
Anyway, is this code working for others? I’ve hit a bit of a wall.
EDIT: Correction. This is working as-is. When trying to change the checkbox field to a text field, it doesn’t save.