[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Sat Aug 8 01:01:33 2020 Cross-referenced by PHPXref 0.7.1