prepare_items(); ?>

Users interested in Contributing

display(); ?>
get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $data = $this->table_data(); usort( $data, array( &$this, 'sort_data' ) ); $perPage = 100; $currentPage = $this->get_pagenum(); $totalItems = count($data); $this->set_pagination_args( array( 'total_items' => $totalItems, 'per_page' => $perPage ) ); $data = array_slice($data,(($currentPage-1)*$perPage),$perPage); $this->_column_headers = array($columns, $hidden, $sortable); $this->items = $data; } /** * Override the parent columns method. Defines the columns to use in your listing table * * @return Array */ public function get_columns() { $columns = array( // 'id' => 'ID', // 'display' => 'Display Name', 'image' => 'Photo', 'username' => 'Username', 'email' => 'Email', 'contribute' => 'Wants to Contribute', 'rdate' => 'Registered', 'ldate' => 'Last Login', 'sdate' => 'Last Save', 'public' => 'Visibility', 'saves' => 'Saves', ); return $columns; } /** * Define which columns are hidden * * @return Array */ public function get_hidden_columns() { return array(); } /** * Define the sortable columns * * @return Array */ public function get_sortable_columns() { return array( 'id' => array('id', false), 'username' => array('username', false), 'rdate' => array('rdate', false), 'ldate' => array('ldate', false), 'sdate' => array('sdate', false), 'pubilc' => array('pubilc', false), 'contribute' => array('contribute', false), 'saves' => array('saves', false), 'public' => array('public', false), 'display' => array('display', false), 'image' => array('image', false), ); } /** * Get the table data * * @return Array */ private function table_data() { $data = array(); $args = array( 'orderby' => 'meta_value', 'meta_key' => 'last_save', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'i_want_to_write_posts', 'value' => 'No thanks', 'compare' => '!=', ), ), 'fields' => 'all' ); // Array of WP_User objects. $users = get_users( $args ); foreach ( $users as $user) { $userid = $user->ID; // don't include user 1 if ( $user->ID === 1) { continue; } // get data $last_login = date('Y-m-d H:i:s', intval( get_user_meta( $userid, 'last_login', true ) ) ); $last_save = date('Y-m-d H:i:s', intval( get_user_meta( $userid, 'last_save', true ) ) ); $save_count = intval( get_user_meta( $userid, 'save_count', true ) ); $in_directory = get_user_meta( $userid, 'in_directory', true ); $i_want_to_write_posts = get_user_meta( $userid, 'i_want_to_write_posts', true ); $rdate = date( 'Y-m-d H:i:s', strtotime( get_userdata( $userid )->user_registered ) ); $view_edit = '
View | Edit'; $user_info = get_userdata( $userid ); $user_email = $user_info->user_email; $data[] = array( 'id' => $userid, 'image' => '', 'username' => get_the_author_meta( 'user_nicename', $userid ) . $view_edit, 'display' => get_the_author_meta( 'display_name', $userid ) . $view_edit, 'rdate' => $rdate === '1970-01-01 00:00:00' ? '' : $rdate, 'ldate' => $last_login === '1970-01-01 00:00:00' ? '' : $last_login, 'sdate' => $last_save === '1970-01-01 00:00:00' ? '' : $last_save, 'public' => $in_directory, 'contribute' => $i_want_to_write_posts, 'saves' => $save_count, 'email' => '' . $user_email . '', ); } return $data; } /** * Define what data to show on each column of the table * * @param Array $item Data * @param String $column_name - Current column name * * @return Mixed */ public function column_default( $item, $column_name ) { switch( $column_name ) { case 'id': case 'image': case 'username': case 'display': case 'rdate': case 'ldate': case 'sdate': case 'public': case 'contribute': case 'saves': case 'email': return $item[ $column_name ]; default: return print_r( $item, true ) ; } } /** * Allows you to sort the data by the variables set in the $_GET * * @return Mixed */ private function sort_data( $a, $b ) { // Set defaults $orderby = 'contribute'; $order = 'desc'; // If orderby is set, use this as the sort column if(!empty($_GET['orderby'])) { $orderby = $_GET['orderby']; } // If order is set use this as the order if(!empty($_GET['order'])) { $order = $_GET['order']; } // string vs number sorting if( $orderby === 'saves' ) { $ao = $a[$orderby]; $bo = $b[$orderby]; $result = ($ao < $bo) ? -1 : (($ao > $bo) ? 1 : 0); } else { $result = strcmp( $a[$orderby], $b[$orderby] ); } if($order === 'asc') { return $result; } return -$result; } } ?>