Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 05:15:55 AM (10 years ago)
Author:
boonebgorges
Message:

Move bp-members classes to their own files.

See #6870.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/classes/class-bp-members-ms-list-table.php

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