Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know that I can visit /wp-admin/options.php on a single install (or on a sub-site on a multisite install), and it will give me a formatted list of all of the options in the site's {prefix}opitions database table.

How can I achieve a similar list in the network dashboard for the {prefix}sitemeta table?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

There is no function for that. But you can use a custom SQL query like this …

SELECT meta_key, meta_value
    FROM $wpdb->sitemeta
    WHERE site_id = $wpdb->siteid
        AND `meta_key`  NOT  LIKE  '_site_transient%'
    ORDER BY meta_key

… to get all non-transient options.

Basic example:

/**
 * Plugin Name: T5 Multi-Site Options
 * Description: Add a page to show all network options.
 * Plugin URI:
 * Version:     2013.01.19
 * Author:      Thomas Scholz
 * Author URI:  http://toscho.de
 * Licence:     MIT
 * License URI: http://opensource.org/licenses/MIT
 * Network:     true
 */

add_action( 'network_admin_menu', array ( 'T5_MS_Options', 'register_admin_menu' ) );

class T5_MS_Options {

    public static function register_admin_menu()
    {
        return add_menu_page(
            'Network Options',
            'Network Options',
            'update_core',
            'network-options',
            array ( __CLASS__, 'render_page' )
        );
    }

    public static function render_page()
    {
        print '<h1>' . $GLOBALS['title'] . '</h1>';

        global $wpdb;

        $sql = "SELECT meta_key, meta_value
            FROM $wpdb->sitemeta
            WHERE site_id = $wpdb->siteid
                AND `meta_key`  NOT  LIKE  '_site_transient%'
            ORDER BY meta_key";

        $options = $wpdb->get_results( $sql );

        if ( ! $options )
            return print "<p>Error: Could not find anything.</p>";

        $header = '<tr><th>Key</th><th>Value</th><th>Serialized</th></tr>';
        print '<table class="widefat">';
        print "<thead>$header</thead>";
        print "<tfoot>$header</tfoot>";

        foreach ( $options as $option )
        {
            print '<tr><td>' . $option->meta_key . '</td><td><pre>';
            $serialized = FALSE;
            $val = maybe_unserialize( $option->meta_value );

            if ( $val !== $option->meta_value )
                $serialized = TRUE;

            print htmlspecialchars( print_r( $val, TRUE ), ENT_QUOTES, 'utf-8', FALSE );

            print '</pre></td><td>' . ( $serialized ? 'yes' : 'no' ) . '</td></tr>';

        }

        print '</table>';
    }
}
share|improve this answer
    
So there's no page built into core like wp-admin/options.php? –  bungeshea Jan 19 '13 at 3:39
    
@bungeshea I am not aware of such a page. –  toscho Jan 19 '13 at 3:49
    
@bungeshea, that's a matter of scanning * the folder /wp-admin/network/, but there's nothing there... * (that's how I found that /wp-admin/press-this.php works by its own) –  brasofilo Jan 19 '13 at 3:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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