[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Sun Nov 29 01:01:38 2020 Cross-referenced by PHPXref 0.7.1