[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/classes/ -> class-bp-members-invitations-list-table.php (source)

   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       * Get the list of views available on this table (e.g. "all", "public").
 107       *
 108       * @since 8.0.0
 109       */
 110  	public function views() {
 111          $tools_url = bp_get_admin_url( 'tools.php' );
 112  
 113          if ( is_network_admin() ) {
 114              $tools_url = network_admin_url( 'admin.php' );
 115          }
 116  
 117          $url_base = add_query_arg(
 118              array(
 119                  'page' => 'bp-members-invitations',
 120              ),
 121              $tools_url
 122          );
 123          ?>
 124  
 125          <h2 class="screen-reader-text">
 126              <?php
 127              /* translators: accessibility text */
 128              esc_html_e( 'Filter invitations list', 'buddypress' );
 129              ?>
 130          </h2>
 131          <ul class="subsubsub">
 132              <li class="all">
 133                  <a href="<?php echo esc_url( $url_base ); ?>" class="<?php if ( empty( $this->active_filters ) ) echo 'current'; ?>">
 134                      <?php esc_html_e( 'All', 'buddypress' ); ?>
 135                  </a> |
 136              </li>
 137              <li class="pending">
 138                  <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'; ?>">
 139                      <?php esc_html_e( 'Pending', 'buddypress' ); ?>
 140                  </a> |
 141              </li>
 142              <li class="accepted">
 143                  <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'; ?>">
 144                      <?php esc_html_e( 'Accepted', 'buddypress' ); ?>
 145                  </a> |
 146              </li>
 147              <li class="draft">
 148                  <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'; ?>">
 149                      <?php esc_html_e( 'Draft (Unsent)', 'buddypress' ); ?>
 150                  </a> |
 151              </li>
 152              <li class="sent">
 153                  <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'; ?>">
 154                      <?php esc_html_e( 'Sent', 'buddypress' ); ?>
 155                  </a>
 156              </li>
 157  
 158              <?php
 159  
 160              /**
 161               * Fires inside listing of views so plugins can add their own.
 162               *
 163               * @since 8.0.0
 164               *
 165               * @param string $url_base       Current URL base for view.
 166               * @param array  $active_filters Current filters being requested.
 167               */
 168              do_action( 'bp_members_invitations_list_table_get_views', $url_base, $this->active_filters ); ?>
 169          </ul>
 170      <?php
 171      }
 172  
 173      /**
 174       * Get rid of the extra nav.
 175       *
 176       * WP_Users_List_Table will add an extra nav to change user's role.
 177       * As we're dealing with invitations, we don't need this.
 178       *
 179       * @since 8.0.0
 180       *
 181       * @param array $which Current table nav item.
 182       */
 183  	public function extra_tablenav( $which ) {
 184          return;
 185      }
 186  
 187      /**
 188       * Specific signups columns.
 189       *
 190       * @since 8.0.0
 191       *
 192       * @return array
 193       */
 194  	public function get_columns() {
 195  
 196          /**
 197           * Filters the single site Members signup columns.
 198           *
 199           * @since 8.0.0
 200           *
 201           * @param array $value Array of columns to display.
 202           */
 203          return apply_filters(
 204              'bp_members_invitations_list_columns',
 205              array(
 206                  'cb'                       => '<input type="checkbox" />',
 207                  'invitee_email'            => __( 'Invitee', 'buddypress' ),
 208                  'username'                 => __( 'Inviter', 'buddypress' ),
 209                  'inviter_registered_date'  => __( 'Inviter Registered', 'buddypress' ),
 210                  'invitation_date_modified' => __( 'Date Modified', 'buddypress' ),
 211                  'invitation_sent'          => __( 'Email Sent', 'buddypress' ),
 212                  'invitation_accepted'      => __( 'Accepted', 'buddypress' )
 213              )
 214          );
 215      }
 216  
 217      /**
 218       * Specific bulk actions for signups.
 219       *
 220       * @since 8.0.0
 221       */
 222  	public function get_bulk_actions() {
 223          $actions = array(
 224              'resend' => _x( 'Resend Email', 'Pending invitation action', 'buddypress' ),
 225          );
 226  
 227          if ( current_user_can( 'delete_users' ) ) {
 228              $actions['delete'] = _x( 'Delete', 'Pending invitation action', 'buddypress' );
 229          }
 230  
 231          return $actions;
 232      }
 233  
 234      /**
 235       * The text shown when no items are found.
 236       *
 237       * Nice job, clean sheet!
 238       *
 239       * @since 8.0.0
 240       */
 241  	public function no_items() {
 242  
 243          if ( bp_get_members_invitations_allowed() ) {
 244              esc_html_e( 'No invitations found.', 'buddypress' );
 245          } else {
 246              $link = sprintf(
 247                  '<a href="%1$s">%2$s</a>',
 248                  esc_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-settings' ), 'admin.php' ) ) ),
 249                  esc_html__( 'Edit settings', 'buddypress' )
 250              );
 251  
 252              /* translators: %s: url to site settings */
 253              printf( __( 'Invitations are not allowed. %s', 'buddypress' ), $link );
 254          }
 255  
 256      }
 257  
 258      /**
 259       * The columns invitations can be reordered by.
 260       *
 261       * @since 8.0.0
 262       */
 263  	public function get_sortable_columns() {
 264          return array(
 265              'invitee_email'            => 'invitee_email',
 266              'username'                 => 'inviter_id',
 267              'invitation_date_modified' => 'date_modified',
 268              'invitation_sent'          => 'invite_sent',
 269              'invitation_accepted'      => 'accepted',
 270          );
 271      }
 272  
 273      /**
 274       * Display invitation rows.
 275       *
 276       * @since 8.0.0
 277       */
 278  	public function display_rows() {
 279          $style = '';
 280          foreach ( $this->items as $invite ) {
 281              $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
 282              echo "\n\t" . $this->single_row( $invite, $style );
 283          }
 284      }
 285  
 286      /**
 287       * Display an invitation row.
 288       *
 289       * @since 8.0.0
 290       *
 291       * @see WP_List_Table::single_row() for explanation of params.
 292       *
 293       * @param BP_Invitation $invite   BP_Invitation object.
 294       * @param string        $style    Styles for the row.
 295       * @param string        $role     Role to be assigned to user.
 296       * @param int           $numposts Number of posts.
 297       * @return void
 298       */
 299  	public function single_row( $invite = null, $style = '', $role = '', $numposts = 0 ) {
 300          echo '<tr' . $style . ' id="invitation-' . esc_attr( $invite->id ) . '">';
 301          echo $this->single_row_columns( $invite );
 302          echo '</tr>';
 303      }
 304  
 305      /**
 306       * Markup for the checkbox used to select items for bulk actions.
 307       *
 308       * @since 8.0.0
 309       *
 310       * @param BP_Invitation $invite BP_Invitation object.
 311       */
 312  	public function column_cb( $invite = null ) {
 313          ?>
 314          <label class="screen-reader-text" for="invitation_<?php echo intval( $invite->id ); ?>">
 315              <?php
 316                  /* translators: accessibility text */
 317                  printf( esc_html__( 'Select invitation: %s', 'buddypress' ), $invite->id );
 318              ?>
 319          </label>
 320          <input type="checkbox" id="invitation_<?php echo intval( $invite->id ) ?>" name="invite_ids[]" value="<?php echo esc_attr( $invite->id ) ?>" />
 321          <?php
 322      }
 323  
 324      /**
 325       * Markup for the checkbox used to select items for bulk actions.
 326       *
 327       * @since 8.0.0
 328       *
 329       * @param BP_Invitation $invite BP_Invitation object.
 330       */
 331  	public function column_invitee_email( $invite = null ) {
 332          echo esc_html( $invite->invitee_email );
 333  
 334          $actions = array();
 335          $tools_url = bp_get_admin_url( 'tools.php' );
 336  
 337          if ( is_network_admin() ) {
 338              $tools_url = network_admin_url( 'admin.php' );
 339          }
 340  
 341          // Resend action only if pending
 342          if ( ! $invite->accepted ) {
 343              // Resend invitation email link.
 344              $email_link = add_query_arg(
 345                  array(
 346                      'page'        => 'bp-members-invitations',
 347                      'invite_id' => $invite->id,
 348                      'action'    => 'resend',
 349                  ),
 350                  $tools_url
 351              );
 352  
 353              if ( ! $invite->invite_sent ) {
 354                  $resend_label = __( 'Send', 'buddypress' );
 355              } else {
 356                  $resend_label = __( 'Resend', 'buddypress' );
 357              }
 358  
 359              $actions['resend'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $email_link ), esc_html( $resend_label ) );
 360          }
 361  
 362          // Delete link. Could be cleanup or revoking the invitation.
 363          $delete_link = add_query_arg(
 364              array(
 365                  'page'      => 'bp-members-invitations',
 366                  'invite_id' => $invite->id,
 367                  'action'    => 'delete',
 368              ),
 369              $tools_url
 370          );
 371  
 372          // Two cases: unsent and accepted (cleanup), and pending (cancels invite).
 373          if ( ! $invite->invite_sent || $invite->accepted ) {
 374              $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), esc_html__( 'Delete', 'buddypress' ) );
 375          } else {
 376              $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), esc_html__( 'Cancel', 'buddypress' ) );
 377          }
 378  
 379          /**
 380           * Filters the row actions for each invitation in list.
 381           *
 382           * @since 8.0.0
 383           *
 384           * @param array  $actions Array of actions and corresponding links.
 385           * @param object $invite  The BP_Invitation.
 386           */
 387          $actions = apply_filters( 'bp_members_invitations_management_row_actions', $actions, $invite );
 388  
 389          echo $this->row_actions( $actions );
 390      }
 391  
 392      /**
 393       * Display invited user's email address.
 394       *
 395       * @since 8.0.0
 396       *
 397       * @param BP_Invitation $invite BP_Invitation object.
 398       */
 399  	public function column_email( $invite = null ) {
 400          printf( '<a href="mailto:%1$s">%2$s</a>', esc_attr( $invite->user_email ), esc_html( $invite->user_email ) );
 401      }
 402  
 403      /**
 404       * The inviter.
 405       *
 406       * @since 8.0.0
 407       *
 408       * @param BP_Invitation $invite BP_Invitation object.
 409       */
 410  	public function column_username( $invite = null ) {
 411          $avatar  = get_avatar( $invite->inviter_id, 32 );
 412          $inviter = get_user_by( 'id', $invite->inviter_id );
 413          if ( ! $inviter ) {
 414              return;
 415          }
 416  
 417          $user_link = bp_core_get_user_domain( $invite->inviter_id );
 418  
 419          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 ) );
 420      }
 421  
 422      /**
 423       * Display invitation date.
 424       *
 425       * @since 8.0.0
 426       *
 427       * @param BP_Invitation $invite BP_Invitation object.
 428       */
 429  	public function column_inviter_registered_date( $invite = null ) {
 430          $inviter = get_user_by( 'id', $invite->inviter_id );
 431          if ( ! $inviter ) {
 432              return;
 433          }
 434          echo esc_html( $inviter->user_registered );
 435      }
 436  
 437      /**
 438       * Display invitation date.
 439       *
 440       * @since 8.0.0
 441       *
 442       * @param BP_Invitation $invite BP_Invitation object.
 443       */
 444  	public function column_invitation_date_modified( $invite = null ) {
 445          echo esc_html( $invite->date_modified );
 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_sent( $invite = null ) {
 456          if ( $invite->invite_sent) {
 457              esc_html_e( 'Yes', 'buddypress' );
 458          } else {
 459              esc_html_e( 'No', 'buddypress' );
 460          }
 461      }
 462  
 463      /**
 464       * Display invitation acceptance status.
 465       *
 466       * @since 8.0.0
 467       *
 468       * @param BP_Invitation $invite BP_Invitation object.
 469       */
 470  	public function column_invitation_accepted( $invite = null ) {
 471          if ( $invite->accepted ) {
 472              esc_html_e( 'Yes', 'buddypress' );
 473          } else {
 474              esc_html_e( 'No', 'buddypress' );
 475          }
 476      }
 477  
 478      /**
 479       * Allow plugins to add their custom column.
 480       *
 481       * @since 8.0.0
 482       *
 483       * @param BP_Invitation $invite      BP_Invitation object.
 484       * @param string        $column_name The column name.
 485       * @return string
 486       */
 487  	function column_default( $invite = null, $column_name = '' ) {
 488  
 489          /**
 490           * Filters the single site custom columns for plugins.
 491           *
 492           * @since 8.0.0
 493           *
 494           * @param string $column_name The column name.
 495           * @param object $invite      The BP_Invitation object..
 496           */
 497          return apply_filters( 'bp_members_invitations_management_custom_column', '', $column_name, $invite );
 498      }
 499  }


Generated: Fri Sep 24 01:01:36 2021 Cross-referenced by PHPXref 0.7.1