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 use WordPress Multisite and made a plugin that adds columns with some data. My code is based on this WP Engineer article.

The key function in WordPress Multisite is manage_sites_custom_column. And the problem is that I want to be able to sort the column I created.

I tried the code in this Scribu's article but it is based on manage_posts_custom_column for single sites.

share|improve this question

1 Answer 1

I tried to solve this issue before. Taking a second look at it, we can alter the sites list using the query filter hook.

Supposing our custom sort URL is
http://example.com/wp-admin/network/sites.php?orderby=site_category

add_action( 'plugins_loaded', function()
{
    global $pagenow;
    if( 
        is_super_admin() 
        && 'sites.php' == $pagenow
        && isset( $_GET['orderby'] ) 
        && 'site_category' == $_GET['orderby'] 
    ) 
        add_filter( 'query', 'b5f_filter_site_query' );
});

function b5f_filter_site_query( $query )
{
    global $wpdb;
    if( FALSE !== strpos( $query, "SELECT * FROM {$wpdb->blogs} WHERE site_id = '1'  LIMIT 0, 20" ) )
        $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '1'  ORDER BY mature DESC LIMIT 0, 20";
    return $query;
}

Yes, I'm playing with the mature column. Probably, a refined SQL query could be made, but not my league... This column is a TINYINT(2). WordPress recognizes 0 and 1, leaving us with 98 options. In my case, enough to categorizing.

If mature > 1, the site is marked as such in site-info.php, but not in sites.php. I'm not really sure how being mature affects the site output.
A workaround to use the mature column liberally is to tell WordPress everything is ok, don't worry, outside the sites.php screen:

add_action( 'plugins_loaded', function()
{
    global $pagenow;
    if( 'sites.php' != $pagenow )
        add_filter( 'blog_details', 'b5f_hack_mature_queries' );

    # Hide the Mature checkbox in site-info.php
    add_action( 'admin_footer', 'b5f_print_sites_footer' );
});

function b5f_hack_mature_queries( $details )
{
    $details->mature = 0;
    return $details;
}

function b5f_print_sites_footer()
{
    if( 'site-info-network' != get_current_screen()->id )
        return;

echo <<<HTML
    <script type="text/javascript">
        jQuery(document).ready( function($) {
            $(".form-table").find("label:contains('Mature')").remove();
        });
    </script>
HTML;
}
share|improve this answer

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.