• I’m trying to add a sub-menu to the Settings list in Network Admin, and the Otto’s tutorial for doing it on a sub-site doesn’t work; I’ve gotten as far as getting add_submenu_page (add_options_page equivalent in sub-site) to show the option but the subsequent functions I got from the tutorial don’t work and the Codex documentation is inaccurate (for instance, I had to use settings.php for parent_slug instead of options-general.php as specified).

    None of the register_setting or add_settings_section or add_settings_field show anything on the actual page.

Viewing 8 replies - 1 through 8 (of 8 total)
  • This is what I use to add to the Network->Settings menu – http://codex.wordpress.org/Function_Reference/add_submenu_page

    function ush_network_pages() {
            add_submenu_page('settings.php', 'Shib Hostnames', 'Shib Hostnames', 'manage_options', 'ush_hostnames_admin', 'ush_hostnames_admin');
    }
    add_action( 'network_admin_menu', 'ush_network_pages' );
    
    function ush_hostnames_admin() {
    // add menu code here
    }

    I dont have an example, but if you want your own menu category, e.g. Network->MyMenu – http://codex.wordpress.org/Function_Reference/add_menu_page

    Thread Starter davehprohoods

    (@davehprohoods)

    Thanks, I gathered that much, but that requires me building all of the HTML for the page instead of using WordPress’ built-in code which comes from the register_setting and add_settings_field functions… are there functions like this that work for the network admin portal? I’m surprised they don’t work the same for both portals.

    I believe those functions should work. I think you did something wrong or you are missing something. Maybe if you showed some of your code. My guess is you are missing one of the initial add_actions – something like this:
    add_action(‘admin_init’, ‘plugin_admin_init’);

    Thread Starter davehprohoods

    (@davehprohoods)

    I tried the functions and the tutorial link you referenced esmi is the “Ott’s tutorial” I mentioned. It doesn’t work with network admin, but I’ll try again and post the code here if it doesn’t work.

    Thread Starter davehprohoods

    (@davehprohoods)

    OK I just copied and pasted Ott’s code to a new plugin, and it only adds the options to the sub-sites’ Settings, not to the Network Admin Settings. Apparently I have to use separate functions, though it’s just not clear in WordPress documentation and I’m not finding any tutorials for it. I’d prefer not to have to make my own HTML (or copy it from a formatted page), but I noticed the Domain Mapping plugin does it, so I’ll just do it that way.

    Thread Starter davehprohoods

    (@davehprohoods)

    One concern with this is that the nonce and security code is not automatically generated… and I’m not sure how to properly handle it from the form. The Domain Mapping plugin just spits out a form with no action and no nonce or security (except for a hidden value)… so I have no clue as a WordPress newb what I’m doing right or wrong here.

    > OK I just copied and pasted Ott’s code to a new plugin, and it only adds the options to the sub-sites’ Settings, not to the Network Admin Settings.

    Yes, because that is what the tutorial is for. If you want to add it to the Network Admin, do as I instructed above. So instead of Otto’s tutorial of:

    add_action('admin_menu', 'plugin_admin_add_page');

    replace with this for Network admin menu:

    add_action( 'network_admin_menu', 'plugin_admin_add_page' );
    function plugin_admin_add_page () {
    add_submenu_page('settings.php',...
    }

    > I’d prefer not to have to make my own HTML

    I believe the settings_fields() and do_settings_sections()should work and do some of the work for you. Sorry I have not tried those setting myself. I prefer to code the html as that gives a lot more flexibility in presentation.

    > The Domain Mapping plugin just spits out a form with no action and no nonce or security

    Of all the plugins I have seen, this is true in most cases. Only admins or superadmins can call these (plugin) functions. You would have a lot other concerns if someone had access as a (super)admin; a nonce would be the least of your concerns. But I definitely see adding a nonce as added protection.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Tutorial for creating Network Admin Settings page?’ is closed to new replies.