/** * Orderby Users column * * @since 1.3 */ public function handle_requests_orderby_users_column($user_query) { // query vars $vars = $user_query->query_vars; // Column $column = $this->get_orderby_type($vars['orderby'], 'wp-users'); if (empty($column)) { return $user_query; } // id $type = $id = key($column); // Check for user custom fields: column-meta-[customfieldname] if (Codepress_Admin_Columns::is_column_meta($type)) { $type = 'column-user-meta'; } // Check for post count: column-user_postcount-[posttype] if (Codepress_Admin_Columns::get_posttype_by_postcount_column($type)) { $type = 'column-user_postcount'; } // var $cusers = array(); switch ($type) { case 'column-user_id': $user_query->query_orderby = "ORDER BY ID {$user_query->query_vars['order']}"; $user_query->query_vars['orderby'] = 'ID'; break; case 'column-user_registered': $user_query->query_orderby = "ORDER BY user_registered {$user_query->query_vars['order']}"; $user_query->query_vars['orderby'] = 'registered'; break; case 'column-nickname': $sort_flag = SORT_REGULAR; foreach ($this->get_users_data() as $u) { if ($u->nickname || $this->show_all_results) { $cusers[$u->ID] = $this->prepare_sort_string_value($u->nickname); } } break; case 'column-first_name': $sort_flag = SORT_REGULAR; foreach ($this->get_users_data() as $u) { if ($u->first_name || $this->show_all_results) { $cusers[$u->ID] = $this->prepare_sort_string_value($u->first_name); } } break; case 'column-last_name': $sort_flag = SORT_REGULAR; foreach ($this->get_users_data() as $u) { if ($u->last_name || $this->show_all_results) { $cusers[$u->ID] = $this->prepare_sort_string_value($u->last_name); } } break; case 'column-user_url': $sort_flag = SORT_REGULAR; foreach ($this->get_users_data() as $u) { if ($u->user_url || $this->show_all_results) { $cusers[$u->ID] = $this->prepare_sort_string_value($u->user_url); } } break; case 'column-user_description': $sort_flag = SORT_REGULAR; foreach ($this->get_users_data() as $u) { if ($u->user_description || $this->show_all_results) { $cusers[$u->ID] = $this->prepare_sort_string_value($u->user_description); } } break; case 'column-user_postcount': $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($id); if ($post_type) { $sort_flag = SORT_REGULAR; foreach ($this->get_users_data() as $u) { $count = Codepress_Admin_Columns::get_post_count($post_type, $u->ID); $cusers[$u->ID] = $this->prepare_sort_string_value($count); } } break; case 'column-user-meta': $field = $column[$id]['field']; if ($field) { // order numeric or string $sort_flag = SORT_REGULAR; if ($column[$id]['field_type'] == 'numeric' || $column[$id]['field_type'] == 'library_id') { $sort_flag = SORT_NUMERIC; } // sort by metavalue foreach ($this->get_users_data() as $u) { $value = get_metadata('user', $u->ID, $field, true); $cusers[$u->ID] = $this->prepare_sort_string_value($value); } } break; /** native WP columns */ // role column /** native WP columns */ // role column case 'role': $sort_flag = SORT_REGULAR; foreach ($this->get_users_data() as $u) { $role = !empty($u->roles[0]) ? $u->roles[0] : ''; if ($role || $this->show_all_results) { $cusers[$u->ID] = $this->prepare_sort_string_value($role); } } break; } if (isset($sort_flag)) { $user_query = $this->get_users_query_vars($user_query, $cusers, $sort_flag); } return $user_query; }
/** * Manage custom column for Users. * * @since 1.1 */ public function manage_users_column_value($value, $column_name, $user_id) { $type = $column_name; $userdata = get_userdata($user_id); if (!$userdata) { return false; } // Check for user custom fields: column-meta-[customfieldname] if ($this->is_column_meta($type)) { $type = 'column-user-meta'; } // Check for post count: column-user_postcount-[posttype] if (Codepress_Admin_Columns::get_posttype_by_postcount_column($type)) { $type = 'column-user_postcount'; } // Hook do_action('cpac-manage-users-column', $type, $column_name, $user_id); $result = ''; switch ($type) { // user id case "column-user_id": $result = $user_id; break; // first name // first name case "column-nickname": $result = $userdata->nickname; break; // first name // first name case "column-first_name": $result = $userdata->first_name; break; // last name // last name case "column-last_name": $result = $userdata->last_name; break; // user url // user url case "column-user_url": $result = $userdata->user_url; break; // user registration date // user registration date case "column-user_registered": $result = $userdata->user_registered; break; // user description // user description case "column-user_description": $result = $this->get_shortened_string(get_the_author_meta('user_description', $user_id), $this->excerpt_length); break; // user description // user description case "column-user_postcount": $post_type = Codepress_Admin_Columns::get_posttype_by_postcount_column($column_name); // get post count $count = Codepress_Admin_Columns::get_post_count($post_type, $user_id); // set result $result = $count > 0 ? "<a href='edit.php?post_type={$post_type}&author={$user_id}'>{$count}</a>" : (string) $count; break; // user actions // user actions case "column-actions": $result = $this->get_column_value_actions($user_id, 'users'); break; // user meta data ( custom field ) // user meta data ( custom field ) case "column-user-meta": $result = $this->get_column_value_custom_field($user_id, $column_name, 'user'); break; default: $result = $value; } // Filter for customizing the result output apply_filters('cpac-users-column-result', $result, $type, $column_name, $user_id); return $result; }