BP_Members_List_Table

List table class for signups admin page.

Defined (1)

The class is defined in the following location(s).

/bp-members/classes/class-bp-members-list-table.php  
  1. class BP_Members_List_Table extends WP_Users_List_Table { 
  2.  
  3. /** 
  4. * Signup counts. 
  5. * @since 2.0.0 
  6. * @var int 
  7. */ 
  8. public $signup_counts = 0; 
  9.  
  10. /** 
  11. * Constructor. 
  12. * @since 2.0.0 
  13. */ 
  14. public function __construct() { 
  15. // Define singular and plural labels, as well as whether we support AJAX. 
  16. parent::__construct( array( 
  17. 'ajax' => false,  
  18. 'plural' => 'signups',  
  19. 'singular' => 'signup',  
  20. 'screen' => get_current_screen()->id,  
  21. ) ); 
  22.  
  23. /** 
  24. * Set up items for display in the list table. 
  25. * Handles filtering of data, sorting, pagination, and any other data 
  26. * manipulation required prior to rendering. 
  27. * @since 2.0.0 
  28. */ 
  29. public function prepare_items() { 
  30. global $usersearch; 
  31.  
  32. $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 
  33. $signups_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 
  34. $paged = $this->get_pagenum(); 
  35.  
  36. $args = array( 
  37. 'offset' => ( $paged - 1 ) * $signups_per_page,  
  38. 'number' => $signups_per_page,  
  39. 'usersearch' => $usersearch,  
  40. 'orderby' => 'signup_id',  
  41. 'order' => 'DESC' 
  42. ); 
  43.  
  44. if ( isset( $_REQUEST['orderby'] ) ) { 
  45. $args['orderby'] = $_REQUEST['orderby']; 
  46.  
  47. if ( isset( $_REQUEST['order'] ) ) { 
  48. $args['order'] = $_REQUEST['order']; 
  49.  
  50. $signups = BP_Signup::get( $args ); 
  51.  
  52. $this->items = $signups['signups']; 
  53. $this->signup_counts = $signups['total']; 
  54.  
  55. $this->set_pagination_args( array( 
  56. 'total_items' => $this->signup_counts,  
  57. 'per_page' => $signups_per_page,  
  58. ) ); 
  59.  
  60. /** 
  61. * Display the users screen views 
  62. * @since 2.5.0 
  63. * @global string $role The name of role the users screens is filtered by 
  64. */ 
  65. public function views() { 
  66. global $role; 
  67.  
  68. // Used to reset the role. 
  69. $reset_role = $role; 
  70.  
  71. // Temporarly set the role to registered. 
  72. $role = 'registered'; 
  73.  
  74. // Used to reset the screen id once views are displayed. 
  75. $reset_screen_id = $this->screen->id; 
  76.  
  77. // Temporarly set the screen id to the users one. 
  78. $this->screen->id = 'users'; 
  79.  
  80. // Use the parent function so that other plugins can safely add views. 
  81. parent::views(); 
  82.  
  83. // Reset the role. 
  84. $role = $reset_role; 
  85.  
  86. // Reset the screen id. 
  87. $this->screen->id = $reset_screen_id; 
  88.  
  89. /** 
  90. * Get rid of the extra nav. 
  91. * WP_Users_List_Table will add an extra nav to change user's role. 
  92. * As we're dealing with signups, we don't need this. 
  93. * @since 2.0.0 
  94. * @param array $which Current table nav item. 
  95. */ 
  96. public function extra_tablenav( $which ) { 
  97. return; 
  98.  
  99. /** 
  100. * Specific signups columns. 
  101. * @since 2.0.0 
  102. * @return array 
  103. */ 
  104. public function get_columns() { 
  105.  
  106. /** 
  107. * Filters the single site Members signup columns. 
  108. * @since 2.0.0 
  109. * @param array $value Array of columns to display. 
  110. */ 
  111. return apply_filters( 'bp_members_signup_columns', array( 
  112. 'cb' => '<input type="checkbox" />',  
  113. 'username' => __( 'Username', 'buddypress' ),  
  114. 'name' => __( 'Name', 'buddypress' ),  
  115. 'email' => __( 'Email', 'buddypress' ),  
  116. 'registered' => __( 'Registered', 'buddypress' ),  
  117. 'date_sent' => __( 'Last Sent', 'buddypress' ),  
  118. 'count_sent' => __( 'Emails Sent', 'buddypress' ) 
  119. ) ); 
  120.  
  121. /** 
  122. * Specific bulk actions for signups. 
  123. * @since 2.0.0 
  124. */ 
  125. public function get_bulk_actions() { 
  126. $actions = array( 
  127. 'activate' => _x( 'Activate', 'Pending signup action', 'buddypress' ),  
  128. 'resend' => _x( 'Email', 'Pending signup action', 'buddypress' ),  
  129. ); 
  130.  
  131. if ( current_user_can( 'delete_users' ) ) { 
  132. $actions['delete'] = __( 'Delete', 'buddypress' ); 
  133.  
  134. return $actions; 
  135.  
  136. /** 
  137. * The text shown when no items are found. 
  138. * Nice job, clean sheet! 
  139. * @since 2.0.0 
  140. */ 
  141. public function no_items() { 
  142.  
  143. if ( bp_get_signup_allowed() ) { 
  144. esc_html_e( 'No pending accounts found.', 'buddypress' ); 
  145. } else { 
  146. $link = false; 
  147.  
  148. // Specific case when BuddyPress is not network activated. 
  149. if ( is_multisite() && current_user_can( 'manage_network_users') ) { 
  150. $link = sprintf( '<a href="%1$s">%2$s</a>', esc_url( network_admin_url( 'settings.php' ) ), esc_html__( 'Edit settings', 'buddypress' ) ); 
  151. } elseif ( current_user_can( 'manage_options' ) ) { 
  152. $link = sprintf( '<a href="%1$s">%2$s</a>', esc_url( bp_get_admin_url( 'options-general.php' ) ), esc_html__( 'Edit settings', 'buddypress' ) ); 
  153.  
  154. printf( __( 'Registration is disabled. %s', 'buddypress' ), $link ); 
  155.  
  156.  
  157. /** 
  158. * The columns signups can be reordered with. 
  159. * @since 2.0.0 
  160. */ 
  161. public function get_sortable_columns() { 
  162. return array( 
  163. 'username' => 'login',  
  164. 'email' => 'email',  
  165. 'registered' => 'signup_id',  
  166. ); 
  167.  
  168. /** 
  169. * Display signups rows. 
  170. * @since 2.0.0 
  171. */ 
  172. public function display_rows() { 
  173. $style = ''; 
  174. foreach ( $this->items as $userid => $signup_object ) { 
  175.  
  176. // Avoid a notice error appearing since 4.3.0. 
  177. if ( isset( $signup_object->id ) ) { 
  178. $signup_object->ID = $signup_object->id; 
  179.  
  180. $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 
  181. echo "\n\t" . $this->single_row( $signup_object, $style ); 
  182.  
  183. /** 
  184. * Display a signup row. 
  185. * @since 2.0.0 
  186. * @see WP_List_Table::single_row() for explanation of params. 
  187. * @param object|null $signup_object Signup user object. 
  188. * @param string $style Styles for the row. 
  189. * @param string $role Role to be assigned to user. 
  190. * @param int $numposts Numper of posts. 
  191. * @return void 
  192. */ 
  193. public function single_row( $signup_object = null, $style = '', $role = '', $numposts = 0 ) { 
  194. echo '<tr' . $style . ' id="signup-' . esc_attr( $signup_object->id ) . '">'; 
  195. echo $this->single_row_columns( $signup_object ); 
  196. echo '</tr>'; 
  197.  
  198. /** 
  199. * Markup for the checkbox used to select items for bulk actions. 
  200. * @since 2.0.0 
  201. * @param object|null $signup_object The signup data object. 
  202. */ 
  203. public function column_cb( $signup_object = null ) { 
  204. ?> 
  205. <label class="screen-reader-text" for="signup_<?php echo intval( $signup_object->id ); ?>"><?php 
  206. /** translators: accessibility text */ 
  207. printf( esc_html__( 'Select user: %s', 'buddypress' ), $signup_object->user_login ); 
  208. ?></label> 
  209. <input type="checkbox" id="signup_<?php echo intval( $signup_object->id ) ?>" name="allsignups[]" value="<?php echo esc_attr( $signup_object->id ) ?>" /> 
  210. <?php 
  211.  
  212. /** 
  213. * The row actions (delete/activate/email). 
  214. * @since 2.0.0 
  215. * @param object|null $signup_object The signup data object. 
  216. */ 
  217. public function column_username( $signup_object = null ) { 
  218. $avatar = get_avatar( $signup_object->user_email, 32 ); 
  219.  
  220. // Activation email link. 
  221. $email_link = add_query_arg( 
  222. array( 
  223. 'page' => 'bp-signups',  
  224. 'signup_id' => $signup_object->id,  
  225. 'action' => 'resend',  
  226. ),  
  227. bp_get_admin_url( 'users.php' ) 
  228. ); 
  229.  
  230. // Activate link. 
  231. $activate_link = add_query_arg( 
  232. array( 
  233. 'page' => 'bp-signups',  
  234. 'signup_id' => $signup_object->id,  
  235. 'action' => 'activate',  
  236. ),  
  237. bp_get_admin_url( 'users.php' ) 
  238. ); 
  239.  
  240. // Delete link. 
  241. $delete_link = add_query_arg( 
  242. array( 
  243. 'page' => 'bp-signups',  
  244. 'signup_id' => $signup_object->id,  
  245. 'action' => 'delete',  
  246. ),  
  247. bp_get_admin_url( 'users.php' ) 
  248. ); 
  249.  
  250. echo $avatar . sprintf( '<strong><a href="%1$s" class="edit" title="%2$s">%3$s</a></strong><br/>', esc_url( $activate_link ), esc_attr__( 'Activate', 'buddypress' ), $signup_object->user_login ); 
  251.  
  252. $actions = array(); 
  253.  
  254. $actions['activate'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $activate_link ), __( 'Activate', 'buddypress' ) ); 
  255. $actions['resend'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $email_link ), __( 'Email', 'buddypress' ) ); 
  256.  
  257. if ( current_user_can( 'delete_users' ) ) { 
  258. $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), __( 'Delete', 'buddypress' ) ); 
  259.  
  260. /** 
  261. * Filters the multisite row actions for each user in list. 
  262. * @since 2.0.0 
  263. * @param array $actions Array of actions and corresponding links. 
  264. * @param object $signup_object The signup data object. 
  265. */ 
  266. $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object ); 
  267.  
  268. echo $this->row_actions( $actions ); 
  269.  
  270. /** 
  271. * Display user name, if any. 
  272. * @since 2.0.0 
  273. * @param object|null $signup_object The signup data object. 
  274. */ 
  275. public function column_name( $signup_object = null ) { 
  276. echo esc_html( $signup_object->user_name ); 
  277.  
  278. /** 
  279. * Display user email. 
  280. * @since 2.0.0 
  281. * @param object|null $signup_object The signup data object. 
  282. */ 
  283. public function column_email( $signup_object = null ) { 
  284. printf( '<a href="mailto:%1$s">%2$s</a>', esc_attr( $signup_object->user_email ), esc_html( $signup_object->user_email ) ); 
  285.  
  286. /** 
  287. * Display registration date. 
  288. * @since 2.0.0 
  289. * @param object|null $signup_object The signup data object. 
  290. */ 
  291. public function column_registered( $signup_object = null ) { 
  292. echo mysql2date( 'Y/m/d', $signup_object->registered ); 
  293.  
  294. /** 
  295. * Display the last time an activation email has been sent. 
  296. * @since 2.0.0 
  297. * @param object|null $signup_object The signup data object. 
  298. */ 
  299. public function column_date_sent( $signup_object = null ) { 
  300. echo mysql2date( 'Y/m/d', $signup_object->date_sent ); 
  301.  
  302. /** 
  303. * Display number of time an activation email has been sent. 
  304. * @since 2.0.0 
  305. * @param object|null $signup_object Signup object instance. 
  306. */ 
  307. public function column_count_sent( $signup_object = null ) { 
  308. echo absint( $signup_object->count_sent ); 
  309.  
  310. /** 
  311. * Allow plugins to add their custom column. 
  312. * @since 2.1.0 
  313. * @param object|null $signup_object The signup data object. 
  314. * @param string $column_name The column name. 
  315. * @return string 
  316. */ 
  317. function column_default( $signup_object = null, $column_name = '' ) { 
  318.  
  319. /** 
  320. * Filters the single site custom columns for plugins. 
  321. * @since 2.1.0 
  322. * @param string $column_name The column name. 
  323. * @param object $signup_object The signup data object. 
  324. */ 
  325. return apply_filters( 'bp_members_signup_custom_column', '', $column_name, $signup_object );