Listing of all site options in dashboard

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>';
    }
}

Leave a Comment