4

I want to add meta fields for the sites in my network (such as a thumbnail and a category). I know how to do this using get/add/update_site_option, but I'm wondering where I could put the UI to manage those meta fields.

The best place would be in the Sites > Infos page, just after the site attributes, but I can't find any hook to hang on. I can add those fields in the "Settings" tab of the same screen, but one has to scroll down a lot to find it, and it gets mixed with advanced settings.

Any suggestion ?

3 Answers 3

3

I finally found a way to add more lines to the Sites > Infos table : My own option in the Sites > Infos table

It's a little bit ugly, but it works. I simply use the action admin_footer to add a bunch of HTML code at the end of the page, and then use jQuery to move it to the right place.

add_action('admin_footer', 'user16975_custom_options');
function user16975_custom_options(){
    global $pagenow;
    if( 'site-info.php' == $pagenow ) {
        ?><table><tr id="user16975_custom_options">
            <th scope="row">My own option</th>
            <td><input type="text"/></td>
        </tr></table>
        <script>jQuery(function($){
            $('.form-table tbody').append($('#user16975_custom_options'));
        });</script><?php
    }
}

The good part is that as soon as the hook will be available, I can use it without big changes in my code.

6
  • 1
    It's simpler with global $pagenow; if( 'site-info.php' == $pagenow ) {}. . . . For the records, I just saw that Multilingual Press creates a new tab in that screen.
    – brasofilo
    Commented Jul 5, 2013 at 22:04
  • Thanks for the $pagenow tip @brasofilo, it's cleaner. Commented Jul 7, 2013 at 20:27
  • Multilingual Press is using the manage_sites_custom_column action to add a column to the sites table in sites.php page. I want to add a tab in the site-info.php page, where you can change the informations linked to one of the sites. Commented Jul 7, 2013 at 20:29
  • MLP has a tab in site-info.php, but I just checked and is injected with jQuery as well :/
    – brasofilo
    Commented Jul 10, 2013 at 20:47
  • 2
    How would you save the data along with the other fields on submit?
    – chris
    Commented Mar 10, 2014 at 23:33
3

First off all – I agreed, there is no specific hooks in this part of the core that allows to create custom setting fields there. But anyway it is possible.

WordPress has network_edit_site_nav_links filter hook which allows to create your custom tab.

But no hooks for the page for the new tab, but it is not a problem anyway because you can achieve the result with simple options page and a little CSS code.

In this tutorial everything is described by steps https://rudrastyh.com/wordpress-multisite/custom-tabs-with-options.html (I think it is no reason to copy all the code from there to this thread).

3
  • 1
    This is a great answer, but you should update your answer include the code here. We don't know how long your site will be around. Commented Feb 14, 2019 at 23:50
  • 2
    Misha's tutorial is excellent, the best example I've found. Commented Dec 21, 2022 at 19:58
  • 1
    😊 thank you! Actually I do not know how long my stackoverflow profile will be around. I received a warning a couple weeks ago. As for my site – it will be around as long as I am alive at least :) Commented Dec 23, 2022 at 9:14
0

The Site Info admin page's code is here: http://core.trac.wordpress.org/browser/trunk/wp-admin/network/site-info.php

Unfortunately, there don't appear to be any hooks or filters in the site-info.php code.

It looks like you'll have to make your own administrative page -- perhaps in the wp-admin Settings menu -- to handle your {$verb}_site_option code.

4
  • I want to have my options UI in the multisite administration zone, (wp-admin/network/...), not in each individual site dashboard. For example, that would be great to have the possibility to add a tab in the Sites > Infos page. Commented Jun 21, 2013 at 13:40
  • This might be what you're looking for then -- wordpress.stackexchange.com/questions/16474/… -- from the Related links on the right.
    – Pat J
    Commented Jun 21, 2013 at 13:45
  • Nope. The post you are linking is talking about the Settings main menu in the Network admin dashbord (wp-admin/network/settings). I'm talking about the page where you can modify individual site options in the Site main menu (wp-admin/network/site-info.php?id=X). Commented Jun 23, 2013 at 20:46
  • You might be out of luck, then.
    – Pat J
    Commented Jun 23, 2013 at 22:24

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.