[ 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              printf( __( 'Registration is disabled. %s', 'buddypress' ), $link );
 199          }
 200  
 201      }
 202  
 203      /**
 204       * The columns signups can be reordered with.
 205       *
 206       * @since 2.0.0
 207       */
 208  	public function get_sortable_columns() {
 209          return array(
 210              'username'   => 'login',
 211              'email'      => 'email',
 212              'registered' => 'signup_id',
 213          );
 214      }
 215  
 216      /**
 217       * Display signups rows.
 218       *
 219       * @since 2.0.0
 220       */
 221  	public function display_rows() {
 222          $style = '';
 223          foreach ( $this->items as $userid => $signup_object ) {
 224  
 225              // Avoid a notice error appearing since 4.3.0.
 226              if ( isset( $signup_object->id ) ) {
 227                  $signup_object->ID = $signup_object->id;
 228              }
 229  
 230              $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
 231              echo "\n\t" . $this->single_row( $signup_object, $style );
 232          }
 233      }
 234  
 235      /**
 236       * Display a signup row.
 237       *
 238       * @since 2.0.0
 239       *
 240       * @see WP_List_Table::single_row() for explanation of params.
 241       *
 242       * @param object|null $signup_object Signup user object.
 243       * @param string      $style         Styles for the row.
 244       * @param string      $role          Role to be assigned to user.
 245       * @param int         $numposts      Numper of posts.
 246       * @return void
 247       */
 248  	public function single_row( $signup_object = null, $style = '', $role = '', $numposts = 0 ) {
 249          echo '<tr' . $style . ' id="signup-' . esc_attr( $signup_object->id ) . '">';
 250          echo $this->single_row_columns( $signup_object );
 251          echo '</tr>';
 252      }
 253  
 254      /**
 255       * Markup for the checkbox used to select items for bulk actions.
 256       *
 257       * @since 2.0.0
 258       *
 259       * @param object|null $signup_object The signup data object.
 260       */
 261  	public function column_cb( $signup_object = null ) {
 262      ?>
 263          <label class="screen-reader-text" for="signup_<?php echo intval( $signup_object->id ); ?>"><?php
 264              /* translators: accessibility text */
 265              printf( esc_html__( 'Select user: %s', 'buddypress' ), $signup_object->user_login );
 266          ?></label>
 267          <input type="checkbox" id="signup_<?php echo intval( $signup_object->id ) ?>" name="allsignups[]" value="<?php echo esc_attr( $signup_object->id ) ?>" />
 268          <?php
 269      }
 270  
 271      /**
 272       * The row actions (delete/activate/email).
 273       *
 274       * @since 2.0.0
 275       *
 276       * @param object|null $signup_object The signup data object.
 277       */
 278  	public function column_username( $signup_object = null ) {
 279          $avatar    = get_avatar( $signup_object->user_email, 32 );
 280  
 281          // Activation email link.
 282          $email_link = add_query_arg(
 283              array(
 284                  'page'        => 'bp-signups',
 285                  'signup_id' => $signup_object->id,
 286                  'action'    => 'resend',
 287              ),
 288              bp_get_admin_url( 'users.php' )
 289          );
 290  
 291          // Activate link.
 292          $activate_link = add_query_arg(
 293              array(
 294                  'page'      => 'bp-signups',
 295                  'signup_id' => $signup_object->id,
 296                  'action'    => 'activate',
 297              ),
 298              bp_get_admin_url( 'users.php' )
 299          );
 300  
 301          // Delete link.
 302          $delete_link = add_query_arg(
 303              array(
 304                  'page'      => 'bp-signups',
 305                  'signup_id' => $signup_object->id,
 306                  'action'    => 'delete',
 307              ),
 308              bp_get_admin_url( 'users.php' )
 309          );
 310  
 311          echo $avatar . sprintf( '<strong><a href="%1$s" class="edit">%2$s</a></strong><br/>', esc_url( $activate_link ), $signup_object->user_login );
 312  
 313          $actions = array();
 314  
 315          $actions['activate'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $activate_link ), __( 'Activate', 'buddypress' ) );
 316          $actions['resend']   = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $email_link ), __( 'Email', 'buddypress' ) );
 317  
 318          if ( current_user_can( 'delete_users' ) ) {
 319              $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), __( 'Delete', 'buddypress' ) );
 320          }
 321  
 322          /**
 323           * Filters the multisite row actions for each user in list.
 324           *
 325           * @since 2.0.0
 326           *
 327           * @param array  $actions       Array of actions and corresponding links.
 328           * @param object $signup_object The signup data object.
 329           */
 330          $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object );
 331  
 332          echo $this->row_actions( $actions );
 333      }
 334  
 335      /**
 336       * Display user name, if any.
 337       *
 338       * @since 2.0.0
 339       *
 340       * @param object|null $signup_object The signup data object.
 341       */
 342  	public function column_name( $signup_object = null ) {
 343          echo esc_html( $signup_object->user_name );
 344      }
 345  
 346      /**
 347       * Display user email.
 348       *
 349       * @since 2.0.0
 350       *
 351       * @param object|null $signup_object The signup data object.
 352       */
 353  	public function column_email( $signup_object = null ) {
 354          printf( '<a href="mailto:%1$s">%2$s</a>', esc_attr( $signup_object->user_email ), esc_html( $signup_object->user_email ) );
 355      }
 356  
 357      /**
 358       * Display registration date.
 359       *
 360       * @since 2.0.0
 361       *
 362       * @param object|null $signup_object The signup data object.
 363       */
 364  	public function column_registered( $signup_object = null ) {
 365          echo mysql2date( 'Y/m/d', $signup_object->registered );
 366      }
 367  
 368      /**
 369       * Display the last time an activation email has been sent.
 370       *
 371       * @since 2.0.0
 372       *
 373       * @param object|null $signup_object The signup data object.
 374       */
 375  	public function column_date_sent( $signup_object = null ) {
 376          echo mysql2date( 'Y/m/d', $signup_object->date_sent );
 377      }
 378  
 379      /**
 380       * Display number of time an activation email has been sent.
 381       *
 382       * @since 2.0.0
 383       *
 384       * @param object|null $signup_object Signup object instance.
 385       */
 386  	public function column_count_sent( $signup_object = null ) {
 387          echo absint( $signup_object->count_sent );
 388      }
 389  
 390      /**
 391       * Allow plugins to add their custom column.
 392       *
 393       * @since 2.1.0
 394       *
 395       * @param object|null $signup_object The signup data object.
 396       * @param string      $column_name   The column name.
 397       * @return string
 398       */
 399  	function column_default( $signup_object = null, $column_name = '' ) {
 400  
 401          /**
 402           * Filters the single site custom columns for plugins.
 403           *
 404           * @since 2.1.0
 405           *
 406           * @param string $column_name   The column name.
 407           * @param object $signup_object The signup data object.
 408           */
 409          return apply_filters( 'bp_members_signup_custom_column', '', $column_name, $signup_object );
 410      }
 411  }


Generated: Wed Nov 13 01:01:39 2019 Cross-referenced by PHPXref 0.7.1