This code adds custom columns to the users table.  Great for developers to customize the user table for their clients site with custom post meta.

 

/**
 * Add columns to the wp-admin user's table
 *
 * @param array $args Associative array where key is wp_usermeta meta_keys or wp_users column names and the value is the display name
 * @return none;
 */
if(!function_exists(load_sortable_user_meta_columns)){
	add_action('admin_init', 'load_sortable_user_meta_columns');
	function load_sortable_user_meta_columns(){
		//THIS IS WHERE YOU ADD THE meta_key => display-title values
		$args = array('cybersourceID'=>'Cybersource ID', 'user_registered'=>'Date Registered');
		new sortable_user_meta_columns($args);
	}
}
if(!class_exists(sortable_user_meta_columns)):
class sortable_user_meta_columns{
	var $defaults = array('nicename', 'email', 'url', 'registered','user_nicename', 'user_email', 'user_url', 'user_registered','display_name','name','post_count','ID','id','user_login');
	function __construct($args){
		$this->args = $args;
		add_action('pre_user_query', array(&$this, 'query'));
		add_action('manage_users_custom_column',  array(&$this, 'content'), 10, 3);
		add_filter('manage_users_columns', array(&$this, 'columns'));
		add_filter( 'manage_users_sortable_columns', array(&$this, 'sortable') );
	}
	function query($query){
		$vars = $query->query_vars;
		if(in_array($vars['orderby'], $this->defaults)) return;
		$title = $this->args[$vars['orderby']];
		if(!empty($title)){
			   $query->query_from .= " LEFT JOIN wp_usermeta m ON (wp_users.ID = m.user_id  AND m.meta_key = '$vars[orderby]')";
			   $query->query_orderby = "ORDER BY m.meta_value ".$vars['order'];
		}
	}
	function columns($columns) {
		foreach($this->args as $key=>$value){
			$columns[$key] = $value;
		}
		return $columns;
	}
	function sortable($columns){
		foreach($this->args as $key=>$value){
			$columns[$key] = $key;
		}
		return $columns;
	}
	function content($value, $column_name, $user_id) {
		$user = get_userdata( $user_id );
		return $user->$column_name;
	}
}
endif;

A plugin created to provide a way for a client to distribute .pdf files to subscribers so that they could not be hot-linked or easily shared.  Of course with some advanced computer knowledge the user could still download the file and distribute it via email. This plugin just makes it much more difficult.

 

The plugin’s admin interface allows the site admin to upload files to a new non-public folder of the server that is created upon install.   Upon upload the file’s name and location is stored in a database table along with a unique hash key that will be used to access the file by subscribers.   The client was using the s2member plugin for its subscriptions purposes which creates a variety of levels or user roles depending on their subscription type.  The plugin was modified to allow the site admin to restrict the uploaded file to be accessed only by particular user levels set by s2member.