Friday, August 30, 2013

User-Access-Manager wordpress plugin sort field at user.php in admin

Whe we use this plugin if we have many user registered in site and feel dificult to find the new user who are not a member yet,if you add the code below you will be able to see the "unauthorised users' by clicking at the "uam user groups"
Added the following code below the file "user-access-manager.php" in your plugin folder.

function user_sortable_columns( $columns) {

    $columns['uam_access'] =array( 'uam_access', 'desc' );
    return $columns;
}
add_filter( 'manage_users_sortable_columns', 'user_sortable_columns' );

function user_column_orderby( $vars ) {
    if ( isset( $vars['orderby'] ) && 'uam_access' == $vars['orderby'] ) {

        $vars = array_merge( $vars, array(
            'meta_key' => 'uam_access',
            'orderby' => 'meta_value'

               ) );


    }
    return $vars;
}
add_filter( 'request', 'user_column_orderby' );

add_action('pre_user_query', 'status_order_in_user_query');

function status_order_in_user_query($query){

// print_r($query); // for debugging

if('uam_access'==$query->query_vars['orderby'] && 'DESC'==$query->query_vars['order']) {

   $query->query_where .= " and id NOT IN (SELECT object_id FROM wp_uam_accessgroup_to_object
WHERE object_type = 'user')";

}

}

No comments:

Post a Comment