25

I'm working on a plugin that will be installed in a multisite instance.

How do I create a single settings page that is visible at the "Network admin" level only - most of the guides i've seen relate to a standard blog level plugin. Any links to information would be useful, otherwise I'll just end up going through sitewide tags to see how it's being done there.

[Update]

Looks like sitewide_tags uses add_site_option, get_site_option and update_site_option, and these functions use wp_sitemeta. However, from what I can see, there's no support for register_setting, add_setting, etc, so you have to get and set your options manually.

4 Answers 4

6

As a reference

To create network or global settings, you need to do the following

  • Add a settings page

    add_submenu_page( 'settings.php'... # cf options.php for blog level`
    
  • Add a global option

    add_site_option($key,$value)
    
  • Update a global option

    update_site_option($key,$value)
    
  • Get a site option

    get_site_option($key)
    

Global settings are saved to the sitemeta table (individual blog settings are saved to <blog_id>_options table

  • I think the Settings API functions at the blog level - so uses the options table, not sitemeta. So, you can't use option groups and the like at the network level (please comment if I've got this wrong)
0

Well, I faced the same need recently, but didn't know the answer either. While not an answer to your question explicitly, an alternative is to just create the options pages under the 'main' blog's options and check if multisite is enabled.

Not the ideal way, but if (like me) you were just creating an internal plugin for your own use, it is workable. It also has the advantage that all the usual functions for admin pages are available - which they aren't yet in the global network admin page context.

0
0

When you use add_submenu_page(), add_menu_page() etc and expect the settings pages to appear in your multisite dashboard, consider using network_admin_menu hook instead of admin_menu

Example:

add_action( 'network_admin_menu', 'network_settings_page' );
function network_settings_page(){
    add_submenu_page(

        ...
    )
}

To save settings you can use network_admin_edit_{ACTION} action hook.

Reference: https://rudrastyh.com/wordpress-multisite/custom-tabs-with-options.html

0

If you're just looking to show the menu item in the Network Admin area, for the main blog site (blog ID 1), you can just set your form to this HTML to save to normal blog 1 options (but also show settings page from Multisite area):

<form method="post" action="<?php echo admin_url('/options.php'); ?>">

When you output the form for your settings page. It won't show any kind of notice that the settings are updated -- but they will be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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