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


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1