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


Generated: Wed Jul 17 01:01:40 2019 Cross-referenced by PHPXref 0.7.1