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