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-list-table.php

    r10515 r10521  
    11<?php
    22/**
    3  * BuddyPress Members List Classes.
     3 * BuddyPress Members List Table class.
    44 *
    55 * @package BuddyPress
     
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
    12 
    13 if ( class_exists( 'WP_Users_List_Table') ) :
    1412
    1513/**
     
    393391        }
    394392}
    395 
    396 endif;
    397 
    398 if ( class_exists( 'WP_MS_Users_List_Table' ) ) :
    399 
    400 /**
    401  * List table class for signups network admin page.
    402  *
    403  * @since 2.0.0
    404  */
    405 class BP_Members_MS_List_Table extends WP_MS_Users_List_Table {
    406 
    407         /**
    408          * Signup counts.
    409          *
    410          * @since 2.0.0
    411          *
    412          * @var int
    413          */
    414         public $signup_counts = 0;
    415 
    416         /**
    417          * Constructor.
    418          *
    419          * @since 2.0.0
    420          */
    421         public function __construct() {
    422                 // Define singular and plural labels, as well as whether we support AJAX.
    423                 parent::__construct( array(
    424                         'ajax'     => false,
    425                         'plural'   => 'signups',
    426                         'singular' => 'signup',
    427                 ) );
    428         }
    429 
    430         /**
    431          * Set up items for display in the list table.
    432          *
    433          * Handles filtering of data, sorting, pagination, and any other data
    434          * manipulation required prior to rendering.
    435          *
    436          * @since 2.0.0
    437          */
    438         public function prepare_items() {
    439                 global $usersearch, $mode;
    440 
    441                 $usersearch       = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    442                 $signups_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) );
    443                 $paged            = $this->get_pagenum();
    444 
    445                 $args = array(
    446                         'offset'     => ( $paged - 1 ) * $signups_per_page,
    447                         'number'     => $signups_per_page,
    448                         'usersearch' => $usersearch,
    449                         'orderby'    => 'signup_id',
    450                         'order'      => 'DESC'
    451                 );
    452 
    453                 if ( isset( $_REQUEST['orderby'] ) ) {
    454                         $args['orderby'] = $_REQUEST['orderby'];
    455                 }
    456 
    457                 if ( isset( $_REQUEST['order'] ) ) {
    458                         $args['order'] = $_REQUEST['order'];
    459                 }
    460 
    461                 $mode    = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
    462                 $signups = BP_Signup::get( $args );
    463 
    464                 $this->items         = $signups['signups'];
    465                 $this->signup_counts = $signups['total'];
    466 
    467                 $this->set_pagination_args( array(
    468                         'total_items' => $this->signup_counts,
    469                         'per_page'    => $signups_per_page,
    470                 ) );
    471         }
    472 
    473         /**
    474          * Get the views : the links above the WP List Table.
    475          *
    476          * @since 2.0.0
    477          *
    478          * @uses WP_MS_Users_List_Table::get_views() to get the users views.
    479          */
    480         public function get_views() {
    481                 $views = parent::get_views();
    482 
    483                 // Remove the 'current' class from the 'All' link.
    484                 $views['all']        = str_replace( 'class="current"', '', $views['all'] );
    485                 $views['registered'] = sprintf( '<a href="%1$s" class="current">%2$s</a>', esc_url( add_query_arg( 'page', 'bp-signups', network_admin_url( 'users.php' ) ) ), sprintf( _x( 'Pending %s', 'signup users', 'buddypress' ), '<span class="count">(' . number_format_i18n( $this->signup_counts ) . ')</span>' ) );
    486 
    487                 return $views;
    488         }
    489 
    490         /**
    491          * Specific signups columns.
    492          *
    493          * @since 2.0.0
    494          *
    495          * @return array
    496          */
    497         public function get_columns() {
    498 
    499                 /**
    500                  * Filters the multisite Members signup columns.
    501                  *
    502                  * @since 2.0.0
    503                  *
    504                  * @param array $value Array of columns to display.
    505                  */
    506                 return apply_filters( 'bp_members_ms_signup_columns', array(
    507                         'cb'         => '<input type="checkbox" />',
    508                         'username'   => __( 'Username',    'buddypress' ),
    509                         'name'       => __( 'Name',        'buddypress' ),
    510                         'email'      => __( 'Email',       'buddypress' ),
    511                         'registered' => __( 'Registered',  'buddypress' ),
    512                         'date_sent'  => __( 'Last Sent',   'buddypress' ),
    513                         'count_sent' => __( 'Emails Sent', 'buddypress' )
    514                 ) );
    515         }
    516 
    517         /**
    518          * Specific bulk actions for signups.
    519          *
    520          * @since 2.0.0
    521          */
    522         public function get_bulk_actions() {
    523                 $actions = array(
    524                         'activate' => _x( 'Activate', 'Pending signup action', 'buddypress' ),
    525                         'resend'   => _x( 'Email',    'Pending signup action', 'buddypress' ),
    526                 );
    527 
    528                 if ( current_user_can( 'delete_users' ) ) {
    529                         $actions['delete'] = __( 'Delete', 'buddypress' );
    530                 }
    531 
    532                 return $actions;
    533         }
    534 
    535         /**
    536          * The text shown when no items are found.
    537          *
    538          * Nice job, clean sheet!
    539          *
    540          * @since 2.0.0
    541          */
    542         public function no_items() {
    543                 if ( bp_get_signup_allowed() ) {
    544                         esc_html_e( 'No pending accounts found.', 'buddypress' );
    545                 } else {
    546                         $link = false;
    547 
    548                         if ( current_user_can( 'manage_network_users' ) ) {
    549                                 $link = sprintf( '<a href="%1$s">%2$s</a>', esc_url( network_admin_url( 'settings.php' ) ), esc_html__( 'Edit settings', 'buddypress' ) );
    550                         }
    551 
    552                         printf( __( 'Registration is disabled. %s', 'buddypress' ), $link );
    553                 }
    554         }
    555 
    556         /**
    557          * The columns signups can be reordered with.
    558          *
    559          * @since 2.0.0
    560          */
    561         public function get_sortable_columns() {
    562                 return array(
    563                         'username'   => 'login',
    564                         'email'      => 'email',
    565                         'registered' => 'signup_id',
    566                 );
    567         }
    568 
    569         /**
    570          * Display signups rows.
    571          *
    572          * @since 2.0.0
    573          */
    574         public function display_rows() {
    575                 $style = '';
    576                 foreach ( $this->items as $userid => $signup_object ) {
    577 
    578                         // Avoid a notice error appearing since 4.3.0.
    579                         if ( isset( $signup_object->id ) ) {
    580                                 $signup_object->ID = $signup_object->id;
    581                         }
    582 
    583                         $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
    584                         echo "\n\t" . $this->single_row( $signup_object, $style );
    585                 }
    586         }
    587 
    588         /**
    589          * Display a signup row.
    590          *
    591          * @since 2.0.0
    592          *
    593          * @see WP_List_Table::single_row() for explanation of params.
    594          *
    595          * @param object|null $signup_object Signup user object.
    596          * @param string      $style         Styles for the row.
    597          */
    598         public function single_row( $signup_object = null, $style = '' ) {
    599                 echo '<tr' . $style . ' id="signup-' . esc_attr( $signup_object->id ) . '">';
    600                 echo $this->single_row_columns( $signup_object );
    601                 echo '</tr>';
    602         }
    603 
    604         /**
    605          * Prevents regular users row actions to be output.
    606          *
    607          * @since 2.4.0
    608          *
    609          * @param object|null $signup_object Signup being acted upon.
    610          * @param string      $column_name   Current column name.
    611          * @param string      $primary       Primary column name.
    612          * @return string
    613          */
    614         protected function handle_row_actions( $signup_object = null, $column_name = '', $primary = '' ) {
    615                 return '';
    616         }
    617 
    618         /**
    619          * Markup for the checkbox used to select items for bulk actions.
    620          *
    621          * @since 2.0.0
    622          *
    623          * @param object|null $signup_object The signup data object.
    624          */
    625         public function column_cb( $signup_object = null ) {
    626         ?>
    627                 <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>
    628                 <input type="checkbox" id="signup_<?php echo intval( $signup_object->id ) ?>" name="allsignups[]" value="<?php echo esc_attr( $signup_object->id ) ?>" />
    629                 <?php
    630         }
    631 
    632         /**
    633          * The row actions (delete/activate/email).
    634          *
    635          * @since 2.0.0
    636          *
    637          * @param object|null $signup_object The signup data object.
    638          */
    639         public function column_username( $signup_object = null ) {
    640                 $avatar = get_avatar( $signup_object->user_email, 32 );
    641 
    642                 // Activation email link.
    643                 $email_link = add_query_arg(
    644                         array(
    645                                 'page'      => 'bp-signups',
    646                                 'signup_id' => $signup_object->id,
    647                                 'action'    => 'resend',
    648                         ),
    649                         network_admin_url( 'users.php' )
    650                 );
    651 
    652                 // Activate link.
    653                 $activate_link = add_query_arg(
    654                         array(
    655                                 'page'      => 'bp-signups',
    656                                 'signup_id' => $signup_object->id,
    657                                 'action'    => 'activate',
    658                         ),
    659                         network_admin_url( 'users.php' )
    660                 );
    661 
    662                 // Delete link.
    663                 $delete_link = add_query_arg(
    664                         array(
    665                                 'page'      => 'bp-signups',
    666                                 'signup_id' => $signup_object->id,
    667                                 'action'    => 'delete',
    668                         ),
    669                         network_admin_url( 'users.php' )
    670                 );
    671 
    672                 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 );
    673 
    674                 $actions = array();
    675 
    676                 $actions['activate'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $activate_link ), __( 'Activate', 'buddypress' ) );
    677                 $actions['resend']   = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $email_link    ), __( 'Email',    'buddypress' ) );
    678 
    679                 if ( current_user_can( 'delete_users' ) ) {
    680                         $actions['delete'] = sprintf( '<a href="%1$s" class="delete">%2$s</a>', esc_url( $delete_link ), __( 'Delete', 'buddypress' ) );
    681                 }
    682 
    683                 /** This filter is documented in bp-members/admin/bp-members-classes.php */
    684                 $actions = apply_filters( 'bp_members_ms_signup_row_actions', $actions, $signup_object );
    685 
    686                 echo $this->row_actions( $actions );
    687         }
    688 
    689         /**
    690          * Display user name, if any.
    691          *
    692          * @since 2.0.0
    693          *
    694          * @param object|null $signup_object The signup data object.
    695          */
    696         public function column_name( $signup_object = null ) {
    697                 echo esc_html( $signup_object->user_name );
    698         }
    699 
    700         /**
    701          * Display user email.
    702          *
    703          * @since 2.0.0
    704          *
    705          * @param object|null $signup_object The signup data object.
    706          */
    707         public function column_email( $signup_object = null ) {
    708                 printf( '<a href="mailto:%1$s">%2$s</a>', esc_attr( $signup_object->user_email ), esc_html( $signup_object->user_email ) );
    709         }
    710 
    711         /**
    712          * Display registration date.
    713          *
    714          * @since 2.0.0
    715          *
    716          * @param object|null $signup_object The signup data object.
    717          */
    718         public function column_registered( $signup_object = null ) {
    719                 global $mode;
    720 
    721                 if ( 'list' === $mode ) {
    722                         $date = 'Y/m/d';
    723                 } else {
    724                         $date = 'Y/m/d \<\b\r \/\> g:i:s a';
    725                 }
    726 
    727                 echo mysql2date( $date, $signup_object->registered ) . "</td>";
    728         }
    729 
    730         /**
    731          * Display the last time an activation email has been sent.
    732          *
    733          * @since 2.0.0
    734          *
    735          * @param object|null $signup_object Signup object instance.
    736          */
    737         public function column_date_sent( $signup_object = null ) {
    738                 global $mode;
    739 
    740                 if ( 'list' === $mode ) {
    741                         $date = 'Y/m/d';
    742                 } else {
    743                         $date = 'Y/m/d \<\b\r \/\> g:i:s a';
    744                 }
    745 
    746                 echo mysql2date( $date, $signup_object->date_sent );
    747         }
    748 
    749         /**
    750          * Display number of time an activation email has been sent.
    751          *
    752          * @since 2.0.0
    753          *
    754          * @param object|null $signup_object Signup object instance.
    755          */
    756         public function column_count_sent( $signup_object = null ) {
    757                 echo absint( $signup_object->count_sent );
    758         }
    759 
    760         /**
    761          * Allow plugins to add their custom column.
    762          *
    763          * @since 2.1.0
    764          *
    765          * @param object|null $signup_object The signup data object.
    766          * @param string      $column_name   The column name.
    767          * @return string
    768          */
    769         function column_default( $signup_object = null, $column_name = '' ) {
    770 
    771                 /**
    772                  * Filters the multisite custom columns for plugins.
    773                  *
    774                  * @since 2.1.0
    775                  *
    776                  * @param string $column_name   The column name.
    777                  * @param object $signup_object The signup data object.
    778                  */
    779                 return apply_filters( 'bp_members_ms_signup_custom_column', '', $column_name, $signup_object );
    780         }
    781 }
    782 
    783 endif;
Note: See TracChangeset for help on using the changeset viewer.