[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Membership Invitation List Table class. 4 * 5 * @package BuddyPress 6 * @subpackage MembersAdminClasses 7 * @since 8.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * List table class for Invitations admin page. 15 * 16 * @since 8.0.0 17 */ 18 class BP_Members_Invitations_List_Table extends WP_Users_List_Table { 19 20 /** 21 * The type of view currently being displayed. 22 * 23 * E.g. "All", "Pending", "Sent", "Unsent"... 24 * 25 * @since 8.0.0 26 * @var string 27 */ 28 public $active_filters = array(); 29 30 /** 31 * Invitation counts. 32 * 33 * @since 8.0.0 34 * @var int 35 */ 36 public $total_items = 0; 37 38 /** 39 * Constructor. 40 * 41 * @since 8.0.0 42 */ 43 public function __construct() { 44 // Define singular and plural labels, as well as whether we support AJAX. 45 parent::__construct( array( 46 'ajax' => false, 47 'plural' => 'invitations', 48 'singular' => 'invitation', 49 'screen' => get_current_screen()->id, 50 ) ); 51 } 52 53 /** 54 * Set up items for display in the list table. 55 * 56 * Handles filtering of data, sorting, pagination, and any other data 57 * manipulation required prior to rendering. 58 * 59 * @since 8.0.0 60 */ 61 public function prepare_items() { 62 global $usersearch; 63 64 $search = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; 65 $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); 66 $paged = $this->get_pagenum(); 67 68 $args = array( 69 'invite_sent' => 'all', 70 'accepted' => 'all', 71 'search_terms' => $search, 72 'order_by' => 'date_modified', 73 'sort_order' => 'DESC', 74 'page' => $paged, 75 'per_page' => $per_page, 76 ); 77 78 if ( isset( $_REQUEST['accepted'] ) && in_array( $_REQUEST['accepted'], array( 'pending', 'accepted' ), true ) ) { 79 $args['accepted'] = $_REQUEST['accepted']; 80 $this->active_filters[] = $_REQUEST['accepted']; 81 } 82 if ( isset( $_REQUEST['sent'] ) && in_array( $_REQUEST['sent'], array( 'draft', 'sent' ), true ) ) { 83 $args['invite_sent'] = $_REQUEST['sent']; 84 $this->active_filters[] = $_REQUEST['sent']; 85 } 86 87 if ( isset( $_REQUEST['orderby'] ) ) { 88 $args['order_by'] = $_REQUEST['orderby']; 89 } 90 91 if ( isset( $_REQUEST['order'] ) ) { 92 $args['sort_order'] = $_REQUEST['order']; 93 } 94 95 $invites_class = new BP_Members_Invitation_Manager(); 96 $this->items = $invites_class->get_invitations( $args ); 97 $this->total_items = $invites_class->get_invitations_total_count( $args ); 98 99 $this->set_pagination_args( array( 100 'total_items' => $this->total_items, 101 'per_page' => $per_page, 102 ) ); 103 } 104 105 /** 106 * Gets the name of the default primary column. 107 * 108 * @since 10.1.0 109 * 110 * @return string Name of the default primary column, in this case, 'invitee_email'. 111 */ 112 protected function get_default_primary_column_name() { 113 return 'invitee_email'; 114 } 115 116 /** 117 * Get the list of views available on this table (e.g. "all", "public"). 118 * 119 * @since 8.0.0 120 */ 121 public function views() { 122 $tools_url = bp_get_admin_url( 'tools.php' ); 123 124 if ( is_network_admin() ) { 125 $tools_url = network_admin_url( 'admin.php' ); 126 } 127 128 $url_base = add_query_arg( 129 array( 130 'page' => 'bp-members-invitations', 131 ), 132 $tools_url 133 ); 134 ?> 135 136 <h2 class="screen-reader-text"> 137 <?php 138 /* translators: accessibility text */ 139 esc_html_e( 'Filter invitations list', 'buddypress' ); 140 ?> 141 </h2> 142 <ul class="subsubsub"> 143 <li class="all"> 144 <a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( empty( $this->active_filters ) ) echo 'current'; ?>"> 145 <?php esc_html_e( 'All', 'buddypress' ); ?> 146 </a> | 147 </li> 148 <li class="pending"> 149 <a href="<?php echo esc_url( add_query_arg( 'accepted', 'pending', $url_base ) ); ?>" class="<?php if ( in_array( 'pending', $this->active_filters, true ) ) echo 'current'; ?>"> 150 <?php esc_html_e( 'Pending', 'buddypress' ); ?> 151 </a> | 152 </li> 153 <li class="accepted"> 154 <a href="<?php echo esc_url( add_query_arg( 'accepted', 'accepted', $url_base ) ); ?>" class="<?php if ( in_array( 'accepted', $this->active_filters, true ) ) echo 'current'; ?>"> 155 <?php esc_html_e( 'Accepted', 'buddypress' ); ?> 156 </a> | 157 </li> 158 <li class="draft"> 159 <a href="<?php echo esc_url( add_query_arg( 'sent', 'draft', $url_base ) ); ?>" class="<?php if ( in_array( 'draft', $this->active_filters, true ) ) echo 'current'; ?>"> 160 <?php esc_html_e( 'Draft (Unsent)', 'buddypress' ); ?> 161 </a> | 162 </li> 163 <li class="sent"> 164 <a href="<?php echo esc_url( add_query_arg( 'sent', 'sent', $url_base ) ); ?>" class="<?php if ( in_array( 'sent', $this->active_filters, true ) ) echo 'current'; ?>"> 165 <?php esc_html_e( 'Sent', 'buddypress' ); ?> 166 </a> 167 </li> 168 169 <?php 170 171 /** 172 * Fires inside listing of views so plugins can add their own. 173 * 174 * @since 8.0.0 175 * 176 * @param string $url_base Current URL base for view. 177 * @param array $active_filters Current filters being requested. 178 */ 179 do_action( 'bp_members_invitations_list_table_get_views', $url_base, $this->active_filters ); ?> 180 </ul> 181 <?php 182 } 183 184 /** 185 * Get rid of the extra nav. 186 * 187 * WP_Users_List_Table will add an extra nav to change user's role. 188 * As we're dealing with invitations, we don't need this. 189 * 190 * @since 8.0.0 191 * 192 * @param array $which Current table nav item. 193 */ 194 public function extra_tablenav( $which ) { 195 return; 196 } 197 198 /** 199 * Specific signups columns. 200 * 201 * @since 8.0.0 202 * 203 * @return array 204 */ 205 public function get_columns() { 206 207 /** 208 * Filters the single site Members signup columns. 209 * 210 * @since 8.0.0 211 * 212 * @param array $value Array of columns to display. 213 */ 214 return apply_filters( 215 'bp_members_invitations_list_columns', 216 array( 217 'cb' => '<input type="checkbox" />', 218 'invitee_email' => __( 'Invitee', 'buddypress' ), 219 'username' => __( 'Inviter', 'buddypress' ), 220 'inviter_registered_date' => __( 'Inviter Registered', 'buddypress' ), 221 'invitation_date_modified' => __( 'Date Modified', 'buddypress' ), 222 'invitation_sent' => __( 'Email Sent', 'buddypress' ), 223 'invitation_accepted' => __( 'Accepted', 'buddypress' ) 224 ) 225 ); 226 } 227 228 /** 229 * Specific bulk actions for signups. 230 * 231 * @since 8.0.0 232 */ 233 public function get_bulk_actions() { 234 $actions = array( 235 'resend' => _x( 'Resend Email', 'Pending invitation action', 'buddypress' ), 236 ); 237 238 if ( current_user_can( 'delete_users' ) ) { 239 $actions['delete'] = _x( 'Delete', 'Pending invitation action', 'buddypress' ); 240 } 241 242 return $actions; 243 } 244 245 /** 246 * The text shown when no items are found. 247 * 248 * Nice job, clean sheet! 249 * 250 * @since 8.0.0 251 */ 252 public function no_items() { 253 254 if ( bp_get_members_invitations_allowed() ) { 255 esc_html_e( 'No invitations found.', 'buddypress' ); 256 } else { 257 $link = sprintf( 258 '<a href="%1$s">%2$s</a>', 259 esc_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-settings' ), 'admin.php' ) ) ), 260 esc_html__( 'Edit settings', 'buddypress' ) 261 ); 262 263 /* translators: %s: url to site settings */ 264 printf( __( 'Invitations are not allowed. %s', 'buddypress' ), $link ); 265 } 266 267 } 268 269 /** 270 * The columns invitations can be reordered by. 271 * 272 * @since 8.0.0 273 */ 274 public function get_sortable_columns() { 275 return array( 276 'invitee_email' => 'invitee_email', 277 'username' => 'inviter_id', 278 'invitation_date_modified' => 'date_modified', 279 'invitation_sent' => 'invite_sent', 280 'invitation_accepted' => 'accepted', 281 ); 282 } 283 284 /** 285 * Display invitation rows. 286 * 287 * @since 8.0.0 288 */ 289 public function display_rows() { 290 $style = ''; 291 foreach ( $this->items as $invite ) { 292 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"'; 293 echo "\n\t" . $this->single_row( $invite, $style ); 294 } 295 } 296 297 /** 298 * Display an invitation row. 299 * 300 * @since 8.0.0 301 * 302 * @see WP_List_Table::single_row() for explanation of params. 303 * 304 * @param BP_Invitation $invite BP_Invitation object. 305 * @param string $style Styles for the row. 306 * @param string $role Role to be assigned to user. 307 * @param int $numposts Number of posts. 308 * @return void 309 */ 310 public function single_row( $invite = null, $style = '', $role = '', $numposts = 0 ) { 311 echo '<tr' . $style . ' id="invitation-' . esc_attr( $invite->id ) . '">'; 312 echo $this->single_row_columns( $invite ); 313 echo '</tr>'; 314 } 315 316 /** 317 * Markup for the checkbox used to select items for bulk actions. 318 * 319 * @since 8.0.0 320 * 321 * @param BP_Invitation $invite BP_Invitation object. 322 */ 323 public function column_cb( $invite = null ) { 324 ?> 325 <label class="screen-reader-text" for="invitation_<?php echo intval( $invite->id ); ?>"> 326 <?php 327 /* translators: accessibility text */ 328 printf( esc_html__( 'Select invitation: %s', 'buddypress' ), $invite->id ); 329 ?> 330 </label> 331 <input type="checkbox" id="invitation_<?php echo intval( $invite->id ) ?>" name="invite_ids[]" value="<?php echo esc_attr( $invite->id ) ?>" /> 332 <?php 333 } 334 335 /** 336 * Markup for the checkbox used to select items for bulk actions. 337 * 338 * @since 8.0.0 339 * 340 * @param BP_Invitation $invite BP_Invitation object. 341 */ 342 public function column_invitee_email( $invite = null ) { 343 echo esc_html( $invite->invitee_email ); 344 345 $actions = array(); 346 $tools_url = bp_get_admin_url( 'tools.php' ); 347 348 if ( is_network_admin() ) { 349 $tools_url = network_admin_url( 'admin.php' ); 350 } 351 352 // Resend action only if pending 353 if ( ! $invite->accepted ) { 354 // Resend invitation email link. 355 $email_link = add_query_arg( 356 array( 357 'page' => 'bp-members-invitations', 358 'invite_id' => $invite->id, 359 'action' => 'resend', 360 ), 361 $tools_url 362 ); 363 364 if ( ! $invite->invite_sent ) { 365 $resend_label = __( 'Send', 'buddypress' ); 366 } else { 367 $resend_label = __( 'Resend', 'buddypress' ); 368 } 369 370 $actions['resend'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $email_link ), esc_html( $resend_label ) ); 371 } 372 373 // Delete link. Could be cleanup or revoking the invitation. 374 $delete_link = add_query_arg( 375 array( 376 'page' => 'bp-members-invitations', 377 'invite_id' => $invite->id, 378 'action' => 'delete', 379 ), 380 $tools_url 381 ); 382 383 // Two cases: unsent and accepted (cleanup), and pending (cancels invite). 384 if ( ! $invite->invite_sent || $invite->accepted ) { 385 $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), esc_html__( 'Delete', 'buddypress' ) ); 386 } else { 387 $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), esc_html__( 'Cancel', 'buddypress' ) ); 388 } 389 390 /** 391 * Filters the row actions for each invitation in list. 392 * 393 * @since 8.0.0 394 * 395 * @param array $actions Array of actions and corresponding links. 396 * @param object $invite The BP_Invitation. 397 */ 398 $actions = apply_filters( 'bp_members_invitations_management_row_actions', $actions, $invite ); 399 400 echo $this->row_actions( $actions ); 401 } 402 403 /** 404 * Display invited user's email address. 405 * 406 * @since 8.0.0 407 * 408 * @param BP_Invitation $invite BP_Invitation object. 409 */ 410 public function column_email( $invite = null ) { 411 printf( '<a href="mailto:%1$s">%2$s</a>', esc_attr( $invite->user_email ), esc_html( $invite->user_email ) ); 412 } 413 414 /** 415 * The inviter. 416 * 417 * @since 8.0.0 418 * 419 * @param BP_Invitation $invite BP_Invitation object. 420 */ 421 public function column_username( $invite = null ) { 422 $avatar = get_avatar( $invite->inviter_id, 32 ); 423 $inviter = get_user_by( 'id', $invite->inviter_id ); 424 if ( ! $inviter ) { 425 return; 426 } 427 428 $user_link = bp_core_get_user_domain( $invite->inviter_id ); 429 430 printf( '%1$s <strong><a href="%2$s" class="edit">%3$s</a></strong><br/>', $avatar, esc_url( $user_link ), esc_html( $inviter->user_login ) ); 431 } 432 433 /** 434 * Display invitation date. 435 * 436 * @since 8.0.0 437 * 438 * @param BP_Invitation $invite BP_Invitation object. 439 */ 440 public function column_inviter_registered_date( $invite = null ) { 441 $inviter = get_user_by( 'id', $invite->inviter_id ); 442 if ( ! $inviter ) { 443 return; 444 } 445 echo esc_html( $inviter->user_registered ); 446 } 447 448 /** 449 * Display invitation date. 450 * 451 * @since 8.0.0 452 * 453 * @param BP_Invitation $invite BP_Invitation object. 454 */ 455 public function column_invitation_date_modified( $invite = null ) { 456 echo esc_html( $invite->date_modified ); 457 } 458 459 /** 460 * Display invitation date. 461 * 462 * @since 8.0.0 463 * 464 * @param BP_Invitation $invite BP_Invitation object. 465 */ 466 public function column_invitation_sent( $invite = null ) { 467 if ( $invite->invite_sent) { 468 esc_html_e( 'Yes', 'buddypress' ); 469 } else { 470 esc_html_e( 'No', 'buddypress' ); 471 } 472 } 473 474 /** 475 * Display invitation acceptance status. 476 * 477 * @since 8.0.0 478 * 479 * @param BP_Invitation $invite BP_Invitation object. 480 */ 481 public function column_invitation_accepted( $invite = null ) { 482 if ( $invite->accepted ) { 483 esc_html_e( 'Yes', 'buddypress' ); 484 } else { 485 esc_html_e( 'No', 'buddypress' ); 486 } 487 } 488 489 /** 490 * Allow plugins to add their custom column. 491 * 492 * @since 8.0.0 493 * 494 * @param BP_Invitation $invite BP_Invitation object. 495 * @param string $column_name The column name. 496 * @return string 497 */ 498 function column_default( $invite = null, $column_name = '' ) { 499 500 /** 501 * Filters the single site custom columns for plugins. 502 * 503 * @since 8.0.0 504 * 505 * @param string $column_name The column name. 506 * @param object $invite The BP_Invitation object.. 507 */ 508 return apply_filters( 'bp_members_invitations_management_custom_column', '', $column_name, $invite ); 509 } 510 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |