Page 1 of 1

Add EOT to all users view

PostPosted: September 4th, 2011, 12:45 pm
by redliontrader
Is there a way to add the EOT field to the All Users view. Would be even better if it were a sortable column. Will do the work if someone can get me started.

Thanks

Re: Add EOT to all users view

PostPosted: September 4th, 2011, 3:55 pm
by Bruce C
I found out how to create a column in the Users list, however I am still looking through the docs for the EOT Constants/Variables.... I'll get back to you if I figure it out, but here's the current code I have:

Code: Select all
<?php
//Two main filters,
add_filter('manage_users_columns', 'add_eot_column');
add_filter('manage_users_custom_column', 'view_eot_column', 10, 3);

function add_eot_column($columns) {
          $columns['current_eot'] = 'EOT';
   return $columns;

}

function view_eot_column($empty='', $column_name, $id) {
   if( $column_name == 'current_eot' ) {
                //The return below is what is shown.
      return  ;

       }
}
?>


This, as it is, only creates the column with the name of EOT.

I'll look at it a bit more.


BTW, found the original code here:
http://wordpress.org/support/topic/mana ... ?replies=6

Re: Add EOT to all users view

PostPosted: September 4th, 2011, 4:45 pm
by Bruce C
Here you go, I got it figured out:

Code: Select all
<?php
add_filter ('manage_users_columns', 'add_eot_column');
add_filter ('manage_users_custom_column', 'view_eot_column', 10, 3);
function add_eot_column ($columns)
   {
      $columns['view_eot'] = 'EOT';
      return $columns;
   }
function view_eot_column ($empty = '', $column_name, $id)
   {
      if ($column_name == 'view_eot')
         {
            if (!get_user_field ('s2member_auto_eot_time', $id) == 0)
               {
                  return date ("M/d/Y", get_user_field ('s2member_auto_eot_time', $id));
               }
            else
               {
                  return "No EOT Set";
               }
         }
   }
?>


This should go either in your theme's functions.php file, the s2hacks.php file, OR a plugin file you create yourself.

Cheers!

Re: Add EOT to all users view

PostPosted: September 10th, 2011, 8:39 am
by redliontrader
Ace.. that is awesome.. Two problems for me though.

If I add it to functions.php it breaks the other columns (num of logins for example don't appear).

Where does s2hacks.php go? In my theme folder? I was going to try it there

Re: Add EOT to all users view

PostPosted: September 10th, 2011, 7:44 pm
by Bruce C
I'm taking another look at this. I'm sorry I didn't see that before.

Re: Add EOT to all users view

PostPosted: September 10th, 2011, 8:10 pm
by Bruce C
Here you go, it was an issue with where I had the return values.

Here's the correct code

Code: Select all
add_filter ('manage_users_columns', 'add_eot_column');
add_filter ('manage_users_custom_column', 'view_eot_column', 11, 3);
function add_eot_column ($eot_column)
   {
      $eot_column['view_eot'] = 'EOT';
      return $eot_column;
   }
function view_eot_column ($eot_column, $column_name, $id)
   {
      if ($column_name == 'view_eot')
         {
            if (!get_user_field ('s2member_auto_eot_time', $id) == 0)
               {
                  $eot_column = date ("M/d/Y", get_user_field ('s2member_auto_eot_time', $id));
               }
         }
      return $eot_column;
   }

Re: Add EOT to all users view

PostPosted: September 14th, 2011, 2:39 am
by Cristián Lávaque
The s2hacks.php file would go in the /wp-content/mu-plugins/ directory. I.e.: /wp-content/mu-plugins/s2hacks.php :)

Just create the dir and file if you don't have them.

Re: Add EOT to all users view

PostPosted: September 19th, 2011, 8:00 pm
by pcscweb
This mod is great!

redliontrader wrote: Would be even better if it were a sortable column.


From what I've read, sorting by the EOT column may not be possible because the values are stored in the wp_usermeta table: http://tech.ipstenu.org/2011/limitations-on-sortable-columns/.

Re: Add EOT to all users view

PostPosted: September 21st, 2011, 11:18 am
by Bruce C
Thanks pcsweb for posting that.

I took a look at the filters that were used the the plugin from that post, and managed to get the column sortable. Here's the code:

Code: Select all
add_filter ('manage_users_columns', 'add_eot_column');
add_filter ('manage_users_custom_column', 'view_eot_column', 11, 3);
function add_eot_column ($eot_column)
   {
      $eot_column['view_eot'] = 'EOT';
      return $eot_column;
   }
function view_eot_column ($eot_column, $column_name, $id)
   {
      if ($column_name == 'view_eot')
         {
            if (!get_user_field ('s2member_auto_eot_time', $id) == 0)
               {
                  $eot_column = date ("M/d/Y", get_user_field ('s2member_auto_eot_time', $id));
               }
         }
      return $eot_column;
   }
function eot_sortable_columns ($columns)
   {
      $columns['view_eot'] = 'EOT';
      return $columns;
   }
add_filter ('manage_users_sortable_columns', 'eot_sortable_columns');
function eot_column_orderby ($vars)
   {
      if (isset ($vars['orderby']) && 'view_eot' == $vars['orderby'])
         {
            $vars = array_merge ($vars, array ('meta_key' => 'view_eot', 'orderby' => 'meta_value', 'order' => 'asc'));
         }
      return $vars;
   }
add_filter ('request', 'eot_column_orderby');


I'm happy we figured this out!

Re: Add EOT to all users view

PostPosted: September 21st, 2011, 11:19 am
by Bruce C
Also, I just wanted to bring up that there's a chance that this may not work on a multisite installation. You can try it, though.

Re: Add EOT to all users view

PostPosted: September 21st, 2011, 12:36 pm
by bitofgrace
This is fantastic Ace - thank you :)

Re: Add EOT to all users view

PostPosted: September 22nd, 2011, 7:23 pm
by pcscweb
It seems to be sorting by Username when I try clicking on the 'EOT' column. Is it working for you?

One thing I noticed was that:

Code: Select all
'view_eot' == $vars['orderby']


should probably be

Code: Select all
'EOT' == $vars['orderby']


to reflect the correct value in the URL-encoded query string param. Fixing that still resulted in the rows sorting by Username instead of EOT.