• Resolved webraket

    (@webraket)


    I’m writing a plugin to display a sortable column on wp-admin/network/sites.php

    <?php
    /*
    Plugin Name: MultiSite SpamColumn
    */
    
    class MultiSiteSpamColumn{
    
    	function init(){
    		if(($_SERVER['PHP_SELF']=='/wp-admin/network/sites.php') && (is_super_admin())){
    			add_filter( 'wpmu_blogs_columns', array('MultiSiteSpamColumn','register_column') );
    			add_action( 'manage_sites_custom_column', array('MultiSiteSpamColumn','display_field'), 10, 2 );
    			add_filter( 'manage_sites-network_sortable_columns', array('MultiSiteSpamColumn','register_sortable_column') );
    		}
    	}
    
    	function register_column( $columns ) {
    		$columns[ 'spam' ] = __( 'Spam' );
    		return $columns;
    	}
    
    	function display_field( $column, $blogid ) {
    		if ( $column == 'spam' ) {
    			echo get_blog_status( $blogid, 'spam');
    		}
    	}
    
    	function register_sortable_column( $columns ) {
    		$columns[ 'spam' ] = 'spam';
    		return $columns;
    	}
    
    }
    add_filter( 'init' , array('MultiSiteSpamColumn','init') );
    ?>

    The sortable field finaly shows up, however results are not sorted yet.
    I’ve tried the query, posts_orderby and posts_clauses filters to modify the query but can’t get it to work.

    A temporary solution I found to make it work is by using a core-hack in wp-admin/includes/class-wp-ms-sites-list-table.php around line 82:

    $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : '';
    		if ( $order_by == 'registered' ) {
    			$query .= ' ORDER BY registered ';
    		} elseif ( $order_by == 'lastupdated' ) {
    			$query .= ' ORDER BY last_updated ';
    		} elseif ( $order_by == 'blogname' ) {
    			if ( is_subdomain_install() )
    				$query .= ' ORDER BY domain ';
    			else
    				$query .= ' ORDER BY path ';
    		} elseif ( $order_by == 'blog_id' ) {
    			$query .= ' ORDER BY blog_id ';
    
    //begin hack
    
    		} elseif ( $order_by == 'spam' ) {
    			$query .= ' ORDER BY spam ';
    //end hack
    
    		} else {
    			$order_by = null;
    		}

    Any help is appreciated to play safe on future-updates, thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter webraket

    (@webraket)

    Took me 2months to get this working without a required core hack.

    It now also displays the sortable spam column on the “Network-Admin => Users” page (wp-admin/network/users.php)

    Here is my final code:
    Just drop it into wp-content/mu-plugins/

    http://pastebin.com/x5bapTue

Viewing 1 replies (of 1 total)
  • The topic ‘Multisite (wp-admin/network/sites.php) order by "spam"’ is closed to new replies.