/bp-members/classes/class-bp-members-list-table.php

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