Skip to:
Content

BuddyPress.org

Changeset 10521


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

Move bp-members classes to their own files.

See #6870.

Location:
trunk/src/bp-members
Files:
6 edited
10 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/admin/bp-members-admin-classes.php

    r10456 r10521  
    1111defined( 'ABSPATH' ) || exit;
    1212
    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     }
     13if ( class_exists( 'WP_Users_List_Table' ) ) {
     14    require dirname( dirname( __FILE__ ) ) . '/classes/class-bp-members-list-table.php';
    39415}
    39516
    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     }
     17if ( class_exists( 'WP_MS_Users_List_Table' ) ) {
     18    require dirname( dirname( __FILE__ ) ) . '/classes/class-bp-members-ms-list-table.php';
    78119}
    782 
    783 endif;
  • trunk/src/bp-members/bp-members-admin.php

    r10461 r10521  
    1111defined( 'ABSPATH' ) || exit;
    1212
    13 if ( !class_exists( 'BP_Members_Admin' ) ) :
    14 
    15 /**
    16  * Load Members admin area.
    17  *
    18  * @since 2.0.0
    19  */
    20 class BP_Members_Admin {
    21 
    22     /** Directory *************************************************************/
    23 
    24     /**
    25      * Path to the BP Members Admin directory.
    26      *
    27      * @var string $admin_dir
    28      */
    29     public $admin_dir = '';
    30 
    31     /** URLs ******************************************************************/
    32 
    33     /**
    34      * URL to the BP Members Admin directory.
    35      *
    36      * @var string $admin_url
    37      */
    38     public $admin_url = '';
    39 
    40     /**
    41      * URL to the BP Members Admin CSS directory.
    42      *
    43      * @var string $css_url
    44      */
    45     public $css_url = '';
    46 
    47     /**
    48      * URL to the BP Members Admin JS directory.
    49      *
    50      * @var string
    51      */
    52     public $js_url = '';
    53 
    54     /** Other *****************************************************************/
    55 
    56     /**
    57      * Screen id for edit user's profile page.
    58      *
    59      * @var string
    60      */
    61     public $user_page = '';
    62 
    63     /**
    64      * Setup BP Members Admin.
    65      *
    66      * @since 2.0.0
    67      *
    68      * @uses buddypress() to get BuddyPress main instance.
    69      */
    70     public static function register_members_admin() {
    71         if ( ! is_admin() ) {
    72             return;
    73         }
    74 
    75         $bp = buddypress();
    76 
    77         if ( empty( $bp->members->admin ) ) {
    78             $bp->members->admin = new self;
    79         }
    80 
    81         return $bp->members->admin;
    82     }
    83 
    84     /**
    85      * Constructor method.
    86      *
    87      * @since 2.0.0
    88      */
    89     public function __construct() {
    90         $this->setup_globals();
    91         $this->setup_actions();
    92     }
    93 
    94     /**
    95      * Set admin-related globals.
    96      *
    97      * @since 2.0.0
    98      */
    99     private function setup_globals() {
    100         $bp = buddypress();
    101 
    102         // Paths and URLs
    103         $this->admin_dir = trailingslashit( $bp->plugin_dir  . 'bp-members/admin' ); // Admin path.
    104         $this->admin_url = trailingslashit( $bp->plugin_url  . 'bp-members/admin' ); // Admin URL.
    105         $this->css_url   = trailingslashit( $this->admin_url . 'css' ); // Admin CSS URL.
    106         $this->js_url    = trailingslashit( $this->admin_url . 'js'  ); // Admin CSS URL.
    107 
    108         // Capability depends on config.
    109         $this->capability = bp_core_do_network_admin() ? 'manage_network_users' : 'edit_users';
    110 
    111         // The Edit Profile Screen id.
    112         $this->user_page = '';
    113 
    114         // The Show Profile Screen id.
    115         $this->user_profile = is_network_admin() ? 'users' : 'profile';
    116 
    117         // The current user id.
    118         $this->current_user_id = get_current_user_id();
    119 
    120         // The user id being edited.
    121         $this->user_id = 0;
    122 
    123         // Is a member editing their own profile.
    124         $this->is_self_profile = false;
    125 
    126         // The screen ids to load specific css for.
    127         $this->screen_id = array();
    128 
    129         // The stats metabox default position.
    130         $this->stats_metabox = new StdClass();
    131 
    132         // BuddyPress edit user's profile args.
    133         $this->edit_profile_args = array( 'page' => 'bp-profile-edit' );
    134         $this->edit_profile_url  = '';
    135         $this->edit_url          = '';
    136 
    137         // Data specific to signups.
    138         $this->users_page   = '';
    139         $this->signups_page = '';
    140         $this->users_url    = bp_get_admin_url( 'users.php' );
    141         $this->users_screen = bp_core_do_network_admin() ? 'users-network' : 'users';
    142 
    143         // Specific config: BuddyPress is not network activated.
    144         $this->subsite_activated = (bool) is_multisite() && ! bp_is_network_activated();
    145 
    146         // When BuddyPress is not network activated, only Super Admin can moderate signups.
    147         if ( ! empty( $this->subsite_activated ) ) {
    148             $this->capability = 'manage_network_users';
    149         }
    150     }
    151 
    152     /**
    153      * Set admin-related actions and filters.
    154      *
    155      * @since 2.0.0
    156      */
    157     private function setup_actions() {
    158 
    159         /** Extended Profile *************************************************
    160          */
    161 
    162         // Enqueue all admin JS and CSS.
    163         add_action( 'bp_admin_enqueue_scripts', array( $this, 'enqueue_scripts'   )        );
    164 
    165         // Add some page specific output to the <head>.
    166         add_action( 'bp_admin_head',            array( $this, 'admin_head'        ), 999   );
    167 
    168         // Add menu item to all users menu.
    169         add_action( 'admin_menu',               array( $this, 'admin_menus'       ), 5     );
    170         add_action( 'network_admin_menu',       array( $this, 'admin_menus'       ), 5     );
    171         add_action( 'user_admin_menu',          array( $this, 'user_profile_menu' ), 5     );
    172 
    173         // Create the Profile Navigation (Profile/Extended Profile).
    174         add_action( 'edit_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
    175         add_action( 'show_user_profile',        array( $this, 'profile_nav'       ), 99, 1 );
    176 
    177         // Editing users of a specific site.
    178         add_action( "admin_head-site-users.php", array( $this, 'profile_admin_head' ) );
    179 
    180         // Add a row action to users listing.
    181         if ( bp_core_do_network_admin() ) {
    182             add_filter( 'ms_user_row_actions',        array( $this, 'row_actions'                    ), 10, 2 );
    183             add_action( 'admin_init',                 array( $this, 'add_edit_profile_url_filter'    )        );
    184             add_action( 'wp_after_admin_bar_render',  array( $this, 'remove_edit_profile_url_filter' )        );
    185         }
    186 
    187         // Add user row actions for single site.
    188         add_filter( 'user_row_actions', array( $this, 'row_actions' ), 10, 2 );
    189 
    190         // Process changes to member type.
    191         add_action( 'bp_members_admin_load', array( $this, 'process_member_type_update' ) );
    192 
    193         /** Signups **********************************************************
    194          */
    195 
    196         if ( is_admin() ) {
    197 
    198             // Filter non multisite user query to remove sign-up users.
    199             if ( ! is_multisite() ) {
    200                 add_action( 'pre_user_query', array( $this, 'remove_signups_from_user_query' ), 10, 1 );
    201             }
    202 
    203             // Reorganise the views navigation in users.php and signups page.
    204             if ( current_user_can( $this->capability ) ) {
    205                 $user_screen = $this->users_screen;
    206 
    207                 /**
    208                  * Users screen on multiblog is users, but signups
    209                  * need to be managed in the network for this case
    210                  */
    211                 if ( bp_is_network_activated() && bp_is_multiblog_mode() && false === strpos( $user_screen, '-network' ) ) {
    212                     $user_screen .= '-network';
    213                 }
    214 
    215                 add_filter( "views_{$user_screen}", array( $this, 'signup_filter_view'    ), 10, 1 );
    216                 add_filter( 'set-screen-option',    array( $this, 'signup_screen_options' ), 10, 3 );
    217             }
    218         }
    219     }
    220 
    221     /**
    222      * Get the user ID.
    223      *
    224      * Look for $_GET['user_id']. If anything else, force the user ID to the
    225      * current user's ID so they aren't left without a user to edit.
    226      *
    227      * @since 2.1.0
    228      *
    229      * @return int
    230      */
    231     private function get_user_id() {
    232         if ( ! empty( $this->user_id ) ) {
    233             return $this->user_id;
    234         }
    235 
    236         $this->user_id = (int) get_current_user_id();
    237 
    238         // We'll need a user ID when not on self profile.
    239         if ( ! empty( $_GET['user_id'] ) ) {
    240             $this->user_id = (int) $_GET['user_id'];
    241         }
    242 
    243         return $this->user_id;
    244     }
    245 
    246     /**
    247      * Can the current user edit the one displayed.
    248      *
    249      * Self profile editing / or bp_moderate check.
    250      * This might be replaced by more granular capabilities
    251      * in the future.
    252      *
    253      * @since 2.1.0
    254      *
    255      * @param int $user_id ID of the user being checked for edit ability.
    256      *
    257      * @return bool
    258      */
    259     private function member_can_edit( $user_id = 0 ) {
    260         $retval = false;
    261 
    262         // Bail if no user ID was passed.
    263         if ( empty( $user_id ) ) {
    264             return $retval;
    265         }
    266 
    267         // Member can edit if they are viewing their own profile.
    268         if ( $this->current_user_id === $user_id ) {
    269             $retval = true;
    270 
    271         // Trust the 'bp_moderate' capability.
    272         } else {
    273             $retval = bp_current_user_can( 'bp_moderate' );
    274         }
    275 
    276         return $retval;
    277     }
    278 
    279     /**
    280      * Get admin notice when saving a user or member profile.
    281      *
    282      * @since 2.1.0
    283      *
    284      * @return array
    285      */
    286     private function get_user_notice() {
    287 
    288         // Setup empty notice for return value.
    289         $notice = array();
    290 
    291         // Updates.
    292         if ( ! empty( $_REQUEST['updated'] ) ) {
    293             switch ( $_REQUEST['updated'] ) {
    294             case 'avatar':
    295                 $notice = array(
    296                     'class'   => 'updated',
    297                     'message' => __( 'Profile photo was deleted.', 'buddypress' )
    298                 );
    299                 break;
    300             case 'ham' :
    301                 $notice = array(
    302                     'class'   => 'updated',
    303                     'message' => __( 'User removed as spammer.', 'buddypress' )
    304                 );
    305                 break;
    306             case 'spam' :
    307                 $notice = array(
    308                     'class'   => 'updated',
    309                     'message' => __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' )
    310                 );
    311                 break;
    312             case 1 :
    313                 $notice = array(
    314                     'class'   => 'updated',
    315                     'message' => __( 'Profile updated.', 'buddypress' )
    316                 );
    317                 break;
    318             }
    319         }
    320 
    321         // Errors.
    322         if ( ! empty( $_REQUEST['error'] ) ) {
    323             switch ( $_REQUEST['error'] ) {
    324             case 'avatar':
    325                 $notice = array(
    326                     'class'   => 'error',
    327                     'message' => __( 'There was a problem deleting that profile photo. Please try again.', 'buddypress' )
    328                 );
    329                 break;
    330             case 'ham' :
    331                 $notice = array(
    332                     'class'   => 'error',
    333                     'message' => __( 'User could not be removed as spammer.', 'buddypress' )
    334                 );
    335                 break;
    336             case 'spam' :
    337                 $notice = array(
    338                     'class'   => 'error',
    339                     'message' => __( 'User could not be marked as spammer.', 'buddypress' )
    340                 );
    341                 break;
    342             case 1 :
    343                 $notice = array(
    344                     'class'   => 'error',
    345                     'message' => __( 'An error occurred while trying to update the profile.', 'buddypress' )
    346                 );
    347                 break;
    348             case 2:
    349                 $notice = array(
    350                     'class'   => 'error',
    351                     'message' => __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' )
    352                 );
    353                 break;
    354             case 3:
    355                 $notice = array(
    356                     'class'   => 'error',
    357                     'message' => __( 'There was a problem updating some of your profile information. Please try again.', 'buddypress' )
    358                 );
    359                 break;
    360             }
    361         }
    362 
    363         return $notice;
    364     }
    365 
    366     /**
    367      * Create the /user/ admin Profile submenus for all members.
    368      *
    369      * @since 2.1.0
    370      *
    371      * @uses add_submenu_page() To add the Edit Profile page in Profile section.
    372      */
    373     public function user_profile_menu() {
    374 
    375         // Setup the hooks array.
    376         $hooks = array();
    377 
    378         // Add the faux "Edit Profile" submenu page.
    379         $hooks['user'] = $this->user_page = add_submenu_page(
    380             'profile.php',
    381             __( 'Edit Profile',  'buddypress' ),
    382             __( 'Edit Profile',  'buddypress' ),
    383             'exist',
    384             'bp-profile-edit',
    385             array( $this, 'user_admin' )
    386         );
    387 
    388         // Setup the screen ID's.
    389         $this->screen_id = array(
    390             $this->user_page    . '-user',
    391             $this->user_profile . '-user'
    392         );
    393 
    394         // Loop through new hooks and add method actions.
    395         foreach ( $hooks as $key => $hook ) {
    396             add_action( "load-{$hook}", array( $this, $key . '_admin_load' ) );
    397         }
    398 
    399         // Add the profile_admin_head method to proper admin_head actions.
    400         add_action( "admin_head-{$this->user_page}", array( $this, 'profile_admin_head' ) );
    401         add_action( "admin_head-profile.php",        array( $this, 'profile_admin_head' ) );
    402     }
    403 
    404     /**
    405      * Create the All Users / Profile > Edit Profile and All Users Signups submenus.
    406      *
    407      * @since 2.0.0
    408      *
    409      * @uses add_submenu_page() To add the Edit Profile page in Users/Profile section.
    410      */
    411     public function admin_menus() {
    412 
    413         // Setup the hooks array.
    414         $hooks = array();
    415 
    416         // Manage user's profile.
    417         $hooks['user'] = $this->user_page = add_submenu_page(
    418             $this->user_profile . '.php',
    419             __( 'Edit Profile',  'buddypress' ),
    420             __( 'Edit Profile',  'buddypress' ),
    421             'read',
    422             'bp-profile-edit',
    423             array( $this, 'user_admin' )
    424         );
    425 
    426         // Only show sign-ups where they belong.
    427         if ( ( ! bp_is_network_activated() && ! is_network_admin() ) || ( is_network_admin() && bp_is_network_activated() ) ) {
    428 
    429             // Manage signups.
    430             $hooks['signups'] = $this->signups_page = add_users_page(
    431                 __( 'Manage Signups',  'buddypress' ),
    432                 __( 'Manage Signups',  'buddypress' ),
    433                 $this->capability,
    434                 'bp-signups',
    435                 array( $this, 'signups_admin' )
    436             );
    437         }
    438 
    439         $edit_page         = 'user-edit';
    440         $profile_page      = 'profile';
    441         $this->users_page  = 'users';
    442 
    443         // Self profile check is needed for this pages.
    444         $page_head = array(
    445             $edit_page        . '.php',
    446             $profile_page     . '.php',
    447             $this->user_page,
    448             $this->users_page . '.php',
    449         );
    450 
    451         // Append '-network' to each array item if in network admin.
    452         if ( is_network_admin() ) {
    453             $edit_page          .= '-network';
    454             $profile_page       .= '-network';
    455             $this->user_page    .= '-network';
    456             $this->users_page   .= '-network';
    457             $this->signups_page .= '-network';
    458         }
    459 
    460         // Setup the screen ID's.
    461         $this->screen_id = array(
    462             $edit_page,
    463             $this->user_page,
    464             $profile_page
    465         );
    466 
    467         // Loop through new hooks and add method actions.
    468         foreach ( $hooks as $key => $hook ) {
    469             add_action( "load-{$hook}", array( $this, $key . '_admin_load' ) );
    470         }
    471 
    472         // Add the profile_admin_head method to proper admin_head actions.
    473         foreach ( $page_head as $head ) {
    474             add_action( "admin_head-{$head}", array( $this, 'profile_admin_head' ) );
    475         }
    476     }
    477 
    478     /**
    479      * Highlight the Users menu if on Edit Profile and check if on the user's admin profile.
    480      *
    481      * @since 2.1.0
    482      */
    483     public function profile_admin_head() {
    484         global $submenu_file, $parent_file;
    485 
    486         // Is the user editing their own profile?
    487         if ( is_user_admin() || ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) ) {
    488             $this->is_self_profile = true;
    489 
    490         // Is the user attempting to edit their own profile.
    491         } elseif ( isset( $_GET['user_id' ] ) || ( isset( $_GET['page'] ) && ( 'bp-profile-edit' === $_GET['page'] ) ) ) {
    492             $this->is_self_profile = (bool) ( $this->get_user_id() === $this->current_user_id );
    493         }
    494 
    495         // Force the parent file to users.php to open the correct top level menu
    496         // but only if not editing a site via the network site editing page.
    497         if ( 'sites.php' !== $parent_file ) {
    498             $parent_file  = 'users.php';
    499             $submenu_file = 'users.php';
    500         }
    501 
    502         // Editing your own profile, so recheck some vars.
    503         if ( true === $this->is_self_profile ) {
    504 
    505             // Use profile.php as the edit page.
    506             $edit_page = 'profile.php';
    507 
    508             // Set profile.php as the parent & sub files to correct the menu nav.
    509             if ( is_blog_admin() || is_user_admin() ) {
    510                 $parent_file  = 'profile.php';
    511                 $submenu_file = 'profile.php';
    512             }
    513 
    514         // Not editing yourself, so use user-edit.php.
    515         } else {
    516             $edit_page = 'user-edit.php';
    517         }
    518 
    519         if ( is_user_admin() ) {
    520             $this->edit_profile_url = add_query_arg( $this->edit_profile_args, user_admin_url( 'profile.php' ) );
    521             $this->edit_url         = user_admin_url( 'profile.php' );
    522 
    523         } elseif ( is_blog_admin() ) {
    524             $this->edit_profile_url = add_query_arg( $this->edit_profile_args, admin_url( 'users.php' ) );
    525             $this->edit_url         = admin_url( $edit_page );
    526 
    527         } elseif ( is_network_admin() ) {
    528             $this->edit_profile_url = add_query_arg( $this->edit_profile_args, network_admin_url( 'users.php' ) );
    529             $this->edit_url         = network_admin_url( $edit_page );
    530         }
    531     }
    532 
    533     /**
    534      * Remove the Edit Profile page.
    535      *
    536      * We add these pages in order to integrate with WP's Users panel, but
    537      * we want them to show up as a row action of the WP panel, not as separate
    538      * subnav items under the Users menu.
    539      *
    540      * @since 2.0.0
    541      */
    542     public function admin_head() {
    543         remove_submenu_page( 'users.php',   'bp-profile-edit' );
    544         remove_submenu_page( 'profile.php', 'bp-profile-edit' );
    545     }
    546 
    547     /** Community Profile *****************************************************/
    548 
    549     /**
    550      * Add some specific styling to the Edit User and Edit User's Profile page.
    551      *
    552      * @since 2.0.0
    553      */
    554     public function enqueue_scripts() {
    555         if ( ! in_array( get_current_screen()->id, $this->screen_id ) ) {
    556             return;
    557         }
    558 
    559         $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    560         $css = $this->css_url . "admin{$min}.css";
    561 
    562         /**
    563          * Filters the CSS URL to enqueue in the Members admin area.
    564          *
    565          * @since 2.0.0
    566          *
    567          * @param string $css URL to the CSS admin file to load.
    568          */
    569         $css = apply_filters( 'bp_members_admin_css', $css );
    570 
    571         wp_enqueue_style( 'bp-members-css', $css, array(), bp_get_version() );
    572 
    573         wp_style_add_data( 'bp-members-css', 'rtl', true );
    574         if ( $min ) {
    575             wp_style_add_data( 'bp-members-css', 'suffix', $min );
    576         }
    577 
    578         // Only load JavaScript for BuddyPress profile.
    579         if ( get_current_screen()->id == $this->user_page ) {
    580             $js = $this->js_url . "admin{$min}.js";
    581 
    582             /**
    583              * Filters the JS URL to enqueue in the Members admin area.
    584              *
    585              * @since 2.0.0
    586              *
    587              * @param string $js URL to the JavaScript admin file to load.
    588              */
    589             $js = apply_filters( 'bp_members_admin_js', $js );
    590             wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
    591         }
    592 
    593         /**
    594          * Fires after all of the members JavaScript and CSS are enqueued.
    595          *
    596          * @since 2.0.0
    597          *
    598          * @param string $id        ID of the current screen.
    599          * @param array  $screen_id Array of allowed screens to add scripts and styles to.
    600          */
    601         do_action( 'bp_members_admin_enqueue_scripts', get_current_screen()->id, $this->screen_id );
    602     }
    603 
    604     /**
    605      * Create the Profile navigation in Edit User & Edit Profile pages.
    606      *
    607      * @since 2.0.0
    608      *
    609      * @param object|null $user   User to create profile navigation for.
    610      * @param string      $active Which profile to highlight.
    611      * @return string
    612      */
    613     public function profile_nav( $user = null, $active = 'WordPress' ) {
    614 
    615         // Bail if no user ID exists here.
    616         if ( empty( $user->ID ) ) {
    617             return;
    618         }
    619 
    620         // Add the user ID to query arguments when not editing yourself.
    621         if ( false === $this->is_self_profile ) {
    622             $query_args = array( 'user_id' => $user->ID );
    623         } else {
    624             $query_args = array();
    625         }
    626 
    627         // Conditionally add a referer if it exists in the existing request.
    628         if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
    629             $query_args['wp_http_referer'] = urlencode( stripslashes_deep( $_REQUEST['wp_http_referer'] ) );
    630         }
    631 
    632         // Setup the two distinct "edit" URL's.
    633         $community_url = add_query_arg( $query_args, $this->edit_profile_url );
    634         $wordpress_url = add_query_arg( $query_args, $this->edit_url         );
    635 
    636         $bp_active = false;
    637         $wp_active = ' nav-tab-active';
    638         if ( 'BuddyPress' === $active ) {
    639             $bp_active = ' nav-tab-active';
    640             $wp_active = false;
    641         } ?>
    642 
    643         <h2 id="profile-nav" class="nav-tab-wrapper">
    644             <?php
    645             /**
    646              * In configs where BuddyPress is not network activated, as regular
    647              * admins do not have the capacity to edit other users, we must add
    648              * this check.
    649              */
    650             if ( current_user_can( 'edit_user', $user->ID ) ) : ?>
    651 
    652                 <a class="nav-tab<?php echo esc_attr( $wp_active ); ?>" href="<?php echo esc_url( $wordpress_url );?>"><?php _e( 'Profile', 'buddypress' ); ?></a>
    653 
    654             <?php endif; ?>
    655 
    656             <a class="nav-tab<?php echo esc_attr( $bp_active ); ?>" href="<?php echo esc_url( $community_url );?>"><?php _e( 'Extended Profile', 'buddypress' ); ?></a>
    657         </h2>
    658 
    659         <?php
    660     }
    661 
    662     /**
    663      * Set up the user's profile admin page.
    664      *
    665      * Loaded before the page is rendered, this function does all initial
    666      * setup, including: processing form requests, registering contextual
    667      * help, and setting up screen options.
    668      *
    669      * @since 2.0.0
    670      */
    671     public function user_admin_load() {
    672 
    673         // Get the user ID.
    674         $user_id = $this->get_user_id();
    675 
    676         // Can current user edit this profile?
    677         if ( ! $this->member_can_edit( $user_id ) ) {
    678             wp_die( __( 'You cannot edit the requested user.', 'buddypress' ) );
    679         }
    680 
    681         // Build redirection URL.
    682         $redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'spam', 'ham', 'delete_avatar' ), $_SERVER['REQUEST_URI'] );
    683         $doaction    = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : false;
    684 
    685         if ( ! empty( $_REQUEST['user_status'] ) ) {
    686             $spam = (bool) ( 'spam' === $_REQUEST['user_status'] );
    687 
    688             if ( $spam !== bp_is_user_spammer( $user_id ) ) {
    689                 $doaction = $_REQUEST['user_status'];
    690             }
    691         }
    692 
    693         /**
    694          * Fires at the start of the signups admin load.
    695          *
    696          * @since 2.0.0
    697          *
    698          * @param string $doaction Current bulk action being processed.
    699          * @param array  $_REQUEST Current $_REQUEST global.
    700          */
    701         do_action_ref_array( 'bp_members_admin_load', array( $doaction, $_REQUEST ) );
    702 
    703         /**
    704          * Filters the allowed actions for use in the user admin page.
    705          *
    706          * @since 2.0.0
    707          *
    708          * @param array $value Array of allowed actions to use.
    709          */
    710         $allowed_actions = apply_filters( 'bp_members_admin_allowed_actions', array( 'update', 'delete_avatar', 'spam', 'ham' ) );
    711 
    712         // Prepare the display of the Community Profile screen.
    713         if ( ! in_array( $doaction, $allowed_actions ) ) {
    714             add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
    715 
    716             get_current_screen()->add_help_tab( array(
    717                 'id'      => 'bp-profile-edit-overview',
    718                 'title'   => __( 'Overview', 'buddypress' ),
    719                 'content' =>
    720                 '<p>' . __( 'This is the admin view of a user&#39;s profile.', 'buddypress' ) . '</p>' .
    721                 '<p>' . __( 'In the main column, you can edit the fields of the user&#39;s extended profile.', 'buddypress' ) . '</p>' .
    722                 '<p>' . __( 'In the right-hand column, you can update the user&#39;s status, delete the user&#39;s avatar, and view recent statistics.', 'buddypress' ) . '</p>'
    723             ) );
    724 
    725             // Help panel - sidebar links.
    726             get_current_screen()->set_help_sidebar(
    727                 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
    728                 '<p>' . __( '<a href="https://codex.buddypress.org/administrator-guide/extended-profiles/">Managing Profiles</a>', 'buddypress' ) . '</p>' .
    729                 '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
    730             );
    731 
    732             // Register metaboxes for the edit screen.
    733             add_meta_box(
    734                 'submitdiv',
    735                 _x( 'Status', 'members user-admin edit screen', 'buddypress' ),
    736                 array( $this, 'user_admin_status_metabox' ),
    737                 get_current_screen()->id,
    738                 'side',
    739                 'core'
    740             );
    741 
    742             // In case xprofile is not active.
    743             $this->stats_metabox->context  = 'normal';
    744             $this->stats_metabox->priority = 'core';
    745 
    746             /**
    747              * Fires before loading the profile fields if component is active.
    748              *
    749              * Plugins should not use this hook, please use 'bp_members_admin_user_metaboxes' instead.
    750              *
    751              * @since 2.0.0
    752              *
    753              * @param int    $user_id       Current user ID for the screen.
    754              * @param string $id            Current screen ID.
    755              * @param object $stats_metabox Object holding position data for use with the stats metabox.
    756              */
    757             do_action_ref_array( 'bp_members_admin_xprofile_metabox', array( $user_id, get_current_screen()->id, $this->stats_metabox ) );
    758 
    759             // If xProfile is inactive, difficult to know what's profile we're on.
    760             if ( 'normal' === $this->stats_metabox->context ) {
    761                 $display_name = bp_core_get_user_displayname( $user_id );
    762             } else {
    763                 $display_name = __( 'Member', 'buddypress' );
    764             }
    765 
    766             // User Stat metabox.
    767             add_meta_box(
    768                 'bp_members_admin_user_stats',
    769                 sprintf( _x( "%s's Stats", 'members user-admin edit screen', 'buddypress' ), $display_name ),
    770                 array( $this, 'user_admin_stats_metabox' ),
    771                 get_current_screen()->id,
    772                 sanitize_key( $this->stats_metabox->context ),
    773                 sanitize_key( $this->stats_metabox->priority )
    774             );
    775 
    776             // Member Type metabox. Only added if member types have been registered.
    777             $member_types = bp_get_member_types();
    778             if ( ! empty( $member_types ) ) {
    779                 add_meta_box(
    780                     'bp_members_admin_member_type',
    781                     _x( 'Member Type', 'members user-admin edit screen', 'buddypress' ),
    782                     array( $this, 'user_admin_member_type_metabox' ),
    783                     get_current_screen()->id,
    784                     'side',
    785                     'core'
    786                 );
    787             }
    788 
    789             /**
    790              * Fires at the end of the Community Profile screen.
    791              *
    792              * Plugins can restrict metabox to "bp_moderate" admins by checking if
    793              * the first argument ($this->is_self_profile) is false in their callback.
    794              * They can also restrict their metabox to self profile editing
    795              * by setting it to true.
    796              *
    797              * @since 2.0.0
    798              *
    799              * @param bool $is_self_profile Whether or not it is the current user's profile.
    800              * @param int  $user_id         Current user ID.
    801              */
    802             do_action( 'bp_members_admin_user_metaboxes', $this->is_self_profile, $user_id );
    803 
    804             // Enqueue JavaScript files.
    805             wp_enqueue_script( 'postbox'   );
    806             wp_enqueue_script( 'dashboard' );
    807 
    808         // Spam or Ham user.
    809         } elseif ( in_array( $doaction, array( 'spam', 'ham' ) ) && empty( $this->is_self_profile ) ) {
    810 
    811             check_admin_referer( 'edit-bp-profile_' . $user_id );
    812 
    813             if ( bp_core_process_spammer_status( $user_id, $doaction ) ) {
    814                 $redirect_to = add_query_arg( 'updated', $doaction, $redirect_to );
    815             } else {
    816                 $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
    817             }
    818 
    819             bp_core_redirect( $redirect_to );
    820 
    821         // Update other stuff once above ones are done.
    822         } else {
    823             $this->redirect = $redirect_to;
    824 
    825             /**
    826              * Fires at end of user profile admin load if doaction does not match any available actions.
    827              *
    828              * @since 2.0.0
    829              *
    830              * @param string $doaction Current bulk action being processed.
    831              * @param int    $user_id  Current user ID.
    832              * @param array  $_REQUEST Current $_REQUEST global.
    833              * @param string $redirect Determined redirect url to send user to.
    834              */
    835             do_action_ref_array( 'bp_members_admin_update_user', array( $doaction, $user_id, $_REQUEST, $this->redirect ) );
    836 
    837             bp_core_redirect( $this->redirect );
    838         }
    839     }
    840 
    841     /**
    842      * Display the user's profile.
    843      *
    844      * @since 2.0.0
    845      */
    846     public function user_admin() {
    847 
    848         if ( ! bp_current_user_can( 'bp_moderate' ) && empty( $this->is_self_profile ) ) {
    849             die( '-1' );
    850         }
    851 
    852         // Get the user ID.
    853         $user_id = $this->get_user_id();
    854         $user    = get_user_to_edit( $user_id );
    855 
    856         // Construct title.
    857         if ( true === $this->is_self_profile ) {
    858             $title = __( 'Profile',   'buddypress' );
    859         } else {
    860             $title = __( 'Edit User', 'buddypress' );
    861         }
    862 
    863         // Construct URL for form.
    864         $request_url     = remove_query_arg( array( 'action', 'error', 'updated', 'spam', 'ham' ), $_SERVER['REQUEST_URI'] );
    865         $form_action_url = add_query_arg( 'action', 'update', $request_url );
    866         $wp_http_referer = false;
    867         if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
    868             $wp_http_referer = remove_query_arg( array( 'action', 'updated' ), $_REQUEST['wp_http_referer'] );
    869         }
    870 
    871         // Prepare notice for admin.
    872         $notice = $this->get_user_notice();
    873 
    874         if ( ! empty( $notice ) ) : ?>
    875 
    876             <div <?php if ( 'updated' === $notice['class'] ) : ?>id="message" <?php endif; ?>class="<?php echo esc_attr( $notice['class'] ); ?>">
    877 
    878                 <p><?php echo esc_html( $notice['message'] ); ?></p>
    879 
    880                 <?php if ( !empty( $wp_http_referer ) && ( 'updated' === $notice['class'] ) ) : ?>
    881 
    882                     <p><a href="<?php echo esc_url( $wp_http_referer ); ?>"><?php esc_html_e( '&larr; Back to Users', 'buddypress' ); ?></a></p>
    883 
    884                 <?php endif; ?>
    885 
    886             </div>
    887 
    888         <?php endif; ?>
    889 
    890         <div class="wrap" id="community-profile-page">
    891             <h1><?php echo esc_html( $title ); ?>
    892 
    893                 <?php if ( empty( $this->is_self_profile ) ) : ?>
    894 
    895                     <?php if ( current_user_can( 'create_users' ) ) : ?>
    896 
    897                         <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user', 'buddypress' ); ?></a>
    898 
    899                     <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
    900 
    901                         <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user', 'buddypress' ); ?></a>
    902 
    903                     <?php endif; ?>
    904 
    905                 <?php endif; ?>
    906             </h1>
    907 
    908             <?php if ( ! empty( $user ) ) :
    909 
    910                 $this->profile_nav( $user, 'BuddyPress' ); ?>
    911 
    912                 <form action="<?php echo esc_url( $form_action_url ); ?>" id="your-profile" method="post">
    913                     <div id="poststuff">
    914 
    915                         <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
    916 
    917                             <div id="postbox-container-1" class="postbox-container">
    918                                 <?php do_meta_boxes( get_current_screen()->id, 'side', $user ); ?>
    919                             </div>
    920 
    921                             <div id="postbox-container-2" class="postbox-container">
    922                                 <?php do_meta_boxes( get_current_screen()->id, 'normal',   $user ); ?>
    923                                 <?php do_meta_boxes( get_current_screen()->id, 'advanced', $user ); ?>
    924                             </div>
    925                         </div><!-- #post-body -->
    926 
    927                     </div><!-- #poststuff -->
    928 
    929                     <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
    930                     <?php wp_nonce_field( 'meta-box-order',  'meta-box-order-nonce', false ); ?>
    931                     <?php wp_nonce_field( 'edit-bp-profile_' . $user->ID ); ?>
    932 
    933                 </form>
    934 
    935             <?php else : ?>
    936 
    937                 <p><?php printf( __( 'No user found with this ID. <a href="%s">Go back and try again</a>.', 'buddypress' ), esc_url( bp_get_admin_url( 'users.php' ) ) ); ?></p>
    938 
    939             <?php endif; ?>
    940 
    941         </div><!-- .wrap -->
    942         <?php
    943     }
    944 
    945     /**
    946      * Render the Status metabox for user's profile screen.
    947      *
    948      * Actions are:
    949      * - Update profile fields if xProfile component is active
    950      * - Spam/Unspam user
    951      *
    952      * @since 2.0.0
    953      *
    954      * @param WP_User|null $user The WP_User object to be edited.
    955      */
    956     public function user_admin_status_metabox( $user = null ) {
    957 
    958         // Bail if no user id or if the user has not activated their account yet.
    959         if ( empty( $user->ID ) ) {
    960             return;
    961         }
    962 
    963         // Bail if user has not been activated yet (how did you get here?).
    964         if ( isset( $user->user_status ) && ( 2 == $user->user_status ) ) : ?>
    965 
    966             <p class="not-activated"><?php esc_html_e( 'User account has not yet been activated', 'buddypress' ); ?></p><br/>
    967 
    968             <?php return;
    969 
    970         endif; ?>
    971 
    972         <div class="submitbox" id="submitcomment">
    973             <div id="minor-publishing">
    974                 <div id="misc-publishing-actions">
    975                     <?php
    976 
    977                     // Get the spam status once here to compare against below.
    978                     $is_spammer = bp_is_user_spammer( $user->ID );
    979 
    980                     /**
    981                      * In configs where BuddyPress is not network activated,
    982                      * regular admins cannot mark a user as a spammer on front
    983                      * end. This prevent them to do it in backend.
    984                      *
    985                      * Also prevent admins from marking themselves or other
    986                      * admins as spammers.
    987                      */
    988                     if ( ( empty( $this->is_self_profile ) && ( ! in_array( $user->user_login, get_super_admins() ) ) && empty( $this->subsite_activated ) ) || ( ! empty( $this->subsite_activated ) && current_user_can( 'manage_network_users' ) ) ) : ?>
    989 
    990                         <div class="misc-pub-section" id="comment-status-radio">
    991                             <label class="approved"><input type="radio" name="user_status" value="ham" <?php checked( $is_spammer, false ); ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></label><br />
    992                             <label class="spam"><input type="radio" name="user_status" value="spam" <?php checked( $is_spammer, true ); ?>><?php esc_html_e( 'Spammer', 'buddypress' ); ?></label>
    993                         </div>
    994 
    995                     <?php endif ;?>
    996 
    997                     <div class="misc-pub-section curtime misc-pub-section-last">
    998                         <?php
    999 
    1000                         // Translators: Publish box date format, see http://php.net/date.
    1001                         $datef = __( 'M j, Y @ G:i', 'buddypress' );
    1002                         $date  = date_i18n( $datef, strtotime( $user->user_registered ) );
    1003                         ?>
    1004                         <span id="timestamp"><?php printf( __( 'Registered on: %s', 'buddypress' ), '<strong>' . $date . '</strong>' ); ?></span>
    1005                     </div>
    1006                 </div> <!-- #misc-publishing-actions -->
    1007 
    1008                 <div class="clear"></div>
    1009             </div><!-- #minor-publishing -->
    1010 
    1011             <div id="major-publishing-actions">
    1012 
    1013                 <div id="publishing-action">
    1014                     <a class="button bp-view-profile" href="<?php echo esc_url( bp_core_get_user_domain( $user->ID ) ); ?>" target="_blank"><?php esc_html_e( 'View Profile', 'buddypress' ); ?></a>
    1015                     <?php submit_button( esc_html__( 'Update Profile', 'buddypress' ), 'primary', 'save', false ); ?>
    1016                 </div>
    1017                 <div class="clear"></div>
    1018             </div><!-- #major-publishing-actions -->
    1019 
    1020         </div><!-- #submitcomment -->
    1021 
    1022         <?php
    1023     }
    1024 
    1025     /**
    1026      * Render the fallback metabox in case a user has been marked as a spammer.
    1027      *
    1028      * @since 2.0.0
    1029      *
    1030      * @param WP_User|null $user The WP_User object to be edited.
    1031      */
    1032     public function user_admin_spammer_metabox( $user = null ) {
    1033     ?>
    1034         <p><?php printf( __( '%s has been marked as a spammer. All BuddyPress data associated with the user has been removed', 'buddypress' ), esc_html( bp_core_get_user_displayname( $user->ID ) ) ) ;?></p>
    1035     <?php
    1036     }
    1037 
    1038     /**
    1039      * Render the Stats metabox to moderate inappropriate images.
    1040      *
    1041      * @since 2.0.0
    1042      *
    1043      * @param WP_User|null $user The WP_User object to be edited.
    1044      */
    1045     public function user_admin_stats_metabox( $user = null ) {
    1046 
    1047         // Bail if no user ID.
    1048         if ( empty( $user->ID ) ) {
    1049             return;
    1050         }
    1051 
    1052         // If account is not activated last activity is the time user registered.
    1053         if ( isset( $user->user_status ) && 2 == $user->user_status ) {
    1054             $last_active = $user->user_registered;
    1055 
    1056         // Account is activated, getting user's last activity.
    1057         } else {
    1058             $last_active = bp_get_user_last_activity( $user->ID );
    1059         }
    1060 
    1061         $datef = __( 'M j, Y @ G:i', 'buddypress' );
    1062         $date  = date_i18n( $datef, strtotime( $last_active ) ); ?>
    1063 
    1064         <ul>
    1065             <li class="bp-members-profile-stats"><?php printf( __( 'Last active: %1$s', 'buddypress' ), '<strong>' . $date . '</strong>' ); ?></li>
    1066 
    1067             <?php
    1068             // Loading other stats only if user has activated their account.
    1069             if ( empty( $user->user_status ) ) {
    1070 
    1071                 /**
    1072                  * Fires in the user stats metabox if the user has activated their account.
    1073                  *
    1074                  * @since 2.0.0
    1075                  *
    1076                  * @param array  $value Array holding the user ID.
    1077                  * @param object $user  Current displayed user object.
    1078                  */
    1079                 do_action( 'bp_members_admin_user_stats', array( 'user_id' => $user->ID ), $user );
    1080             }
    1081             ?>
    1082         </ul>
    1083 
    1084         <?php
    1085     }
    1086 
    1087     /**
    1088      * Render the Member Type metabox.
    1089      *
    1090      * @since 2.2.0
    1091      *
    1092      * @param WP_User|null $user The WP_User object to be edited.
    1093      */
    1094     public function user_admin_member_type_metabox( $user = null ) {
    1095 
    1096         // Bail if no user ID.
    1097         if ( empty( $user->ID ) ) {
    1098             return;
    1099         }
    1100 
    1101         $types = bp_get_member_types( array(), 'objects' );
    1102         $current_type = bp_get_member_type( $user->ID );
    1103         ?>
    1104 
    1105         <label for="bp-members-profile-member-type" class="screen-reader-text"><?php esc_html_e( 'Select member type', 'buddypress' ); ?></label>
    1106         <select name="bp-members-profile-member-type" id="bp-members-profile-member-type">
    1107             <option value="" <?php selected( '', $current_type ); ?>><?php /* translators: no option picked in select box */ esc_attr_e( '----', 'buddypress' ) ?></option>
    1108             <?php foreach ( $types as $type ) : ?>
    1109                 <option value="<?php echo esc_attr( $type->name ) ?>" <?php selected( $type->name, $current_type ) ?>><?php echo esc_html( $type->labels['singular_name'] ) ?></option>
    1110             <?php endforeach; ?>
    1111         </select>
    1112 
    1113         <?php
    1114 
    1115         wp_nonce_field( 'bp-member-type-change-' . $user->ID, 'bp-member-type-nonce' );
    1116     }
    1117 
    1118     /**
    1119      * Process changes from the Member Type metabox.
    1120      *
    1121      * @since 2.2.0
    1122      */
    1123     public function process_member_type_update() {
    1124         if ( ! isset( $_POST['bp-member-type-nonce'] ) || ! isset( $_POST['bp-members-profile-member-type'] ) ) {
    1125             return;
    1126         }
    1127 
    1128         $user_id = $this->get_user_id();
    1129 
    1130         check_admin_referer( 'bp-member-type-change-' . $user_id, 'bp-member-type-nonce' );
    1131 
    1132         // Permission check.
    1133         if ( ! current_user_can( 'bp_moderate' ) && $user_id != bp_loggedin_user_id() ) {
    1134             return;
    1135         }
    1136 
    1137         // Member type string must either reference a valid member type, or be empty.
    1138         $member_type = stripslashes( $_POST['bp-members-profile-member-type'] );
    1139         if ( ! empty( $member_type ) && ! bp_get_member_type_object( $member_type ) ) {
    1140             return;
    1141         }
    1142 
    1143         /*
    1144          * If an invalid member type is passed, someone's doing something
    1145          * fishy with the POST request, so we can fail silently.
    1146          */
    1147         if ( bp_set_member_type( $user_id, $member_type ) ) {
    1148             // @todo Success messages can't be posted because other stuff happens on the page load.
    1149         }
    1150     }
    1151 
    1152     /**
    1153      * Add a link to Profile in Users listing row actions.
    1154      *
    1155      * @since 2.0.0
    1156      *
    1157      * @param array|string $actions WordPress row actions (edit, delete).
    1158      * @param object|null  $user    The object for the user row.
    1159      * @return array Merged actions.
    1160      */
    1161     public function row_actions( $actions = '', $user = null ) {
    1162 
    1163         // Bail if no user ID.
    1164         if ( empty( $user->ID ) ) {
    1165             return;
    1166         }
    1167 
    1168         // Setup args array.
    1169         $args = array();
    1170 
    1171         // Add the user ID if it's not for the current user.
    1172         if ( $user->ID !== $this->current_user_id ) {
    1173             $args['user_id'] = $user->ID;
    1174         }
    1175 
    1176         // Add the referer.
    1177         $args['wp_http_referer'] = urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) );
    1178 
    1179         // Add the "Extended" link if the current user can edit this user.
    1180         if ( current_user_can( 'edit_user', $user->ID ) || bp_current_user_can( 'bp_moderate' ) ) {
    1181 
    1182             // Add query args and setup the Extended link.
    1183             $edit_profile      = add_query_arg( $args, $this->edit_profile_url );
    1184             $edit_profile_link = sprintf( '<a href="%1$s">%2$s</a>',  esc_url( $edit_profile ), esc_html__( 'Extended', 'buddypress' ) );
    1185 
    1186             /**
    1187              * Check the edit action is available
    1188              * and preserve the order edit | profile | remove/delete.
    1189              */
    1190             if ( ! empty( $actions['edit'] ) ) {
    1191                 $edit_action = $actions['edit'];
    1192                 unset( $actions['edit'] );
    1193 
    1194                 $new_edit_actions = array(
    1195                     'edit'         => $edit_action,
    1196                     'edit-profile' => $edit_profile_link,
    1197                 );
    1198 
    1199             // If not available simply add the edit profile action.
    1200             } else {
    1201                 $new_edit_actions = array( 'edit-profile' => $edit_profile_link );
    1202             }
    1203 
    1204             $actions = array_merge( $new_edit_actions, $actions );
    1205         }
    1206 
    1207         return $actions;
    1208     }
    1209 
    1210     /**
    1211      * Add a filter to edit profile url in WP Admin Bar.
    1212      *
    1213      * @since 2.1.0
    1214      */
    1215     public function add_edit_profile_url_filter() {
    1216         add_filter( 'bp_members_edit_profile_url', array( $this, 'filter_adminbar_profile_link' ), 10, 3 );
    1217     }
    1218 
    1219     /**
    1220      * Filter the profile url.
    1221      *
    1222      * @since 2.1.0
    1223      *
    1224      * @uses  user_admin_url()
    1225      *
    1226      * @param string $profile_link Profile Link for admin bar.
    1227      * @param string $url          Profile URL.
    1228      * @param int    $user_id      User ID.
    1229      * @return string
    1230      */
    1231     public function filter_adminbar_profile_link( $profile_link = '', $url = '', $user_id = 0 ) {
    1232         if ( ! is_super_admin( $user_id ) && is_admin() ) {
    1233             $profile_link = user_admin_url( 'profile.php' );
    1234         }
    1235         return $profile_link;
    1236     }
    1237 
    1238     /**
    1239      * Remove the filter to edit profile url in WP Admin Bar.
    1240      *
    1241      * @since 2.1.0
    1242      */
    1243     public function remove_edit_profile_url_filter() {
    1244         remove_filter( 'bp_members_edit_profile_url', array( $this, 'filter_adminbar_profile_link' ), 10, 3 );
    1245     }
    1246 
    1247     /** Signups Management ****************************************************/
    1248 
    1249     /**
    1250      * Display the admin preferences about signups pagination.
    1251      *
    1252      * @since 2.0.0
    1253      *
    1254      * @param int    $value     Value for signup option.
    1255      * @param string $option    Value for the option key.
    1256      * @param int    $new_value Value for the saved option.
    1257      * @return int The pagination preferences.
    1258      */
    1259     public function signup_screen_options( $value = 0, $option = '', $new_value = 0 ) {
    1260         if ( 'users_page_bp_signups_network_per_page' != $option && 'users_page_bp_signups_per_page' != $option ) {
    1261             return $value;
    1262         }
    1263 
    1264         // Per page.
    1265         $new_value = (int) $new_value;
    1266         if ( $new_value < 1 || $new_value > 999 ) {
    1267             return $value;
    1268         }
    1269 
    1270         return $new_value;
    1271     }
    1272 
    1273     /**
    1274      * Make sure no signups will show in users list.
    1275      *
    1276      * This is needed to handle signups that may have not been activated
    1277      * before the 2.0.0 upgrade.
    1278      *
    1279      * @since 2.0.0
    1280      *
    1281      * @param WP_User_Query|null $query The users query.
    1282      * @return WP_User_Query The users query without the signups.
    1283      */
    1284     public function remove_signups_from_user_query( $query = null ) {
    1285         global $wpdb;
    1286 
    1287         // Bail if this is an ajax request.
    1288         if ( defined( 'DOING_AJAX' ) ) {
    1289             return;
    1290         }
    1291 
    1292         // Bail if updating BuddyPress.
    1293         if ( bp_is_update() ) {
    1294             return;
    1295         }
    1296 
    1297         // Bail if there is no current admin screen.
    1298         if ( ! function_exists( 'get_current_screen' ) || ! get_current_screen() ) {
    1299             return;
    1300         }
    1301 
    1302         // Get current screen.
    1303         $current_screen = get_current_screen();
    1304 
    1305         // Bail if not on a users page.
    1306         if ( ! isset( $current_screen->id ) || $this->users_page !== $current_screen->id ) {
    1307             return;
    1308         }
    1309 
    1310         // Bail if already querying by an existing role.
    1311         if ( ! empty( $query->query_vars['role'] ) ) {
    1312             return;
    1313         }
    1314 
    1315         $query->query_where .= " AND {$wpdb->users}.user_status != 2";
    1316     }
    1317 
    1318     /**
    1319      * Filter the WP Users List Table views to include 'bp-signups'.
    1320      *
    1321      * @since 2.0.0
    1322      *
    1323      * @param array $views WP List Table views.
    1324      * @return array The views with the signup view added.
    1325      */
    1326     public function signup_filter_view( $views = array() ) {
    1327 
    1328         // Remove the 'current' class from All if we're on the signups view.
    1329         if ( $this->signups_page == get_current_screen()->id ) {
    1330             $views['all'] = str_replace( 'class="current"', '', $views['all'] );
    1331             $class        = 'current';
    1332         } else {
    1333             $class        = '';
    1334         }
    1335 
    1336         $signups = BP_Signup::count_signups();
    1337 
    1338         if ( is_network_admin() ) {
    1339             $base_url = network_admin_url( 'users.php' );
    1340         } else {
    1341             $base_url = bp_get_admin_url( 'users.php' );
    1342         }
    1343 
    1344         $url     = add_query_arg( 'page', 'bp-signups', $base_url );
    1345         $text    = sprintf( _x( 'Pending %s', 'signup users', 'buddypress' ), '<span class="count">(' . number_format_i18n( $signups ) . ')</span>' );
    1346 
    1347         $views['registered'] = sprintf( '<a href="%1$s" class="%2$s">%3$s</a>', esc_url( $url ), $class, $text );
    1348 
    1349         return $views;
    1350     }
    1351 
    1352     /**
    1353      * Load the Signup WP Users List table.
    1354      *
    1355      * @since 2.0.0
    1356      *
    1357      * @param string $class    The name of the class to use.
    1358      * @param string $required The parent class.
    1359      * @return WP_List_Table The List table.
    1360      */
    1361     public static function get_list_table_class( $class = '', $required = '' ) {
    1362         if ( empty( $class ) ) {
    1363             return;
    1364         }
    1365 
    1366         if ( ! empty( $required ) ) {
    1367             require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
    1368             require_once( buddypress()->members->admin->admin_dir . 'bp-members-admin-classes.php' );
    1369         }
    1370 
    1371         return new $class();
    1372     }
    1373 
    1374     /**
    1375      * Set up the signups admin page.
    1376      *
    1377      * Loaded before the page is rendered, this function does all initial
    1378      * setup, including: processing form requests, registering contextual
    1379      * help, and setting up screen options.
    1380      *
    1381      * @since 2.0.0
    1382      *
    1383      * @global $bp_members_signup_list_table
    1384      */
    1385     public function signups_admin_load() {
    1386         global $bp_members_signup_list_table;
    1387 
    1388         // Build redirection URL.
    1389         $redirect_to = remove_query_arg( array( 'action', 'error', 'updated', 'activated', 'notactivated', 'deleted', 'notdeleted', 'resent', 'notresent', 'do_delete', 'do_resend', 'do_activate', '_wpnonce', 'signup_ids' ), $_SERVER['REQUEST_URI'] );
    1390         $doaction    = bp_admin_list_table_current_bulk_action();
    1391 
    1392         /**
    1393          * Fires at the start of the signups admin load.
    1394          *
    1395          * @since 2.0.0
    1396          *
    1397          * @param string $doaction Current bulk action being processed.
    1398          * @param array  $_REQUEST Current $_REQUEST global.
    1399          */
    1400         do_action( 'bp_signups_admin_load', $doaction, $_REQUEST );
    1401 
    1402         /**
    1403          * Filters the allowed actions for use in the user signups admin page.
    1404          *
    1405          * @since 2.0.0
    1406          *
    1407          * @param array $value Array of allowed actions to use.
    1408          */
    1409         $allowed_actions = apply_filters( 'bp_signups_admin_allowed_actions', array( 'do_delete', 'do_activate', 'do_resend' ) );
    1410 
    1411         // Prepare the display of the Community Profile screen.
    1412         if ( ! in_array( $doaction, $allowed_actions ) || ( -1 == $doaction ) ) {
    1413 
    1414             if ( is_network_admin() ) {
    1415                 $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_MS_List_Table', 'ms-users' );
    1416             } else {
    1417                 $bp_members_signup_list_table = self::get_list_table_class( 'BP_Members_List_Table', 'users' );
    1418             }
    1419 
    1420             // The per_page screen option.
    1421             add_screen_option( 'per_page', array( 'label' => _x( 'Pending Accounts', 'Pending Accounts per page (screen options)', 'buddypress' ) ) );
    1422 
    1423             get_current_screen()->add_help_tab( array(
    1424                 'id'      => 'bp-signups-overview',
    1425                 'title'   => __( 'Overview', 'buddypress' ),
    1426                 'content' =>
    1427                 '<p>' . __( 'This is the administration screen for pending accounts on your site.', 'buddypress' ) . '</p>' .
    1428                 '<p>' . __( 'From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress' ) . '</p>' .
    1429                 '<p>' . __( 'You can reorder the list of your pending accounts by clicking on the Username, Email or Registered column headers.', 'buddypress' ) . '</p>' .
    1430                 '<p>' . __( 'Using the search form, you can find pending accounts more easily. The Username and Email fields will be included in the search.', 'buddypress' ) . '</p>'
    1431             ) );
    1432 
    1433             get_current_screen()->add_help_tab( array(
    1434                 'id'      => 'bp-signups-actions',
    1435                 'title'   => __( 'Actions', 'buddypress' ),
    1436                 'content' =>
    1437                 '<p>' . __( 'Hovering over a row in the pending accounts list will display action links that allow you to manage pending accounts. You can perform the following actions:', 'buddypress' ) . '</p>' .
    1438                 '<ul><li>' . __( '"Email" takes you to the confirmation screen before being able to send the activation link to the desired pending account. You can only send the activation email once per day.', 'buddypress' ) . '</li>' .
    1439                 '<li>' . __( '"Delete" allows you to delete a pending account from your site. You will be asked to confirm this deletion.', 'buddypress' ) . '</li></ul>' .
    1440                 '<p>' . __( 'By clicking on a Username you will be able to activate a pending account from the confirmation screen.', 'buddypress' ) . '</p>' .
    1441                 '<p>' . __( 'Bulk actions allow you to perform these 3 actions for the selected rows.', 'buddypress' ) . '</p>'
    1442             ) );
    1443 
    1444             // Help panel - sidebar links.
    1445             get_current_screen()->set_help_sidebar(
    1446                 '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
    1447                 '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
    1448             );
    1449 
    1450             // Add accessible hidden headings and text for the Pending Users screen.
    1451             if ( bp_get_major_wp_version() >= 4.4 ) {
    1452                 get_current_screen()->set_screen_reader_content( array(
    1453                     'heading_views'      => __( 'Filter users list', 'buddypress' ),
    1454                     'heading_pagination' => __( 'Pending users list navigation', 'buddypress' ),
    1455                     'heading_list'       => __( 'Pending users list', 'buddypress' ),
    1456                 ) );
    1457             }
    1458 
    1459         } else {
    1460             if ( ! empty( $_REQUEST['signup_ids' ] ) ) {
    1461                 $signups = wp_parse_id_list( $_REQUEST['signup_ids' ] );
    1462             }
    1463 
    1464             // Handle resent activation links.
    1465             if ( 'do_resend' == $doaction ) {
    1466 
    1467                 // Nonce check.
    1468                 check_admin_referer( 'signups_resend' );
    1469 
    1470                 $resent = BP_Signup::resend( $signups );
    1471 
    1472                 if ( empty( $resent ) ) {
    1473                     $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
    1474                 } else {
    1475                     $query_arg = array( 'updated' => 'resent' );
    1476 
    1477                     if ( ! empty( $resent['resent'] ) ) {
    1478                         $query_arg['resent'] = count( $resent['resent'] );
    1479                     }
    1480 
    1481                     if ( ! empty( $resent['errors'] ) ) {
    1482                         $query_arg['notsent'] = count( $resent['errors'] );
    1483                         set_transient( '_bp_admin_signups_errors', $resent['errors'], 30 );
    1484                     }
    1485 
    1486                     $redirect_to = add_query_arg( $query_arg, $redirect_to );
    1487                 }
    1488 
    1489                 bp_core_redirect( $redirect_to );
    1490 
    1491             // Handle activated accounts.
    1492             } elseif ( 'do_activate' == $doaction ) {
    1493 
    1494                 // Nonce check.
    1495                 check_admin_referer( 'signups_activate' );
    1496 
    1497                 $activated = BP_Signup::activate( $signups );
    1498 
    1499                 if ( empty( $activated ) ) {
    1500                     $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
    1501                 } else {
    1502                     $query_arg = array( 'updated' => 'activated' );
    1503 
    1504                     if ( ! empty( $activated['activated'] ) ) {
    1505                         $query_arg['activated'] = count( $activated['activated'] );
    1506                     }
    1507 
    1508                     if ( ! empty( $activated['errors'] ) ) {
    1509                         $query_arg['notactivated'] = count( $activated['errors'] );
    1510                         set_transient( '_bp_admin_signups_errors', $activated['errors'], 30 );
    1511                     }
    1512 
    1513                     $redirect_to = add_query_arg( $query_arg, $redirect_to );
    1514                 }
    1515 
    1516                 bp_core_redirect( $redirect_to );
    1517 
    1518             // Handle sign-ups delete.
    1519             } elseif ( 'do_delete' == $doaction ) {
    1520 
    1521                 // Nonce check.
    1522                 check_admin_referer( 'signups_delete' );
    1523 
    1524                 $deleted = BP_Signup::delete( $signups );
    1525 
    1526                 if ( empty( $deleted ) ) {
    1527                     $redirect_to = add_query_arg( 'error', $doaction, $redirect_to );
    1528                 } else {
    1529                     $query_arg = array( 'updated' => 'deleted' );
    1530 
    1531                     if ( ! empty( $deleted['deleted'] ) ) {
    1532                         $query_arg['deleted'] = count( $deleted['deleted'] );
    1533                     }
    1534 
    1535                     if ( ! empty( $deleted['errors'] ) ) {
    1536                         $query_arg['notdeleted'] = count( $deleted['errors'] );
    1537                         set_transient( '_bp_admin_signups_errors', $deleted['errors'], 30 );
    1538                     }
    1539 
    1540                     $redirect_to = add_query_arg( $query_arg, $redirect_to );
    1541                 }
    1542 
    1543                 bp_core_redirect( $redirect_to );
    1544 
    1545             // Plugins can update other stuff from here.
    1546             } else {
    1547                 $this->redirect = $redirect_to;
    1548 
    1549                 /**
    1550                  * Fires at end of signups admin load if doaction does not match any actions.
    1551                  *
    1552                  * @since 2.0.0
    1553                  *
    1554                  * @param string $doaction Current bulk action being processed.
    1555                  * @param array  $_REQUEST Current $_REQUEST global.
    1556                  * @param string $redirect Determined redirect url to send user to.
    1557                  */
    1558                 do_action( 'bp_members_admin_update_signups', $doaction, $_REQUEST, $this->redirect );
    1559 
    1560                 bp_core_redirect( $this->redirect );
    1561             }
    1562         }
    1563     }
    1564 
    1565     /**
    1566      * Display any activation errors.
    1567      *
    1568      * @since 2.0.0
    1569      */
    1570     public function signups_display_errors() {
    1571 
    1572         // Look for sign-up errors.
    1573         $errors = get_transient( '_bp_admin_signups_errors' );
    1574 
    1575         // Bail if no activation errors.
    1576         if ( empty( $errors ) ) {
    1577             return;
    1578         }
    1579 
    1580         // Loop through errors and display them.
    1581         foreach ( $errors as $error ) : ?>
    1582 
    1583             <li><?php echo esc_html( $error[0] );?>: <?php echo esc_html( $error[1] );?></li>
    1584 
    1585         <?php endforeach;
    1586 
    1587         // Delete the redirect transient.
    1588         delete_transient( '_bp_admin_signups_errors' );
    1589     }
    1590 
    1591     /**
    1592      * Get admin notice when viewing the sign-up page.
    1593      *
    1594      * @since 2.1.0
    1595      *
    1596      * @return array
    1597      */
    1598     private function get_signup_notice() {
    1599 
    1600         // Setup empty notice for return value.
    1601         $notice = array();
    1602 
    1603         // Updates.
    1604         if ( ! empty( $_REQUEST['updated'] ) ) {
    1605             switch ( $_REQUEST['updated'] ) {
    1606                 case 'resent':
    1607                     $notice = array(
    1608                         'class'   => 'updated',
    1609                         'message' => ''
    1610                     );
    1611 
    1612                     if ( ! empty( $_REQUEST['resent'] ) ) {
    1613                         $notice['message'] .= sprintf(
    1614                             _nx( '%s activation email successfully sent! ', '%s activation emails successfully sent! ',
    1615                              absint( $_REQUEST['resent'] ),
    1616                              'signup resent',
    1617                              'buddypress'
    1618                             ),
    1619                             number_format_i18n( absint( $_REQUEST['resent'] ) )
    1620                         );
    1621                     }
    1622 
    1623                     if ( ! empty( $_REQUEST['notsent'] ) ) {
    1624                         $notice['message'] .= sprintf(
    1625                             _nx( '%s activation email was not sent.', '%s activation emails were not sent.',
    1626                              absint( $_REQUEST['notsent'] ),
    1627                              'signup notsent',
    1628                              'buddypress'
    1629                             ),
    1630                             number_format_i18n( absint( $_REQUEST['notsent'] ) )
    1631                         );
    1632 
    1633                         if ( empty( $_REQUEST['resent'] ) ) {
    1634                             $notice['class'] = 'error';
    1635                         }
    1636                     }
    1637 
    1638                     break;
    1639 
    1640                 case 'activated':
    1641                     $notice = array(
    1642                         'class'   => 'updated',
    1643                         'message' => ''
    1644                     );
    1645 
    1646                     if ( ! empty( $_REQUEST['activated'] ) ) {
    1647                         $notice['message'] .= sprintf(
    1648                             _nx( '%s account successfully activated! ', '%s accounts successfully activated! ',
    1649                              absint( $_REQUEST['activated'] ),
    1650                              'signup resent',
    1651                              'buddypress'
    1652                             ),
    1653                             number_format_i18n( absint( $_REQUEST['activated'] ) )
    1654                         );
    1655                     }
    1656 
    1657                     if ( ! empty( $_REQUEST['notactivated'] ) ) {
    1658                         $notice['message'] .= sprintf(
    1659                             _nx( '%s account was not activated.', '%s accounts were not activated.',
    1660                              absint( $_REQUEST['notactivated'] ),
    1661                              'signup notsent',
    1662                              'buddypress'
    1663                             ),
    1664                             number_format_i18n( absint( $_REQUEST['notactivated'] ) )
    1665                         );
    1666 
    1667                         if ( empty( $_REQUEST['activated'] ) ) {
    1668                             $notice['class'] = 'error';
    1669                         }
    1670                     }
    1671 
    1672                     break;
    1673 
    1674                 case 'deleted':
    1675                     $notice = array(
    1676                         'class'   => 'updated',
    1677                         'message' => ''
    1678                     );
    1679 
    1680                     if ( ! empty( $_REQUEST['deleted'] ) ) {
    1681                         $notice['message'] .= sprintf(
    1682                             _nx( '%s sign-up successfully deleted!', '%s sign-ups successfully deleted!',
    1683                              absint( $_REQUEST['deleted'] ),
    1684                              'signup deleted',
    1685                              'buddypress'
    1686                             ),
    1687                             number_format_i18n( absint( $_REQUEST['deleted'] ) )
    1688                         );
    1689                     }
    1690 
    1691                     if ( ! empty( $_REQUEST['notdeleted'] ) ) {
    1692                         $notice['message'] .= sprintf(
    1693                             _nx( '%s sign-up was not deleted.', '%s sign-ups were not deleted.',
    1694                              absint( $_REQUEST['notdeleted'] ),
    1695                              'signup notdeleted',
    1696                              'buddypress'
    1697                             ),
    1698                             number_format_i18n( absint( $_REQUEST['notdeleted'] ) )
    1699                         );
    1700 
    1701                         if ( empty( $_REQUEST['deleted'] ) ) {
    1702                             $notice['class'] = 'error';
    1703                         }
    1704                     }
    1705 
    1706                     break;
    1707             }
    1708         }
    1709 
    1710         // Errors.
    1711         if ( ! empty( $_REQUEST['error'] ) ) {
    1712             switch ( $_REQUEST['error'] ) {
    1713                 case 'do_resend':
    1714                     $notice = array(
    1715                         'class'   => 'error',
    1716                         'message' => esc_html__( 'There was a problem sending the activation emails. Please try again.', 'buddypress' ),
    1717                     );
    1718                     break;
    1719 
    1720                 case 'do_activate':
    1721                     $notice = array(
    1722                         'class'   => 'error',
    1723                         'message' => esc_html__( 'There was a problem activating accounts. Please try again.', 'buddypress' ),
    1724                     );
    1725                     break;
    1726 
    1727                 case 'do_delete':
    1728                     $notice = array(
    1729                         'class'   => 'error',
    1730                         'message' => esc_html__( 'There was a problem deleting sign-ups. Please try again.', 'buddypress' ),
    1731                     );
    1732                     break;
    1733             }
    1734         }
    1735 
    1736         return $notice;
    1737     }
    1738 
    1739     /**
    1740      * Signups admin page router.
    1741      *
    1742      * Depending on the context, display
    1743      * - the list of signups,
    1744      * - or the delete confirmation screen,
    1745      * - or the activate confirmation screen,
    1746      * - or the "resend" email confirmation screen.
    1747      *
    1748      * Also prepare the admin notices.
    1749      *
    1750      * @since 2.0.0
    1751      */
    1752     public function signups_admin() {
    1753         $doaction = bp_admin_list_table_current_bulk_action();
    1754 
    1755         // Prepare notices for admin.
    1756         $notice = $this->get_signup_notice();
    1757 
    1758         // Display notices.
    1759         if ( ! empty( $notice ) ) :
    1760             if ( 'updated' === $notice['class'] ) : ?>
    1761 
    1762                 <div id="message" class="<?php echo esc_attr( $notice['class'] ); ?>">
    1763 
    1764             <?php else: ?>
    1765 
    1766                 <div class="<?php echo esc_attr( $notice['class'] ); ?>">
    1767 
    1768             <?php endif; ?>
    1769 
    1770                 <p><?php echo $notice['message']; ?></p>
    1771 
    1772                 <?php if ( ! empty( $_REQUEST['notactivated'] ) || ! empty( $_REQUEST['notdeleted'] ) || ! empty( $_REQUEST['notsent'] ) ) :?>
    1773 
    1774                     <ul><?php $this->signups_display_errors();?></ul>
    1775 
    1776                 <?php endif ;?>
    1777 
    1778             </div>
    1779 
    1780         <?php endif;
    1781 
    1782         // Show the proper screen.
    1783         switch ( $doaction ) {
    1784             case 'activate' :
    1785             case 'delete' :
    1786             case 'resend' :
    1787                 $this->signups_admin_manage( $doaction );
    1788                 break;
    1789 
    1790             default:
    1791                 $this->signups_admin_index();
    1792                 break;
    1793 
    1794         }
    1795     }
    1796 
    1797     /**
    1798      * This is the list of the Pending accounts (signups).
    1799      *
    1800      * @since 2.0.0
    1801      *
    1802      * @global $plugin_page
    1803      * @global $bp_members_signup_list_table
    1804      */
    1805     public function signups_admin_index() {
    1806         global $plugin_page, $bp_members_signup_list_table;
    1807 
    1808         $usersearch = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
    1809 
    1810         // Prepare the group items for display.
    1811         $bp_members_signup_list_table->prepare_items();
    1812 
    1813         if ( is_network_admin() ) {
    1814             $form_url = network_admin_url( 'users.php' );
    1815         } else {
    1816             $form_url = bp_get_admin_url( 'users.php' );
    1817         }
    1818 
    1819         $form_url = add_query_arg(
    1820             array(
    1821                 'page' => 'bp-signups',
    1822             ),
    1823             $form_url
    1824         );
    1825 
    1826         $search_form_url = remove_query_arg(
    1827             array(
    1828                 'action',
    1829                 'deleted',
    1830                 'notdeleted',
    1831                 'error',
    1832                 'updated',
    1833                 'delete',
    1834                 'activate',
    1835                 'activated',
    1836                 'notactivated',
    1837                 'resend',
    1838                 'resent',
    1839                 'notresent',
    1840                 'do_delete',
    1841                 'do_activate',
    1842                 'do_resend',
    1843                 'action2',
    1844                 '_wpnonce',
    1845                 'signup_ids'
    1846             ), $_SERVER['REQUEST_URI']
    1847         );
    1848 
    1849         ?>
    1850 
    1851         <div class="wrap">
    1852             <h1><?php _e( 'Users', 'buddypress' ); ?>
    1853 
    1854                 <?php if ( current_user_can( 'create_users' ) ) : ?>
    1855 
    1856                     <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user', 'buddypress' ); ?></a>
    1857 
    1858                 <?php elseif ( is_multisite() && current_user_can( 'promote_users' ) ) : ?>
    1859 
    1860                     <a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user', 'buddypress' ); ?></a>
    1861 
    1862                 <?php endif;
    1863 
    1864                 if ( $usersearch ) {
    1865                     printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;', 'buddypress' ) . '</span>', esc_html( $usersearch ) );
    1866                 }
    1867 
    1868                 ?>
    1869             </h1>
    1870 
    1871             <?php // Display each signups on its own row. ?>
    1872             <?php $bp_members_signup_list_table->views(); ?>
    1873 
    1874             <form id="bp-signups-search-form" action="<?php echo esc_url( $search_form_url ) ;?>">
    1875                 <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" />
    1876                 <?php $bp_members_signup_list_table->search_box( __( 'Search Pending Users', 'buddypress' ), 'bp-signups' ); ?>
    1877             </form>
    1878 
    1879             <form id="bp-signups-form" action="<?php echo esc_url( $form_url );?>" method="post">
    1880                 <?php $bp_members_signup_list_table->display(); ?>
    1881             </form>
    1882         </div>
    1883     <?php
    1884     }
    1885 
    1886     /**
    1887      * This is the confirmation screen for actions.
    1888      *
    1889      * @since 2.0.0
    1890      *
    1891      * @param string $action Delete, activate, or resend activation link.
    1892      * @return string
    1893      */
    1894     public function signups_admin_manage( $action = '' ) {
    1895         if ( ! current_user_can( $this->capability ) || empty( $action ) ) {
    1896             die( '-1' );
    1897         }
    1898 
    1899         // Get the user IDs from the URL.
    1900         $ids = false;
    1901         if ( ! empty( $_POST['allsignups'] ) ) {
    1902             $ids = wp_parse_id_list( $_POST['allsignups'] );
    1903         } elseif ( ! empty( $_GET['signup_id'] ) ) {
    1904             $ids = absint( $_GET['signup_id'] );
    1905         }
    1906 
    1907         if ( empty( $ids ) ) {
    1908             return false;
    1909         }
    1910 
    1911         // Query for signups, and filter out those IDs that don't
    1912         // correspond to an actual signup.
    1913         $signups_query = BP_Signup::get( array(
    1914             'include' => $ids,
    1915         ) );
    1916 
    1917         $signups    = $signups_query['signups'];
    1918         $signup_ids = wp_list_pluck( $signups, 'signup_id' );
    1919 
    1920         // Set up strings.
    1921         switch ( $action ) {
    1922             case 'delete' :
    1923                 $header_text = __( 'Delete Pending Accounts', 'buddypress' );
    1924                 if ( 1 == count( $signup_ids ) ) {
    1925                     $helper_text = __( 'You are about to delete the following account:', 'buddypress' );
    1926                 } else {
    1927                     $helper_text = __( 'You are about to delete the following accounts:', 'buddypress' );
    1928                 }
    1929                 break;
    1930 
    1931             case 'activate' :
    1932                 $header_text = __( 'Activate Pending Accounts', 'buddypress' );
    1933                 if ( 1 == count( $signup_ids ) ) {
    1934                     $helper_text = __( 'You are about to activate the following account:', 'buddypress' );
    1935                 } else {
    1936                     $helper_text = __( 'You are about to activate the following accounts:', 'buddypress' );
    1937                 }
    1938                 break;
    1939 
    1940             case 'resend' :
    1941                 $header_text = __( 'Resend Activation Emails', 'buddypress' );
    1942                 if ( 1 == count( $signup_ids ) ) {
    1943                     $helper_text = __( 'You are about to resend an activation email to the following account:', 'buddypress' );
    1944                 } else {
    1945                     $helper_text = __( 'You are about to resend an activation email to the following accounts:', 'buddypress' );
    1946                 }
    1947                 break;
    1948         }
    1949 
    1950         // These arguments are added to all URLs.
    1951         $url_args = array( 'page' => 'bp-signups' );
    1952 
    1953         // These arguments are only added when performing an action.
    1954         $action_args = array(
    1955             'action'     => 'do_' . $action,
    1956             'signup_ids' => implode( ',', $signup_ids )
    1957         );
    1958 
    1959         if ( is_network_admin() ) {
    1960             $base_url = network_admin_url( 'users.php' );
    1961         } else {
    1962             $base_url = bp_get_admin_url( 'users.php' );
    1963         }
    1964 
    1965         $cancel_url = add_query_arg( $url_args, $base_url );
    1966         $action_url = wp_nonce_url(
    1967             add_query_arg(
    1968                 array_merge( $url_args, $action_args ),
    1969                 $base_url
    1970             ),
    1971             'signups_' . $action
    1972         );
    1973 
    1974         ?>
    1975 
    1976         <div class="wrap">
    1977             <h1><?php echo esc_html( $header_text ); ?></h1>
    1978             <p><?php echo esc_html( $helper_text ); ?></p>
    1979 
    1980             <ol class="bp-signups-list">
    1981             <?php foreach ( $signups as $signup ) :
    1982 
    1983                 $last_notified = mysql2date( 'Y/m/d g:i:s a', $signup->date_sent ); ?>
    1984 
    1985                 <li>
    1986                     <?php echo esc_html( $signup->user_name ) ?> - <?php echo sanitize_email( $signup->user_email );?>
    1987 
    1988                     <?php if ( 'resend' == $action ) : ?>
    1989 
    1990                         <p class="description">
    1991                             <?php printf( esc_html__( 'Last notified: %s', 'buddypress'), $last_notified ) ;?>
    1992 
    1993                             <?php if ( ! empty( $signup->recently_sent ) ) : ?>
    1994 
    1995                                 <span class="attention wp-ui-text-notification"> <?php esc_html_e( '(less than 24 hours ago)', 'buddypress' ); ?></span>
    1996 
    1997                             <?php endif; ?>
    1998                         </p>
    1999 
    2000                     <?php endif; ?>
    2001 
    2002                 </li>
    2003 
    2004             <?php endforeach; ?>
    2005             </ol>
    2006 
    2007             <?php if ( 'delete' === $action ) : ?>
    2008 
    2009                 <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
    2010 
    2011             <?php endif ; ?>
    2012 
    2013             <a class="button-primary" href="<?php echo esc_url( $action_url ); ?>"><?php esc_html_e( 'Confirm', 'buddypress' ); ?></a>
    2014             <a class="button" href="<?php echo esc_url( $cancel_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a>
    2015         </div>
    2016 
    2017         <?php
    2018     }
    2019 }
    2020 endif; // End class_exists check.
     13require dirname( __FILE__ ) . '/classes/class-bp-members-admin.php';
    202114
    202215// Load the BP Members admin.
  • trunk/src/bp-members/bp-members-loader.php

    r10506 r10521  
    1111defined( 'ABSPATH' ) || exit;
    1212
    13 /**
    14  * Defines the BuddyPress Members Component.
    15  */
    16 class BP_Members_Component extends BP_Component {
    17 
    18     /**
    19      * Member types.
    20      *
    21      * @see bp_register_member_type()
    22      *
    23      * @since 2.2.0
    24      * @var array
    25      */
    26     public $types = array();
    27 
    28     /**
    29      * Start the members component creation process.
    30      *
    31      * @since 1.5.0
    32      */
    33     public function __construct() {
    34         parent::start(
    35             'members',
    36             __( 'Members', 'buddypress' ),
    37             buddypress()->plugin_dir,
    38             array(
    39                 'adminbar_myaccount_order' => 20,
    40                 'search_query_arg' => 'members_search',
    41             )
    42         );
    43     }
    44 
    45     /**
    46      * Include bp-members files.
    47      *
    48      * @see BP_Component::includes() for description of parameters.
    49      *
    50      * @param array $includes See {@link BP_Component::includes()}.
    51      */
    52     public function includes( $includes = array() ) {
    53 
    54         // Always include these files.
    55         $includes = array(
    56             'actions',
    57             'classes',
    58             'filters',
    59             'screens',
    60             'template',
    61             'adminbar',
    62             'functions',
    63             'widgets',
    64             'cache',
    65         );
    66 
    67         if ( bp_is_active( 'activity' ) ) {
    68             $includes[] = 'activity';
    69         }
    70 
    71         // Include these only if in admin.
    72         if ( is_admin() ) {
    73             $includes[] = 'admin';
    74         }
    75 
    76         parent::includes( $includes );
    77     }
    78 
    79     /**
    80      * Set up bp-members global settings.
    81      *
    82      * The BP_MEMBERS_SLUG constant is deprecated, and only used here for
    83      * backwards compatibility.
    84      *
    85      * @since 1.5.0
    86      *
    87      * @see BP_Component::setup_globals() for description of parameters.
    88      *
    89      * @param array $args See {@link BP_Component::setup_globals()}.
    90      */
    91     public function setup_globals( $args = array() ) {
    92         global $wpdb;
    93 
    94         $bp = buddypress();
    95 
    96         /** Component Globals ************************************************
    97          */
    98 
    99         // Define a slug, as a fallback for backpat.
    100         if ( !defined( 'BP_MEMBERS_SLUG' ) ) {
    101             define( 'BP_MEMBERS_SLUG', $this->id );
    102         }
    103 
    104         // Override any passed args.
    105         $args = array(
    106             'slug'            => BP_MEMBERS_SLUG,
    107             'root_slug'       => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG,
    108             'has_directory'   => true,
    109             'directory_title' => _x( 'Members', 'component directory title', 'buddypress' ),
    110             'search_string'   => __( 'Search Members...', 'buddypress' ),
    111             'global_tables'   => array(
    112                 'table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity',
    113                 'table_name_signups'       => $wpdb->base_prefix . 'signups', // signups is a global WordPress table
    114             )
    115         );
    116 
    117         parent::setup_globals( $args );
    118 
    119         /** Logged in user ***************************************************
    120          */
    121 
    122         // The core userdata of the user who is currently logged in.
    123         $bp->loggedin_user->userdata       = bp_core_get_core_userdata( bp_loggedin_user_id() );
    124 
    125         // Fetch the full name for the logged in user.
    126         $bp->loggedin_user->fullname       = isset( $bp->loggedin_user->userdata->display_name ) ? $bp->loggedin_user->userdata->display_name : '';
    127 
    128         // Hits the DB on single WP installs so get this separately.
    129         $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin( bp_loggedin_user_id() );
    130 
    131         // The domain for the user currently logged in. eg: http://example.com/members/andy.
    132         $bp->loggedin_user->domain         = bp_core_get_user_domain( bp_loggedin_user_id() );
    133 
    134         /** Displayed user ***************************************************
    135          */
    136 
    137         // The core userdata of the user who is currently being displayed.
    138         $bp->displayed_user->userdata = bp_core_get_core_userdata( bp_displayed_user_id() );
    139 
    140         // Fetch the full name displayed user.
    141         $bp->displayed_user->fullname = isset( $bp->displayed_user->userdata->display_name ) ? $bp->displayed_user->userdata->display_name : '';
    142 
    143         // The domain for the user currently being displayed.
    144         $bp->displayed_user->domain   = bp_core_get_user_domain( bp_displayed_user_id() );
    145 
    146         /** Signup ***********************************************************
    147          */
    148 
    149         $bp->signup = new stdClass;
    150 
    151         /** Profiles Fallback ************************************************
    152          */
    153 
    154         if ( ! bp_is_active( 'xprofile' ) ) {
    155             $bp->profile       = new stdClass;
    156             $bp->profile->slug = 'profile';
    157             $bp->profile->id   = 'profile';
    158         }
    159     }
    160 
    161     /**
    162      * Set up canonical stack for this component.
    163      *
    164      * @since 2.1.0
    165      */
    166     public function setup_canonical_stack() {
    167         $bp = buddypress();
    168 
    169         /** Default Profile Component ****************************************
    170          */
    171 
    172         if ( defined( 'BP_DEFAULT_COMPONENT' ) && BP_DEFAULT_COMPONENT ) {
    173             $bp->default_component = BP_DEFAULT_COMPONENT;
    174         } else {
    175             if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) {
    176                 $bp->default_component = bp_get_activity_slug();
    177             } else {
    178                 $bp->default_component = ( 'xprofile' === $bp->profile->id ) ? 'profile' : $bp->profile->id;
    179             }
    180         }
    181 
    182         /** Canonical Component Stack ****************************************
    183          */
    184 
    185         if ( bp_displayed_user_id() ) {
    186             $bp->canonical_stack['base_url'] = bp_displayed_user_domain();
    187 
    188             if ( bp_current_component() ) {
    189                 $bp->canonical_stack['component'] = bp_current_component();
    190             }
    191 
    192             if ( bp_current_action() ) {
    193                 $bp->canonical_stack['action'] = bp_current_action();
    194             }
    195 
    196             if ( !empty( $bp->action_variables ) ) {
    197                 $bp->canonical_stack['action_variables'] = bp_action_variables();
    198             }
    199 
    200             // Looking at the single member root/home, so assume the default.
    201             if ( ! bp_current_component() ) {
    202                 $bp->current_component = $bp->default_component;
    203 
    204             // The canonical URL will not contain the default component.
    205             } elseif ( bp_is_current_component( $bp->default_component ) && ! bp_current_action() ) {
    206                 unset( $bp->canonical_stack['component'] );
    207             }
    208 
    209             // If we're on a spammer's profile page, only users with the 'bp_moderate' cap
    210             // can view subpages on the spammer's profile.
    211             //
    212             // users without the cap trying to access a spammer's subnav page will get
    213             // redirected to the root of the spammer's profile page.  this occurs by
    214             // by removing the component in the canonical stack.
    215             if ( bp_is_user_spammer( bp_displayed_user_id() ) && ! bp_current_user_can( 'bp_moderate' ) ) {
    216                 unset( $bp->canonical_stack['component'] );
    217             }
    218         }
    219     }
    220 
    221     /**
    222      * Set up fall-back component navigation if XProfile is inactive.
    223      *
    224      * @since 1.5.0
    225      *
    226      * @see BP_Component::setup_nav() for a description of arguments.
    227      *
    228      * @param array $main_nav Optional. See BP_Component::setup_nav() for
    229      *                        description.
    230      * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
    231      *                        description.
    232      */
    233     public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    234 
    235         // Bail if XProfile component is active.
    236         if ( bp_is_active( 'xprofile' ) ) {
    237             return;
    238         }
    239 
    240         // Don't set up navigation if there's no member.
    241         if ( ! is_user_logged_in() && ! bp_is_user() ) {
    242             return;
    243         }
    244 
    245         // Determine user to use.
    246         if ( bp_displayed_user_domain() ) {
    247             $user_domain = bp_displayed_user_domain();
    248         } elseif ( bp_loggedin_user_domain() ) {
    249             $user_domain = bp_loggedin_user_domain();
    250         } else {
    251             return;
    252         }
    253 
    254         $slug         = bp_get_profile_slug();
    255         $profile_link = trailingslashit( $user_domain . $slug );
    256 
    257         // Setup the main navigation.
    258         $main_nav = array(
    259             'name'                => _x( 'Profile', 'Member profile main navigation', 'buddypress' ),
    260             'slug'                => $slug,
    261             'position'            => 20,
    262             'screen_function'     => 'bp_members_screen_display_profile',
    263             'default_subnav_slug' => 'public',
    264             'item_css_id'         => buddypress()->profile->id
    265         );
    266 
    267         // Setup the subnav items for the member profile.
    268         $sub_nav[] = array(
    269             'name'            => _x( 'View', 'Member profile view', 'buddypress' ),
    270             'slug'            => 'public',
    271             'parent_url'      => $profile_link,
    272             'parent_slug'     => $slug,
    273             'screen_function' => 'bp_members_screen_display_profile',
    274             'position'        => 10
    275         );
    276 
    277         parent::setup_nav( $main_nav, $sub_nav );
    278     }
    279 
    280     /**
    281      * Set up the title for pages and <title>.
    282      */
    283     public function setup_title() {
    284         $bp = buddypress();
    285 
    286         if ( bp_is_my_profile() ) {
    287             $bp->bp_options_title = __( 'You', 'buddypress' );
    288         } elseif ( bp_is_user() ) {
    289             $bp->bp_options_title  = bp_get_displayed_user_fullname();
    290             $bp->bp_options_avatar = bp_core_fetch_avatar( array(
    291                 'item_id' => bp_displayed_user_id(),
    292                 'type'    => 'thumb',
    293                 'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $bp->bp_options_title )
    294             ) );
    295         }
    296 
    297         parent::setup_title();
    298     }
    299 
    300     /**
    301      * Setup cache groups.
    302      *
    303      * @since 2.2.0
    304      */
    305     public function setup_cache_groups() {
    306 
    307         // Global groups.
    308         wp_cache_add_global_groups( array(
    309             'bp_last_activity',
    310             'bp_member_type'
    311         ) );
    312 
    313         parent::setup_cache_groups();
    314     }
    315 }
     13require dirname( __FILE__ ) . '/classes/class-bp-members-component.php';
    31614
    31715/**
  • trunk/src/bp-members/bp-members-screens.php

    r10487 r10521  
    1212// Exit if accessed directly.
    1313defined( 'ABSPATH' ) || exit;
     14
     15require dirname( __FILE__ ) . '/classes/class-bp-members-theme-compat.php';
     16require dirname( __FILE__ ) . '/classes/class-bp-registration-theme-compat.php';
    1417
    1518/**
     
    382385/** Theme Compatibility *******************************************************/
    383386
    384 /**
    385  * The main theme compat class for BuddyPress Members.
    386  *
    387  * This class sets up the necessary theme compatibility actions to safely output
    388  * member template parts to the_title and the_content areas of a theme.
    389  *
    390  * @since 1.7.0
    391  */
    392 class BP_Members_Theme_Compat {
    393 
    394     /**
    395      * Set up the members component theme compatibility.
    396      *
    397      * @since 1.7.0
    398      */
    399     public function __construct() {
    400         add_action( 'bp_setup_theme_compat', array( $this, 'is_members' ) );
    401     }
    402 
    403     /**
    404      * Are we looking at something that needs members theme compatibility?
    405      *
    406      * @since 1.7.0
    407      */
    408     public function is_members() {
    409 
    410         // Bail if not looking at the members component or a user's page.
    411         if ( ! bp_is_members_component() && ! bp_is_user() ) {
    412             return;
    413         }
    414 
    415         // Members Directory.
    416         if ( ! bp_current_action() && ! bp_current_item() ) {
    417             bp_update_is_directory( true, 'members' );
    418 
    419             /**
    420              * Fires if looking at Members directory when needing theme compat.
    421              *
    422              * @since 1.5.0
    423              */
    424             do_action( 'bp_members_screen_index' );
    425 
    426             add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    427             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    428             add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
    429 
    430         // User page.
    431         } elseif ( bp_is_user() ) {
    432 
    433             // If we're on a single activity permalink page, we shouldn't use the members
    434             // template, so stop here!
    435             if ( bp_is_active( 'activity' ) && bp_is_single_activity() ) {
    436                 return;
    437             }
    438 
    439             /**
    440              * Fires if looking at Members user page when needing theme compat.
    441              *
    442              * @since 1.5.0
    443              */
    444             do_action( 'bp_members_screen_display_profile' );
    445 
    446             add_filter( 'bp_get_buddypress_template',                array( $this, 'single_template_hierarchy' ) );
    447             add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post'    ) );
    448             add_filter( 'bp_replace_the_content',                    array( $this, 'single_dummy_content' ) );
    449 
    450         }
    451     }
    452 
    453     /** Directory *************************************************************/
    454 
    455     /**
    456      * Add template hierarchy to theme compat for the members directory page.
    457      *
    458      * This is to mirror how WordPress has
    459      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    460      *
    461      * @since 1.8.0
    462      *
    463      * @param array $templates The templates from bp_get_theme_compat_templates().
    464      * @return array $templates Array of custom templates to look for.
    465      */
    466     public function directory_template_hierarchy( $templates = array() ) {
    467 
    468         // Set up the template hierarchy.
    469         $new_templates = array();
    470         if ( '' !== bp_get_current_member_type() ) {
    471             $new_templates[] = 'members/index-directory-type-' . sanitize_file_name( bp_get_current_member_type() ) . '.php';
    472         }
    473         $new_templates[] = 'members/index-directory.php';
    474 
    475         /**
    476          * Filters the template hierarchy for theme compat and members directory page.
    477          *
    478          * @since 1.8.0
    479          *
    480          * @param array $value Array of template paths to add to hierarchy.
    481          */
    482         $new_templates = apply_filters( 'bp_template_hierarchy_members_directory', $new_templates );
    483 
    484         // Merge new templates with existing stack
    485         // @see bp_get_theme_compat_templates().
    486         $templates = array_merge( (array) $new_templates, $templates );
    487 
    488         return $templates;
    489     }
    490 
    491     /**
    492      * Update the global $post with directory data.
    493      *
    494      * @since 1.7.0
    495      */
    496     public function directory_dummy_post() {
    497         bp_theme_compat_reset_post( array(
    498             'ID'             => 0,
    499             'post_title'     => bp_get_directory_title( 'members' ),
    500             'post_author'    => 0,
    501             'post_date'      => 0,
    502             'post_content'   => '',
    503             'post_type'      => 'page',
    504             'post_status'    => 'publish',
    505             'is_page'        => true,
    506             'comment_status' => 'closed'
    507         ) );
    508     }
    509 
    510     /**
    511      * Filter the_content with the members index template part.
    512      *
    513      * @since 1.7.0
    514      */
    515     public function directory_content() {
    516         return bp_buffer_template_part( 'members/index', null, false );
    517     }
    518 
    519     /** Single ****************************************************************/
    520 
    521     /**
    522      * Add custom template hierarchy to theme compat for member pages.
    523      *
    524      * This is to mirror how WordPress has
    525      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    526      *
    527      * @since 1.8.0
    528      *
    529      * @param string $templates The templates from
    530      *                          bp_get_theme_compat_templates().
    531      * @return array $templates Array of custom templates to look for.
    532      */
    533     public function single_template_hierarchy( $templates ) {
    534         // Setup some variables we're going to reference in our custom templates.
    535         $user_nicename = buddypress()->displayed_user->userdata->user_nicename;
    536 
    537         /**
    538          * Filters the template hierarchy for theme compat and member pages.
    539          *
    540          * @since 1.8.0
    541          *
    542          * @param array $value Array of template paths to add to hierarchy.
    543          */
    544         $new_templates = apply_filters( 'bp_template_hierarchy_members_single_item', array(
    545             'members/single/index-id-'        . sanitize_file_name( bp_displayed_user_id() ) . '.php',
    546             'members/single/index-nicename-'  . sanitize_file_name( $user_nicename )         . '.php',
    547             'members/single/index-action-'    . sanitize_file_name( bp_current_action() )    . '.php',
    548             'members/single/index-component-' . sanitize_file_name( bp_current_component() ) . '.php',
    549             'members/single/index.php'
    550         ) );
    551 
    552         // Merge new templates with existing stack
    553         // @see bp_get_theme_compat_templates().
    554         $templates = array_merge( (array) $new_templates, $templates );
    555 
    556         return $templates;
    557     }
    558 
    559     /**
    560      * Update the global $post with the displayed user's data.
    561      *
    562      * @since 1.7.0
    563      */
    564     public function single_dummy_post() {
    565         bp_theme_compat_reset_post( array(
    566             'ID'             => 0,
    567             'post_title'     => bp_get_displayed_user_fullname(),
    568             'post_author'    => 0,
    569             'post_date'      => 0,
    570             'post_content'   => '',
    571             'post_type'      => 'page',
    572             'post_status'    => 'publish',
    573             'is_page'        => true,
    574             'comment_status' => 'closed'
    575         ) );
    576     }
    577 
    578     /**
    579      * Filter the_content with the members' single home template part.
    580      *
    581      * @since 1.7.0
    582      */
    583     public function single_dummy_content() {
    584         return bp_buffer_template_part( 'members/single/home', null, false );
    585     }
    586 }
    587387new BP_Members_Theme_Compat();
    588 
    589 /**
    590  * The main theme compat class for BuddyPress Registration.
    591  *
    592  * This class sets up the necessary theme compatibility actions to safely output
    593  * registration template parts to the_title and the_content areas of a theme.
    594  *
    595  * @since 1.7.0
    596  */
    597 class BP_Registration_Theme_Compat {
    598 
    599     /**
    600      * Setup the groups component theme compatibility.
    601      *
    602      * @since 1.7.0
    603      */
    604     public function __construct() {
    605         add_action( 'bp_setup_theme_compat', array( $this, 'is_registration' ) );
    606     }
    607 
    608     /**
    609      * Are we looking at either the registration or activation pages?
    610      *
    611      * @since 1.7.0
    612      */
    613     public function is_registration() {
    614 
    615         // Bail if not looking at the registration or activation page.
    616         if ( ! bp_is_register_page() && ! bp_is_activation_page() ) {
    617             return;
    618         }
    619 
    620         // Not a directory.
    621         bp_update_is_directory( false, 'register' );
    622 
    623         // Setup actions.
    624         add_filter( 'bp_get_buddypress_template',                array( $this, 'template_hierarchy' ) );
    625         add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'dummy_post'    ) );
    626         add_filter( 'bp_replace_the_content',                    array( $this, 'dummy_content' ) );
    627     }
    628 
    629     /** Template ***********************************************************/
    630 
    631     /**
    632      * Add template hierarchy to theme compat for registration/activation pages.
    633      *
    634      * This is to mirror how WordPress has
    635      * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
    636      *
    637      * @since 1.8.0
    638      *
    639      * @param string $templates The templates from bp_get_theme_compat_templates().
    640      * @return array $templates Array of custom templates to look for.
    641      */
    642     public function template_hierarchy( $templates ) {
    643         $component = sanitize_file_name( bp_current_component() );
    644 
    645         /**
    646          * Filters the template hierarchy for theme compat and registration/activation pages.
    647          *
    648          * This filter is a variable filter that depends on the current component
    649          * being used.
    650          *
    651          * @since 1.8.0
    652          *
    653          * @param array $value Array of template paths to add to hierarchy.
    654          */
    655         $new_templates = apply_filters( "bp_template_hierarchy_{$component}", array(
    656             "members/index-{$component}.php"
    657         ) );
    658 
    659         // Merge new templates with existing stack
    660         // @see bp_get_theme_compat_templates().
    661         $templates = array_merge( (array) $new_templates, $templates );
    662 
    663         return $templates;
    664     }
    665 
    666     /**
    667      * Update the global $post with dummy data.
    668      *
    669      * @since 1.7.0
    670      */
    671     public function dummy_post() {
    672         // Registration page.
    673         if ( bp_is_register_page() ) {
    674             $title = __( 'Create an Account', 'buddypress' );
    675 
    676             if ( 'completed-confirmation' == bp_get_current_signup_step() ) {
    677                 $title = __( 'Check Your Email To Activate Your Account!', 'buddypress' );
    678             }
    679 
    680         // Activation page.
    681         } else {
    682             $title = __( 'Activate Your Account', 'buddypress' );
    683 
    684             if ( bp_account_was_activated() ) {
    685                 $title = __( 'Account Activated', 'buddypress' );
    686             }
    687         }
    688 
    689         bp_theme_compat_reset_post( array(
    690             'ID'             => 0,
    691             'post_title'     => $title,
    692             'post_author'    => 0,
    693             'post_date'      => 0,
    694             'post_content'   => '',
    695             'post_type'      => 'page',
    696             'post_status'    => 'publish',
    697             'is_page'        => true,
    698             'comment_status' => 'closed'
    699         ) );
    700     }
    701 
    702     /**
    703      * Filter the_content with either the register or activate templates.
    704      *
    705      * @since 1.7.0
    706      */
    707     public function dummy_content() {
    708         if ( bp_is_register_page() ) {
    709             return bp_buffer_template_part( 'members/register', null, false );
    710         } else {
    711             return bp_buffer_template_part( 'members/activate', null, false );
    712         }
    713     }
    714 }
    715388new BP_Registration_Theme_Compat();
  • trunk/src/bp-members/bp-members-template.php

    r10459 r10521  
    1212// Exit if accessed directly.
    1313defined( 'ABSPATH' ) || exit;
     14
     15require dirname( __FILE__ ) . '/classes/class-bp-core-members-template.php';
    1416
    1517/**
     
    282284        return apply_filters( 'bp_get_activate_slug', $slug );
    283285    }
    284 
    285 /**
    286  * The main member template loop class.
    287  *
    288  * Responsible for loading a group of members into a loop for display.
    289  */
    290 class BP_Core_Members_Template {
    291 
    292     /**
    293      * The loop iterator.
    294      *
    295      * @var int
    296      */
    297     public $current_member = -1;
    298 
    299     /**
    300      * The number of members returned by the paged query.
    301      *
    302      * @var int
    303      */
    304     public $member_count;
    305 
    306     /**
    307      * Array of members located by the query.
    308      *
    309      * @var array
    310      */
    311     public $members;
    312 
    313     /**
    314      * The member object currently being iterated on.
    315      *
    316      * @var object
    317      */
    318     public $member;
    319 
    320     /**
    321      * A flag for whether the loop is currently being iterated.
    322      *
    323      * @var bool
    324      */
    325     public $in_the_loop;
    326 
    327     /**
    328      * The type of member being requested. Used for ordering results.
    329      *
    330      * @var string
    331      */
    332     public $type;
    333 
    334     /**
    335      * The unique string used for pagination queries.
    336      *
    337      * @var string
    338      */
    339     public $pag_arg;
    340 
    341     /**
    342      * The page number being requested.
    343      *
    344      * @var string
    345      */
    346     public $pag_page;
    347 
    348     /**
    349      * The number of items being requested per page.
    350      *
    351      * @var string
    352      */
    353     public $pag_num;
    354 
    355     /**
    356      * An HTML string containing pagination links.
    357      *
    358      * @var string
    359      */
    360     public $pag_links;
    361 
    362     /**
    363      * The total number of members matching the query parameters.
    364      *
    365      * @var int
    366      */
    367     public $total_member_count;
    368 
    369     /**
    370      * Constructor method.
    371      *
    372      * @see BP_User_Query for an in-depth description of parameters.
    373      *
    374      * @param string       $type                Sort order.
    375      * @param int          $page_number         Page of results.
    376      * @param int          $per_page            Number of results per page.
    377      * @param int          $max                 Max number of results to return.
    378      * @param int          $user_id             Limit to friends of a user.
    379      * @param string       $search_terms        Limit to users matching search terms.
    380      * @param array        $include             Limit results by these user IDs.
    381      * @param bool         $populate_extras     Fetch optional extras.
    382      * @param array        $exclude             Exclude these IDs from results.
    383      * @param array        $meta_key            Limit to users with a meta_key.
    384      * @param array        $meta_value          Limit to users with a meta_value (with meta_key).
    385      * @param string       $page_arg            Optional. The string used as a query parameter in pagination links.
    386      *                                          Default: 'upage'.
    387      * @param array|string $member_type         Array or comma-separated string of member types to limit results to.
    388      * @param array|string $member_type__in     Array or comma-separated string of member types to limit results to.
    389      * @param array|string $member_type__not_in Array or comma-separated string of member types to exclude
    390      *                                          from results.
    391      */
    392     function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '', $member_type__in = '', $member_type__not_in = '' ) {
    393 
    394         $this->pag_arg  = sanitize_key( $page_arg );
    395         $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page_number );
    396         $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $per_page    );
    397         $this->type     = $type;
    398 
    399         if ( !empty( $_REQUEST['letter'] ) )
    400             $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude );
    401         else
    402             $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'member_type' => $member_type, 'member_type__in' => $member_type__in, 'member_type__not_in' => $member_type__not_in ) );
    403 
    404         if ( !$max || $max >= (int) $this->members['total'] )
    405             $this->total_member_count = (int) $this->members['total'];
    406         else
    407             $this->total_member_count = (int) $max;
    408 
    409         $this->members = $this->members['users'];
    410 
    411         if ( $max ) {
    412             if ( $max >= count( $this->members ) ) {
    413                 $this->member_count = count( $this->members );
    414             } else {
    415                 $this->member_count = (int) $max;
    416             }
    417         } else {
    418             $this->member_count = count( $this->members );
    419         }
    420 
    421         if ( (int) $this->total_member_count && (int) $this->pag_num ) {
    422             $pag_args = array(
    423                 $this->pag_arg => '%#%',
    424             );
    425 
    426             if ( defined( 'DOING_AJAX' ) && true === (bool) DOING_AJAX ) {
    427                 $base = remove_query_arg( 's', wp_get_referer() );
    428             } else {
    429                 $base = '';
    430             }
    431 
    432             /**
    433              * Defaults to an empty array to make sure paginate_links()
    434              * won't add the $page_arg to the links which would break
    435              * pagination in case JavaScript is disabled.
    436              */
    437             $add_args = array();
    438 
    439             if ( ! empty( $search_terms ) ) {
    440                 $query_arg = bp_core_get_component_search_query_arg( 'members' );
    441                 $add_args[ $query_arg ] = urlencode( $search_terms );
    442             }
    443 
    444             $this->pag_links = paginate_links( array(
    445                 'base'      => add_query_arg( $pag_args, $base ),
    446                 'format'    => '',
    447                 'total'     => ceil( (int) $this->total_member_count / (int) $this->pag_num ),
    448                 'current'   => (int) $this->pag_page,
    449                 'prev_text' => _x( '&larr;', 'Member pagination previous text', 'buddypress' ),
    450                 'next_text' => _x( '&rarr;', 'Member pagination next text', 'buddypress' ),
    451                 'mid_size'  => 1,
    452                 'add_args'  => $add_args,
    453             ) );
    454         }
    455     }
    456 
    457     /**
    458      * Whether there are members available in the loop.
    459      *
    460      * @see bp_has_members()
    461      *
    462      * @return bool True if there are items in the loop, otherwise false.
    463      */
    464     function has_members() {
    465         if ( $this->member_count )
    466             return true;
    467 
    468         return false;
    469     }
    470 
    471     /**
    472      * Set up the next member and iterate index.
    473      *
    474      * @return object The next member to iterate over.
    475      */
    476     function next_member() {
    477         $this->current_member++;
    478         $this->member = $this->members[$this->current_member];
    479 
    480         return $this->member;
    481     }
    482 
    483     /**
    484      * Rewind the members and reset member index.
    485      */
    486     function rewind_members() {
    487         $this->current_member = -1;
    488         if ( $this->member_count > 0 ) {
    489             $this->member = $this->members[0];
    490         }
    491     }
    492 
    493     /**
    494      * Whether there are members left in the loop to iterate over.
    495      *
    496      * This method is used by {@link bp_members()} as part of the while loop
    497      * that controls iteration inside the members loop, eg:
    498      *     while ( bp_members() ) { ...
    499      *
    500      * @see bp_members()
    501      *
    502      * @return bool True if there are more members to show, otherwise false.
    503      */
    504     function members() {
    505         if ( $this->current_member + 1 < $this->member_count ) {
    506             return true;
    507         } elseif ( $this->current_member + 1 == $this->member_count ) {
    508 
    509             /**
    510              * Fires right before the rewinding of members listing.
    511              *
    512              * @since 1.5.0
    513              */
    514             do_action('member_loop_end');
    515             // Do some cleaning up after the loop.
    516             $this->rewind_members();
    517         }
    518 
    519         $this->in_the_loop = false;
    520         return false;
    521     }
    522 
    523     /**
    524      * Set up the current member inside the loop.
    525      *
    526      * Used by {@link bp_the_member()} to set up the current member data
    527      * while looping, so that template tags used during that iteration make
    528      * reference to the current member.
    529      *
    530      * @see bp_the_member()
    531      */
    532     function the_member() {
    533 
    534         $this->in_the_loop = true;
    535         $this->member      = $this->next_member();
    536 
    537         // Loop has just started.
    538         if ( 0 == $this->current_member ) {
    539 
    540             /**
    541              * Fires if the current member is the first in the loop.
    542              *
    543              * @since 1.5.0
    544              */
    545             do_action( 'member_loop_start' );
    546         }
    547 
    548     }
    549 }
    550 
    551 /**
    552  * Rewind the members and reset member index.
    553  */
    554 function bp_rewind_members() {
    555     global $members_template;
    556 
    557     return $members_template->rewind_members();
    558 }
    559286
    560287/**
  • trunk/src/bp-members/bp-members-widgets.php

    r10417 r10521  
    1010// Exit if accessed directly.
    1111defined( 'ABSPATH' ) || exit;
     12
     13require dirname( __FILE__ ) . '/classes/class-bp-core-members-widget.php';
     14require dirname( __FILE__ ) . '/classes/class-bp-core-whos-online-widget.php';
     15require dirname( __FILE__ ) . '/classes/class-bp-core-recently-active-widget.php';
    1216
    1317/**
     
    2428}
    2529add_action( 'bp_register_widgets', 'bp_members_register_widgets' );
    26 
    27 /**
    28  * Members Widget.
    29  *
    30  * @since 1.0.3
    31  */
    32 class BP_Core_Members_Widget extends WP_Widget {
    33 
    34     /**
    35      * Constructor method.
    36      */
    37     public function __construct() {
    38 
    39         // Setup widget name & description.
    40         $name        = _x( '(BuddyPress) Members', 'widget name', 'buddypress' );
    41         $description = __( 'A dynamic list of recently active, popular, and newest members', 'buddypress' );
    42 
    43         // Call WP_Widget constructor.
    44         parent::__construct( false, $name, array(
    45             'description' => $description,
    46             'classname'   => 'widget_bp_core_members_widget buddypress widget',
    47         ) );
    48 
    49         // Maybe enqueue JS for widget.
    50         if ( is_active_widget( false, false, $this->id_base ) && ! is_admin() && ! is_network_admin() ) {
    51             wp_enqueue_script( 'bp-widget-members' );
    52         }
    53     }
    54 
    55     /**
    56      * Display the Members widget.
    57      *
    58      * @see WP_Widget::widget() for description of parameters.
    59      *
    60      * @param array $args     Widget arguments.
    61      * @param array $instance Widget settings, as saved by the user.
    62      */
    63     public function widget( $args, $instance ) {
    64 
    65         // Get widget settings.
    66         $settings = $this->parse_settings( $instance );
    67 
    68         /**
    69          * Filters the title of the Members widget.
    70          *
    71          * @since 1.8.0
    72          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    73          *
    74          * @param string $title    The widget title.
    75          * @param array  $settings The settings for the particular instance of the widget.
    76          * @param string $id_base  Root ID for all widgets of this type.
    77          */
    78         $title = apply_filters( 'widget_title', $settings['title'], $settings, $this->id_base );
    79         $title = $settings['link_title'] ? '<a href="' . bp_get_members_directory_permalink() . '">' . $title . '</a>' : $title;
    80 
    81         /**
    82          * Filters the separator of the member widget links.
    83          *
    84          * @since 2.4.0
    85          *
    86          * @param string $separator Separator string. Default '|'.
    87          */
    88         $separator = apply_filters( 'bp_members_widget_separator', '|' );
    89 
    90         // Output before widget HTMl, title (and maybe content before & after it).
    91         echo $args['before_widget']
    92            . $args['before_title']
    93            . $title
    94            . $args['after_title'];
    95 
    96         // Setup args for querying members.
    97         $members_args = array(
    98             'user_id'         => 0,
    99             'type'            => $settings['member_default'],
    100             'per_page'        => $settings['max_members'],
    101             'max'             => $settings['max_members'],
    102             'populate_extras' => true,
    103             'search_terms'    => false,
    104         ); ?>
    105 
    106         <?php if ( bp_has_members( $members_args ) ) : ?>
    107 
    108             <div class="item-options" id="members-list-options">
    109                 <a href="<?php bp_members_directory_permalink(); ?>" id="newest-members" <?php if ( 'newest' === $settings['member_default'] ) : ?>class="selected"<?php endif; ?>><?php esc_html_e( 'Newest', 'buddypress' ); ?></a>
    110                 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span>
    111                 <a href="<?php bp_members_directory_permalink(); ?>" id="recently-active-members" <?php if ( 'active' === $settings['member_default'] ) : ?>class="selected"<?php endif; ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></a>
    112 
    113                 <?php if ( bp_is_active( 'friends' ) ) : ?>
    114                     <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span>
    115                     <a href="<?php bp_members_directory_permalink(); ?>" id="popular-members" <?php if ( 'popular' === $settings['member_default'] ) : ?>class="selected"<?php endif; ?>><?php esc_html_e( 'Popular', 'buddypress' ); ?></a>
    116 
    117                 <?php endif; ?>
    118 
    119             </div>
    120 
    121             <ul id="members-list" class="item-list">
    122 
    123                 <?php while ( bp_members() ) : bp_the_member(); ?>
    124 
    125                     <li class="vcard">
    126                         <div class="item-avatar">
    127                             <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a>
    128                         </div>
    129 
    130                         <div class="item">
    131                             <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>" title="<?php bp_member_name(); ?>"><?php bp_member_name(); ?></a></div>
    132                             <div class="item-meta">
    133                                 <span class="activity"><?php
    134                                     if ( 'newest' === $settings['member_default'] ) :
    135                                         bp_member_registered();
    136                                     elseif ( 'active' === $settings['member_default'] ) :
    137                                         bp_member_last_active();
    138                                     elseif ( 'popular' === $settings['member_default'] ) :
    139                                         bp_member_total_friend_count();
    140                                     endif; ?></span>
    141                             </div>
    142                         </div>
    143                     </li>
    144 
    145                 <?php endwhile; ?>
    146 
    147             </ul>
    148 
    149             <?php wp_nonce_field( 'bp_core_widget_members', '_wpnonce-members', false ); ?>
    150 
    151             <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo esc_attr( $settings['max_members'] ); ?>" />
    152 
    153         <?php else: ?>
    154 
    155             <div class="widget-error">
    156                 <?php esc_html_e( 'No one has signed up yet!', 'buddypress' ); ?>
    157             </div>
    158 
    159         <?php endif; ?>
    160 
    161         <?php echo $args['after_widget'];
    162     }
    163 
    164     /**
    165      * Update the Members widget options.
    166      *
    167      * @param array $new_instance The new instance options.
    168      * @param array $old_instance The old instance options.
    169      * @return array $instance The parsed options to be saved.
    170      */
    171     public function update( $new_instance, $old_instance ) {
    172         $instance = $old_instance;
    173 
    174         $instance['title']          = strip_tags( $new_instance['title'] );
    175         $instance['max_members']    = strip_tags( $new_instance['max_members'] );
    176         $instance['member_default'] = strip_tags( $new_instance['member_default'] );
    177         $instance['link_title']     = (bool) $new_instance['link_title'];
    178 
    179         return $instance;
    180     }
    181 
    182     /**
    183      * Output the Members widget options form.
    184      *
    185      * @param array $instance Widget instance settings.
    186      *
    187      * @return void
    188      */
    189     public function form( $instance ) {
    190 
    191         // Get widget settings.
    192         $settings       = $this->parse_settings( $instance );
    193         $title          = strip_tags( $settings['title'] );
    194         $max_members    = strip_tags( $settings['max_members'] );
    195         $member_default = strip_tags( $settings['member_default'] );
    196         $link_title     = (bool) $settings['link_title']; ?>
    197 
    198         <p>
    199             <label for="<?php echo $this->get_field_id( 'title' ); ?>">
    200                 <?php esc_html_e( 'Title:', 'buddypress' ); ?>
    201                 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" />
    202             </label>
    203         </p>
    204 
    205         <p>
    206             <label for="<?php echo $this->get_field_id( 'link_title' ) ?>">
    207                 <input type="checkbox" name="<?php echo $this->get_field_name( 'link_title' ) ?>" id="<?php echo $this->get_field_id( 'link_title' ) ?>" value="1" <?php checked( $link_title ) ?> />
    208                 <?php esc_html_e( 'Link widget title to Members directory', 'buddypress' ); ?>
    209             </label>
    210         </p>
    211 
    212         <p>
    213             <label for="<?php echo $this->get_field_id( 'max_members' ); ?>">
    214                 <?php esc_html_e( 'Max members to show:', 'buddypress' ); ?>
    215                 <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" />
    216             </label>
    217         </p>
    218 
    219         <p>
    220             <label for="<?php echo $this->get_field_id( 'member_default' ) ?>"><?php esc_html_e( 'Default members to show:', 'buddypress' ); ?></label>
    221             <select name="<?php echo $this->get_field_name( 'member_default' ) ?>" id="<?php echo $this->get_field_id( 'member_default' ) ?>">
    222                 <option value="newest"  <?php if ( 'newest'  === $member_default ) : ?>selected="selected"<?php endif; ?>><?php esc_html_e( 'Newest',  'buddypress' ); ?></option>
    223                 <option value="active"  <?php if ( 'active'  === $member_default ) : ?>selected="selected"<?php endif; ?>><?php esc_html_e( 'Active',  'buddypress' ); ?></option>
    224                 <option value="popular" <?php if ( 'popular' === $member_default ) : ?>selected="selected"<?php endif; ?>><?php esc_html_e( 'Popular', 'buddypress' ); ?></option>
    225             </select>
    226         </p>
    227 
    228     <?php
    229     }
    230 
    231     /**
    232      * Merge the widget settings into defaults array.
    233      *
    234      * @since 2.3.0
    235      *
    236      * @uses bp_parse_args() To merge widget settings into defaults.
    237      *
    238      * @param array $instance Widget instance settings.
    239      * @return array
    240      */
    241     public function parse_settings( $instance = array() ) {
    242         return bp_parse_args( $instance, array(
    243             'title'          => __( 'Members', 'buddypress' ),
    244             'max_members'    => 5,
    245             'member_default' => 'active',
    246             'link_title'     => false
    247         ), 'members_widget_settings' );
    248     }
    249 }
    250 
    251 /**
    252  * Who's Online Widget.
    253  *
    254  * @since 1.0.3
    255  */
    256 class BP_Core_Whos_Online_Widget extends WP_Widget {
    257 
    258     /**
    259      * Constructor method.
    260      */
    261     public function __construct() {
    262         $name        = _x( "(BuddyPress) Who's Online", 'widget name', 'buddypress' );
    263         $description = __( 'Profile photos of online users', 'buddypress' );
    264         parent::__construct( false, $name, array(
    265             'description' => $description,
    266             'classname' => 'widget_bp_core_whos_online_widget buddypress widget',
    267         ) );
    268     }
    269 
    270     /**
    271      * Display the Who's Online widget.
    272      *
    273      * @see WP_Widget::widget() for description of parameters.
    274      *
    275      * @param array $args     Widget arguments.
    276      * @param array $instance Widget settings, as saved by the user.
    277      */
    278     public function widget( $args, $instance ) {
    279 
    280         // Get widget settings.
    281         $settings = $this->parse_settings( $instance );
    282 
    283         /**
    284          * Filters the title of the Who's Online widget.
    285          *
    286          * @since 1.8.0
    287          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    288          *
    289          * @param string $title    The widget title.
    290          * @param array  $settings The settings for the particular instance of the widget.
    291          * @param string $id_base  Root ID for all widgets of this type.
    292          */
    293         $title = apply_filters( 'widget_title', $settings['title'], $settings, $this->id_base );
    294 
    295         echo $args['before_widget']
    296            . $args['before_title']
    297            . $title
    298            . $args['after_title'];
    299 
    300         // Setup args for querying members.
    301         $members_args = array(
    302             'user_id'         => 0,
    303             'type'            => 'online',
    304             'per_page'        => $settings['max_members'],
    305             'max'             => $settings['max_members'],
    306             'populate_extras' => true,
    307             'search_terms'    => false,
    308         ); ?>
    309 
    310         <?php if ( bp_has_members( $members_args ) ) : ?>
    311 
    312             <div class="avatar-block">
    313 
    314                 <?php while ( bp_members() ) : bp_the_member(); ?>
    315 
    316                     <div class="item-avatar">
    317                         <a href="<?php bp_member_permalink(); ?>" title="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a>
    318                     </div>
    319 
    320                 <?php endwhile; ?>
    321 
    322             </div>
    323 
    324         <?php else: ?>
    325 
    326             <div class="widget-error">
    327                 <?php esc_html_e( 'There are no users currently online', 'buddypress' ); ?>
    328             </div>
    329 
    330         <?php endif; ?>
    331 
    332         <?php echo $args['after_widget'];
    333     }
    334 
    335     /**
    336      * Update the Who's Online widget options.
    337      *
    338      * @param array $new_instance The new instance options.
    339      * @param array $old_instance The old instance options.
    340      * @return array $instance The parsed options to be saved.
    341      */
    342     public function update( $new_instance, $old_instance ) {
    343         $instance                = $old_instance;
    344         $instance['title']       = strip_tags( $new_instance['title'] );
    345         $instance['max_members'] = strip_tags( $new_instance['max_members'] );
    346 
    347         return $instance;
    348     }
    349 
    350     /**
    351      * Output the Who's Online widget options form.
    352      *
    353      * @param array $instance Widget instance settings.
    354      * @return void
    355      */
    356     public function form( $instance ) {
    357 
    358         // Get widget settings.
    359         $settings    = $this->parse_settings( $instance );
    360         $title       = strip_tags( $settings['title'] );
    361         $max_members = strip_tags( $settings['max_members'] ); ?>
    362 
    363         <p>
    364             <label for="<?php echo $this->get_field_id( 'title' ); ?>">
    365                 <?php esc_html_e( 'Title:', 'buddypress' ); ?>
    366                 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" />
    367             </label>
    368         </p>
    369 
    370         <p>
    371             <label for="<?php echo $this->get_field_id( 'max_members' ); ?>">
    372                 <?php esc_html_e( 'Max members to show:', 'buddypress' ); ?>
    373                 <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" />
    374             </label>
    375         </p>
    376 
    377     <?php
    378     }
    379 
    380     /**
    381      * Merge the widget settings into defaults array.
    382      *
    383      * @since 2.3.0
    384      *
    385      * @uses bp_parse_args() To merge widget settings into defaults.
    386      *
    387      * @param array $instance Widget instance settings.
    388      * @return array
    389      */
    390     public function parse_settings( $instance = array() ) {
    391         return bp_parse_args( $instance, array(
    392             'title'          => __( "Who's Online", 'buddypress' ),
    393             'max_members'    => 15,
    394         ), 'members_widget_settings' );
    395     }
    396 }
    397 
    398 /**
    399  * Recently Active Members Widget.
    400  *
    401  * @since 1.0.3
    402  */
    403 class BP_Core_Recently_Active_Widget extends WP_Widget {
    404 
    405     /**
    406      * Constructor method.
    407      */
    408     public function __construct() {
    409         $name        = _x( '(BuddyPress) Recently Active Members', 'widget name', 'buddypress' );
    410         $description = __( 'Profile photos of recently active members', 'buddypress' );
    411         parent::__construct( false, $name, array(
    412             'description' => $description,
    413             'classname'   => 'widget_bp_core_recently_active_widget buddypress widget',
    414         ) );
    415     }
    416 
    417     /**
    418      * Display the Recently Active widget.
    419      *
    420      * @see WP_Widget::widget() for description of parameters.
    421      *
    422      * @param array $args     Widget arguments.
    423      * @param array $instance Widget settings, as saved by the user.
    424      */
    425     public function widget( $args, $instance ) {
    426 
    427         // Get widget settings.
    428         $settings = $this->parse_settings( $instance );
    429 
    430         /**
    431          * Filters the title of the Recently Active widget.
    432          *
    433          * @since 1.8.0
    434          * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    435          *
    436          * @param string $title    The widget title.
    437          * @param array  $settings The settings for the particular instance of the widget.
    438          * @param string $id_base  Root ID for all widgets of this type.
    439          */
    440         $title = apply_filters( 'widget_title', $settings['title'], $settings, $this->id_base );
    441 
    442         echo $args['before_widget'];
    443         echo $args['before_title']
    444            . $title
    445            . $args['after_title'];
    446 
    447         // Setup args for querying members.
    448         $members_args = array(
    449             'user_id'         => 0,
    450             'type'            => 'active',
    451             'per_page'        => $settings['max_members'],
    452             'max'             => $settings['max_members'],
    453             'populate_extras' => true,
    454             'search_terms'    => false,
    455         ); ?>
    456 
    457         <?php if ( bp_has_members( $members_args ) ) : ?>
    458 
    459             <div class="avatar-block">
    460 
    461                 <?php while ( bp_members() ) : bp_the_member(); ?>
    462 
    463                     <div class="item-avatar">
    464                         <a href="<?php bp_member_permalink(); ?>" title="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a>
    465                     </div>
    466 
    467                 <?php endwhile; ?>
    468 
    469             </div>
    470 
    471         <?php else: ?>
    472 
    473             <div class="widget-error">
    474                 <?php esc_html_e( 'There are no recently active members', 'buddypress' ); ?>
    475             </div>
    476 
    477         <?php endif; ?>
    478 
    479         <?php echo $args['after_widget'];
    480     }
    481 
    482     /**
    483      * Update the Recently Active widget options.
    484      *
    485      * @param array $new_instance The new instance options.
    486      * @param array $old_instance The old instance options.
    487      * @return array $instance The parsed options to be saved.
    488      */
    489     public function update( $new_instance, $old_instance ) {
    490         $instance                = $old_instance;
    491         $instance['title']       = strip_tags( $new_instance['title'] );
    492         $instance['max_members'] = strip_tags( $new_instance['max_members'] );
    493 
    494         return $instance;
    495     }
    496 
    497     /**
    498      * Output the Recently Active widget options form.
    499      *
    500      * @param array $instance Widget instance settings.
    501      * @return void
    502      */
    503     public function form( $instance ) {
    504 
    505         // Get widget settings.
    506         $settings    = $this->parse_settings( $instance );
    507         $title       = strip_tags( $settings['title'] );
    508         $max_members = strip_tags( $settings['max_members'] ); ?>
    509 
    510         <p>
    511             <label for="<?php echo $this->get_field_id( 'title' ); ?>">
    512                 <?php esc_html_e( 'Title:', 'buddypress' ); ?>
    513                 <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%" />
    514             </label>
    515         </p>
    516 
    517         <p>
    518             <label for="<?php echo $this->get_field_id( 'max_members' ); ?>">
    519                 <?php esc_html_e( 'Max members to show:', 'buddypress' ); ?>
    520                 <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" />
    521             </label>
    522         </p>
    523 
    524     <?php
    525     }
    526 
    527     /**
    528      * Merge the widget settings into defaults array.
    529      *
    530      * @since 2.3.0
    531      *
    532      * @uses bp_parse_args() To merge widget settings into defaults.
    533      *
    534      * @param array $instance Widget instance settings.
    535      * @return array
    536      */
    537     public function parse_settings( $instance = array() ) {
    538         return bp_parse_args( $instance, array(
    539             'title'          => __( 'Recently Active Members', 'buddypress' ),
    540             'max_members'    => 15,
    541         ), 'recently_active_members_widget_settings' );
    542     }
    543 }
    54430
    54531/**
  • trunk/src/bp-members/classes/class-bp-core-members-template.php

    r10515 r10521  
    11<?php
    22/**
    3  * BuddyPress Member Template Tags.
    4  *
    5  * Functions that are safe to use inside your template files and themes.
     3 * BuddyPress Member Template loop class.
    64 *
    75 * @package BuddyPress
    86 * @subpackage Members
    9  * @since 1.5.0
    107 */
    118
    129// Exit if accessed directly.
    1310defined( 'ABSPATH' ) || exit;
    14 
    15 /**
    16  * Output the profile component slug.
    17  *
    18  * @since 2.4.0
    19  *
    20  * @uses bp_get_profile_slug()
    21  */
    22 function bp_profile_slug() {
    23     echo bp_get_profile_slug();
    24 }
    25     /**
    26      * Return the profile component slug.
    27      *
    28      * @since 2.4.0
    29      *
    30      * @return string
    31      */
    32     function bp_get_profile_slug() {
    33 
    34         /**
    35          * Filters the profile component slug.
    36          *
    37          * @since 2.4.0
    38          *
    39          * @param string $slug Profile component slug.
    40          */
    41         return apply_filters( 'bp_get_profile_slug', buddypress()->profile->slug );
    42     }
    43 
    44 /**
    45  * Output the members component slug.
    46  *
    47  * @since 1.5.0
    48  *
    49  * @uses bp_get_members_slug()
    50  */
    51 function bp_members_slug() {
    52     echo bp_get_members_slug();
    53 }
    54     /**
    55      * Return the members component slug.
    56      *
    57      * @since 1.5.0
    58      *
    59      * @return string
    60      */
    61     function bp_get_members_slug() {
    62 
    63         /**
    64          * Filters the Members component slug.
    65          *
    66          * @since 1.5.0
    67          *
    68          * @param string $slug Members component slug.
    69          */
    70         return apply_filters( 'bp_get_members_slug', buddypress()->members->slug );
    71     }
    72 
    73 /**
    74  * Output the members component root slug.
    75  *
    76  * @since 1.5.0
    77  *
    78  * @uses bp_get_members_root_slug()
    79  */
    80 function bp_members_root_slug() {
    81     echo bp_get_members_root_slug();
    82 }
    83     /**
    84      * Return the members component root slug.
    85      *
    86      * @since 1.5.0
    87      *
    88      * @return string
    89      */
    90     function bp_get_members_root_slug() {
    91 
    92         /**
    93          * Filters the Members component root slug.
    94          *
    95          * @since 1.5.0
    96          *
    97          * @param string $slug Members component root slug.
    98          */
    99         return apply_filters( 'bp_get_members_root_slug', buddypress()->members->root_slug );
    100     }
    101 
    102 /**
    103  * Output the member type base slug.
    104  *
    105  * @since 2.5.0
    106  */
    107 function bp_members_member_type_base() {
    108     echo esc_url( bp_get_members_member_type_base() );
    109 }
    110     /**
    111      * Get the member type base slug.
    112      *
    113      * The base slug is the string used as the base prefix when generating member type directory URLs.
    114      * For example, in example.com/members/type/foo/, 'foo' is the member type and 'type' is the
    115      * base slug.
    116      *
    117      * @since 2.5.0
    118      *
    119      * @return string
    120      */
    121     function bp_get_members_member_type_base() {
    122         /**
    123          * Filters the member type URL base.
    124          *
    125          * @since 2.3.0
    126          *
    127          * @param string $base
    128          */
    129         return apply_filters( 'bp_members_member_type_base', _x( 'type', 'member type URL base', 'buddypress' ) );
    130     }
    131 
    132 /**
    133  * Output member directory permalink.
    134  *
    135  * @since 1.5.0
    136  *
    137  * @uses bp_get_members_directory_permalink()
    138  */
    139 function bp_members_directory_permalink() {
    140     echo esc_url( bp_get_members_directory_permalink() );
    141 }
    142     /**
    143      * Return member directory permalink.
    144      *
    145      * @since 1.5.0
    146      *
    147      * @return string
    148      */
    149     function bp_get_members_directory_permalink() {
    150 
    151         /**
    152          * Filters the member directory permalink.
    153          *
    154          * @since 1.5.0
    155          *
    156          * @param string $value Members directory permalink.
    157          */
    158         return apply_filters( 'bp_get_members_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) );
    159     }
    160 
    161 /**
    162  * Output member type directory permalink.
    163  *
    164  * @since 2.5.0
    165  *
    166  * @uses bp_get_member_type_directory_permalink()
    167  *
    168  * @param string $member_type Optional. Member type.
    169  */
    170 function bp_member_type_directory_permalink( $member_type = '' ) {
    171     echo esc_url( bp_get_member_type_directory_permalink( $member_type ) );
    172 }
    173     /**
    174      * Return member type directory permalink.
    175      *
    176      * @since 2.5.0
    177      *
    178      * @param string $member_type Optional. Member type. Defaults to current member type.
    179      * @return string Member type directory URL on success, an empty string on failure.
    180      */
    181     function bp_get_member_type_directory_permalink( $member_type = '' ) {
    182 
    183         if ( $member_type ) {
    184             $_member_type = $member_type;
    185         } else {
    186             // Fall back on the current member type.
    187             $_member_type = bp_get_current_member_type();
    188         }
    189 
    190         $type = bp_get_member_type_object( $_member_type );
    191 
    192         // Bail when member type is not found or has no directory.
    193         if ( ! $type || ! $type->has_directory ) {
    194             return '';
    195         }
    196 
    197         /**
    198          * Filters the member type directory permalink.
    199          *
    200          * @since 2.5.0
    201          *
    202          * @param string $value       Member type directory permalink.
    203          * @param object $type        Member type object.
    204          * @param string $member_type Member type name, as passed to the function.
    205          */
    206         return apply_filters( 'bp_get_member_type_directory_permalink', trailingslashit( bp_get_members_directory_permalink() . bp_get_members_member_type_base() . '/' . $type->directory_slug ), $type, $member_type );
    207     }
    208 
    209 /**
    210  * Output the sign-up slug.
    211  *
    212  * @since 1.5.0
    213  *
    214  * @uses bp_get_signup_slug()
    215  */
    216 function bp_signup_slug() {
    217     echo bp_get_signup_slug();
    218 }
    219     /**
    220      * Return the sign-up slug.
    221      *
    222      * @since 1.5.0
    223      *
    224      * @return string
    225      */
    226     function bp_get_signup_slug() {
    227         $bp = buddypress();
    228 
    229         if ( !empty( $bp->pages->register->slug ) ) {
    230             $slug = $bp->pages->register->slug;
    231         } elseif ( defined( 'BP_REGISTER_SLUG' ) ) {
    232             $slug = BP_REGISTER_SLUG;
    233         } else {
    234             $slug = 'register';
    235         }
    236 
    237         /**
    238          * Filters the sign-up slug.
    239          *
    240          * @since 1.5.0
    241          *
    242          * @param string $slug Sign-up slug.
    243          */
    244         return apply_filters( 'bp_get_signup_slug', $slug );
    245     }
    246 
    247 /**
    248  * Output the activation slug.
    249  *
    250  * @since 1.5.0
    251  *
    252  * @uses bp_get_activate_slug()
    253  */
    254 function bp_activate_slug() {
    255     echo bp_get_activate_slug();
    256 }
    257     /**
    258      * Return the activation slug.
    259      *
    260      * @since 1.5.0
    261      *
    262      * @return string
    263      */
    264     function bp_get_activate_slug() {
    265         $bp = buddypress();
    266 
    267         if ( !empty( $bp->pages->activate->slug ) ) {
    268             $slug = $bp->pages->activate->slug;
    269         } elseif ( defined( 'BP_ACTIVATION_SLUG' ) ) {
    270             $slug = BP_ACTIVATION_SLUG;
    271         } else {
    272             $slug = 'activate';
    273         }
    274 
    275         /**
    276          * Filters the activation slug.
    277          *
    278          * @since 1.5.0
    279          *
    280          * @param string $slug Activation slug.
    281          */
    282         return apply_filters( 'bp_get_activate_slug', $slug );
    283     }
    28411
    28512/**
     
    548275    }
    549276}
    550 
    551 /**
    552  * Rewind the members and reset member index.
    553  */
    554 function bp_rewind_members() {
    555     global $members_template;
    556 
    557     return $members_template->rewind_members();
    558 }
    559 
    560 /**
    561  * Initialize the members loop.
    562  *
    563  * Based on the $args passed, bp_has_members() populates the $members_template
    564  * global, enabling the use of BuddyPress templates and template functions to
    565  * display a list of members.
    566  *
    567  * @global object $members_template {@link BP_Members_Template}
    568  *
    569  * @param array|string $args {
    570  *     Arguments for limiting the contents of the members loop. Most arguments
    571  *     are in the same format as {@link BP_User_Query}. However, because
    572  *     the format of the arguments accepted here differs in a number of ways,
    573  *     and because bp_has_members() determines some default arguments in a
    574  *     dynamic fashion, we list all accepted arguments here as well.
    575  *
    576  *     Arguments can be passed as an associative array, or as a URL query
    577  *     string (eg, 'user_id=4&per_page=3').
    578  *
    579  *     @type int                   $type                Sort order. Accepts 'active', 'random', 'newest', 'popular',
    580  *                                                      'online', 'alphabetical'. Default: 'active'.
    581  *     @type int|bool              $page                Page of results to display. Default: 1.
    582  *     @type int|bool              $per_page            Number of results per page. Default: 20.
    583  *     @type int|bool              $max                 Maximum number of results to return. Default: false (unlimited).
    584  *     @type string                $page_arg            The string used as a query parameter in pagination links.
    585  *                                                      Default: 'bpage'.
    586  *     @type array|int|string|bool $include             Limit results by a list of user IDs. Accepts an array, a
    587  *                                                      single integer, a comma-separated list of IDs, or false (to
    588  *                                                      disable this limiting). Accepts 'active', 'alphabetical',
    589  *                                                      'newest', or 'random'. Default: false.
    590  *     @type array|int|string|bool $exclude             Exclude users from results by ID. Accepts an array, a single
    591  *                                                      integer, a comma-separated list of IDs, or false (to disable
    592  *                                                      this limiting). Default: false.
    593  *     @type int                   $user_id             If provided, results are limited to the friends of the specified
    594  *                                                      user. When on a user's Friends page, defaults to the ID of the
    595  *                                                      displayed user. Otherwise defaults to 0.
    596  *     @type string|array          $member_type         Array or comma-separated list of member types to limit
    597  *                                                      results to.
    598  *     @type string|array          $member_type__in     Array or comma-separated list of member types to limit
    599  *                                                      results to.
    600  *     @type string|array          $member_type__not_in Array or comma-separated list of member types to exclude
    601  *                                                      from results.
    602  *     @type string                $search_terms        Limit results by a search term. Default: value of
    603  *                                                      `$_REQUEST['members_search']` or `$_REQUEST['s']`, if present.
    604  *                                                      Otherwise false.
    605  *     @type string                $meta_key            Limit results by the presence of a usermeta key.
    606  *                                                      Default: false.
    607  *     @type mixed                 $meta_value          When used with meta_key, limits results by the a matching
    608  *                                                      usermeta value. Default: false.
    609  *     @type bool                  $populate_extras     Whether to fetch optional data, such as friend counts.
    610  *                                                      Default: true.
    611  * }
    612  * @return bool Returns true when blogs are found, otherwise false.
    613  */
    614 function bp_has_members( $args = '' ) {
    615     global $members_template;
    616 
    617     // Default user ID.
    618     $user_id = 0;
    619 
    620     // User filtering.
    621     if ( bp_is_user_friends() && ! bp_is_user_friend_requests() ) {
    622         $user_id = bp_displayed_user_id();
    623     }
    624 
    625     $member_type = bp_get_current_member_type();
    626     if ( ! $member_type && ! empty( $_GET['member_type'] ) ) {
    627         if ( is_array( $_GET['member_type'] ) ) {
    628             $member_type = $_GET['member_type'];
    629         } else {
    630             // Can be a comma-separated list.
    631             $member_type = explode( ',', $_GET['member_type'] );
    632         }
    633     }
    634 
    635     $search_terms_default = null;
    636     $search_query_arg = bp_core_get_component_search_query_arg( 'members' );
    637     if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
    638         $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
    639     }
    640 
    641     // Type: active ( default ) | random | newest | popular | online | alphabetical.
    642     $r = bp_parse_args( $args, array(
    643         'type'                => 'active',
    644         'page'                => 1,
    645         'per_page'            => 20,
    646         'max'                 => false,
    647 
    648         'page_arg'            => 'upage',  // See https://buddypress.trac.wordpress.org/ticket/3679.
    649 
    650         'include'             => false,    // Pass a user_id or a list (comma-separated or array) of user_ids to only show these users.
    651         'exclude'             => false,    // Pass a user_id or a list (comma-separated or array) of user_ids to exclude these users.
    652 
    653         'user_id'             => $user_id, // Pass a user_id to only show friends of this user.
    654         'member_type'         => $member_type,
    655         'member_type__in'     => '',
    656         'member_type__not_in' => '',
    657         'search_terms'        => $search_terms_default,
    658 
    659         'meta_key'            => false,    // Only return users with this usermeta.
    660         'meta_value'          => false,    // Only return users where the usermeta value matches. Requires meta_key.
    661 
    662         'populate_extras'     => true      // Fetch usermeta? Friend count, last active etc.
    663     ), 'has_members' );
    664 
    665     // Pass a filter if ?s= is set.
    666     if ( is_null( $r['search_terms'] ) ) {
    667         if ( !empty( $_REQUEST['s'] ) ) {
    668             $r['search_terms'] = $_REQUEST['s'];
    669         } else {
    670             $r['search_terms'] = false;
    671         }
    672     }
    673 
    674     // Set per_page to max if max is larger than per_page.
    675     if ( !empty( $r['max'] ) && ( $r['per_page'] > $r['max'] ) ) {
    676         $r['per_page'] = $r['max'];
    677     }
    678 
    679     // Query for members and populate $members_template global.
    680     $members_template = new BP_Core_Members_Template(
    681         $r['type'],
    682         $r['page'],
    683         $r['per_page'],
    684         $r['max'],
    685         $r['user_id'],
    686         $r['search_terms'],
    687         $r['include'],
    688         $r['populate_extras'],
    689         $r['exclude'],
    690         $r['meta_key'],
    691         $r['meta_value'],
    692         $r['page_arg'],
    693         $r['member_type'],
    694         $r['member_type__in'],
    695         $r['member_type__not_in']
    696     );
    697 
    698     /**
    699      * Filters whether or not BuddyPress has members to iterate over.
    700      *
    701      * @since 1.2.4
    702      *
    703      * @param bool  $value            Whether or not there are members to iterate over.
    704      * @param array $members_template Populated $members_template global.
    705      */
    706     return apply_filters( 'bp_has_members', $members_template->has_members(), $members_template );
    707 }
    708 
    709 /**
    710  * Set up the current member inside the loop.
    711  *
    712  * @return object
    713  */
    714 function bp_the_member() {
    715     global $members_template;
    716     return $members_template->the_member();
    717 }
    718 
    719 /**
    720  * Check whether there are more members to iterate over.
    721  *
    722  * @return bool
    723  */
    724 function bp_members() {
    725     global $members_template;
    726     return $members_template->members();
    727 }
    728 
    729 /**
    730  * Output the members pagination count.
    731  */
    732 function bp_members_pagination_count() {
    733     echo bp_get_members_pagination_count();
    734 }
    735     /**
    736      * Generate the members pagination count.
    737      *
    738      * @return string
    739      */
    740     function bp_get_members_pagination_count() {
    741         global $members_template;
    742 
    743         if ( empty( $members_template->type ) )
    744             $members_template->type = '';
    745 
    746         $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
    747         $from_num  = bp_core_number_format( $start_num );
    748         $to_num    = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) );
    749         $total     = bp_core_number_format( $members_template->total_member_count );
    750 
    751         if ( 'active' == $members_template->type ) {
    752             if ( 1 == $members_template->total_member_count ) {
    753                 $pag = __( 'Viewing 1 active member', 'buddypress' );
    754             } else {
    755                 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s active member', 'Viewing %1$s - %2$s of %3$s active members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total );
    756             }
    757         } elseif ( 'popular' == $members_template->type ) {
    758             if ( 1 == $members_template->total_member_count ) {
    759                 $pag = __( 'Viewing 1 member with friends', 'buddypress' );
    760             } else {
    761                 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member with friends', 'Viewing %1$s - %2$s of %3$s members with friends', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total );
    762             }
    763         } elseif ( 'online' == $members_template->type ) {
    764             if ( 1 == $members_template->total_member_count ) {
    765                 $pag = __( 'Viewing 1 online member', 'buddypress' );
    766             } else {
    767                 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s online member', 'Viewing %1$s - %2$s of %3$s online members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total );
    768             }
    769         } else {
    770             if ( 1 == $members_template->total_member_count ) {
    771                 $pag = __( 'Viewing 1 member', 'buddypress' );
    772             } else {
    773                 $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member', 'Viewing %1$s - %2$s of %3$s members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total );
    774             }
    775         }
    776 
    777         /**
    778          * Filters the members pagination count.
    779          *
    780          * @since 1.5.0
    781          *
    782          * @param string $pag Pagination count string.
    783          */
    784         return apply_filters( 'bp_members_pagination_count', $pag );
    785     }
    786 
    787 /**
    788  * Output the members pagination links.
    789  */
    790 function bp_members_pagination_links() {
    791     echo bp_get_members_pagination_links();
    792 }
    793     /**
    794      * Fetch the members pagination links.
    795      *
    796      * @return string
    797      */
    798     function bp_get_members_pagination_links() {
    799         global $members_template;
    800 
    801         /**
    802          * Filters the members pagination link.
    803          *
    804          * @since 1.2.0
    805          *
    806          * @param string $pag_links HTML markup for pagination links.
    807          */
    808         return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links );
    809     }
    810 
    811 /**
    812  * Output the ID of the current member in the loop.
    813  *
    814  * @uses bp_get_member_user_id()
    815  */
    816 function bp_member_user_id() {
    817     echo bp_get_member_user_id();
    818 }
    819     /**
    820      * Get the ID of the current member in the loop.
    821      *
    822      * @return string Member ID.
    823      */
    824     function bp_get_member_user_id() {
    825         global $members_template;
    826         $member_id = isset( $members_template->member->id ) ? (int) $members_template->member->id : false;
    827 
    828         /**
    829          * Filters the ID of the current member in the loop.
    830          *
    831          * @since 1.2.0
    832          *
    833          * @param int $member_id ID of the member being iterated over.
    834          */
    835         return apply_filters( 'bp_get_member_user_id', $member_id );
    836     }
    837 
    838 /**
    839  * Output the row class of the current member in the loop.
    840  *
    841  * @since 1.7.0
    842  *
    843  * @param array $classes Array of custom classes.
    844  */
    845 function bp_member_class( $classes = array() ) {
    846     echo bp_get_member_class( $classes );
    847 }
    848     /**
    849      * Return the row class of the current member in the loop.
    850      *
    851      * @since 1.7.0
    852      *
    853      * @param array $classes Array of custom classes.
    854      *
    855      * @return string Row class of the member
    856      */
    857     function bp_get_member_class( $classes = array() ) {
    858         global $members_template;
    859 
    860         // Add even/odd classes, but only if there's more than 1 member.
    861         if ( $members_template->member_count > 1 ) {
    862             $pos_in_loop = (int) $members_template->current_member;
    863             $classes[]   = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
    864 
    865         // If we've only one member in the loop, don't bother with odd and even.
    866         } else {
    867             $classes[] = 'bp-single-member';
    868         }
    869 
    870         // Maybe add 'is-online' class.
    871         if ( ! empty( $members_template->member->last_activity ) ) {
    872 
    873             // Calculate some times.
    874             $current_time  = strtotime( bp_core_current_time() );
    875             $last_activity = strtotime( $members_template->member->last_activity );
    876             $still_online  = strtotime( '+5 minutes', $last_activity );
    877 
    878             // Has the user been active recently?
    879             if ( $current_time <= $still_online ) {
    880                 $classes[] = 'is-online';
    881             }
    882         }
    883 
    884         // Add current user class.
    885         if ( bp_loggedin_user_id() === (int) $members_template->member->id ) {
    886             $classes[] = 'is-current-user';
    887         }
    888 
    889         /**
    890          * Filters the determined classes to add to the HTML element.
    891          *
    892          * @since 1.7.0
    893          *
    894          * @param string $classes Classes to be added to the HTML element.
    895          */
    896         $classes = apply_filters( 'bp_get_member_class', $classes );
    897         $classes = array_merge( $classes, array() );
    898         $retval  = 'class="' . join( ' ', $classes ) . '"';
    899 
    900         return $retval;
    901     }
    902 
    903 /**
    904  * Output nicename of current member in the loop.
    905  */
    906 function bp_member_user_nicename() {
    907     echo bp_get_member_user_nicename();
    908 }
    909     /**
    910      * Get the nicename of the current member in the loop.
    911      *
    912      * @return string Members nicename.
    913      */
    914     function bp_get_member_user_nicename() {
    915         global $members_template;
    916 
    917         /**
    918          * Filters the nicename of the current member in the loop.
    919          *
    920          * @since 1.2.5
    921          *
    922          * @param string $user_nicename Nicename for the current member.
    923          */
    924         return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename );
    925     }
    926 
    927 /**
    928  * Output login for current member in the loop.
    929  */
    930 function bp_member_user_login() {
    931     echo bp_get_member_user_login();
    932 }
    933     /**
    934      * Get the login of the current member in the loop.
    935      *
    936      * @return string Member's login.
    937      */
    938     function bp_get_member_user_login() {
    939         global $members_template;
    940 
    941         /**
    942          * Filters the login of the current member in the loop.
    943          *
    944          * @since 1.2.5
    945          *
    946          * @param string $user_login Login for the current member.
    947          */
    948         return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login );
    949     }
    950 
    951 /**
    952  * Output the email address for the current member in the loop.
    953  */
    954 function bp_member_user_email() {
    955     echo bp_get_member_user_email();
    956 }
    957     /**
    958      * Get the email address of the current member in the loop.
    959      *
    960      * @return string Member's email address.
    961      */
    962     function bp_get_member_user_email() {
    963         global $members_template;
    964 
    965         /**
    966          * Filters the email address of the current member in the loop.
    967          *
    968          * @since 1.2.5
    969          *
    970          * @param string $user_email Email address for the current member.
    971          */
    972         return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email );
    973     }
    974 
    975 /**
    976  * Check whether the current member in the loop is the logged-in user.
    977  *
    978  * @return bool
    979  */
    980 function bp_member_is_loggedin_user() {
    981     global $members_template;
    982 
    983     /**
    984      * Filters whether the current member in the loop is the logged-in user.
    985      *
    986      * @since 1.2.5
    987      *
    988      * @param bool $value Whether current member in the loop is logged in.
    989      */
    990     return apply_filters( 'bp_member_is_loggedin_user', bp_loggedin_user_id() == $members_template->member->id ? true : false );
    991 }
    992 
    993 /**
    994  * Output a member's avatar.
    995  *
    996  * @see bp_get_member_avatar() for description of arguments.
    997  *
    998  * @param array|string $args See {@link bp_get_member_avatar()}.
    999  */
    1000 function bp_member_avatar( $args = '' ) {
    1001 
    1002     /**
    1003      * Filters a members avatar.
    1004      *
    1005      * @since 1.2.0
    1006      *
    1007      * @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg.
    1008      */
    1009     echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
    1010 }
    1011     /**
    1012      * Get a member's avatar.
    1013      *
    1014      * @see bp_core_fetch_avatar() For a description of arguments and
    1015      *      return values.
    1016      *
    1017      * @param array|string $args  {
    1018      *     Arguments are listed here with an explanation of their defaults.
    1019      *     For more information about the arguments, see
    1020      *     {@link bp_core_fetch_avatar()}.
    1021      *     @type string   $alt     Default: 'Profile picture of [user name]'.
    1022      *     @type string   $class   Default: 'avatar'.
    1023      *     @type string   $type    Default: 'thumb'.
    1024      *     @type int|bool $width   Default: false.
    1025      *     @type int|bool $height  Default: false.
    1026      *     @type bool     $id      Currently unused.
    1027      *     @type bool     $no_grav Default: false.
    1028      * }
    1029      * @return string User avatar string.
    1030      */
    1031     function bp_get_member_avatar( $args = '' ) {
    1032         global $members_template;
    1033 
    1034         $fullname = !empty( $members_template->member->fullname ) ? $members_template->member->fullname : $members_template->member->display_name;
    1035 
    1036         $defaults = array(
    1037             'type'   => 'thumb',
    1038             'width'  => false,
    1039             'height' => false,
    1040             'class'  => 'avatar',
    1041             'id'     => false,
    1042             'alt'    => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname )
    1043         );
    1044 
    1045         $r = wp_parse_args( $args, $defaults );
    1046         extract( $r, EXTR_SKIP );
    1047 
    1048         /**
    1049          * Filters a members avatar.
    1050          *
    1051          * @since 1.2.0
    1052          *
    1053          * @param string $value Formatted HTML <img> element, or raw avatar URL based on $html arg.
    1054          */
    1055         return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
    1056     }
    1057 
    1058 /**
    1059  * Output the permalink for the current member in the loop.
    1060  */
    1061 function bp_member_permalink() {
    1062     echo bp_get_member_permalink();
    1063 }
    1064     /**
    1065      * Get the permalink for the current member in the loop.
    1066      *
    1067      * @return string
    1068      */
    1069     function bp_get_member_permalink() {
    1070         global $members_template;
    1071 
    1072         /**
    1073          * Filters the permalink for the current member in the loop.
    1074          *
    1075          * @since 1.2.0
    1076          *
    1077          * @param string $value Permalink for the current member in the loop.
    1078          */
    1079         return apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) );
    1080     }
    1081 
    1082     /**
    1083      * Alias of {@link bp_member_permalink()}.
    1084      */
    1085     function bp_member_link() { echo bp_get_member_permalink(); }
    1086 
    1087     /**
    1088      * Alias of {@link bp_get_member_permalink()}.
    1089      */
    1090     function bp_get_member_link() { return bp_get_member_permalink(); }
    1091 
    1092 /**
    1093  * Output display name of current member in the loop.
    1094  */
    1095 function bp_member_name() {
    1096 
    1097     /**
    1098      * Filters the display name of current member in the loop.
    1099      *
    1100      * @since 1.2.0
    1101      *
    1102      * @param string $value Display name for current member.
    1103      */
    1104     echo apply_filters( 'bp_member_name', bp_get_member_name() );
    1105 }
    1106     /**
    1107      * Get the display name of the current member in the loop.
    1108      *
    1109      * Full name is, by default, pulled from xprofile's Full Name field.
    1110      * When this field is empty, we try to get an alternative name from the
    1111      * WP users table, in the following order of preference: display_name,
    1112      * user_nicename, user_login.
    1113      *
    1114      * @return string The user's fullname for display.
    1115      */
    1116     function bp_get_member_name() {
    1117         global $members_template;
    1118 
    1119         // Generally, this only fires when xprofile is disabled.
    1120         if ( empty( $members_template->member->fullname ) ) {
    1121             // Our order of preference for alternative fullnames.
    1122             $name_stack = array(
    1123                 'display_name',
    1124                 'user_nicename',
    1125                 'user_login'
    1126             );
    1127 
    1128             foreach ( $name_stack as $source ) {
    1129                 if ( !empty( $members_template->member->{$source} ) ) {
    1130                     // When a value is found, set it as fullname and be done with it.
    1131                     $members_template->member->fullname = $members_template->member->{$source};
    1132                     break;
    1133                 }
    1134             }
    1135         }
    1136 
    1137         /**
    1138          * Filters the display name of current member in the loop.
    1139          *
    1140          * @since 1.2.0
    1141          *
    1142          * @param string $fullname Display name for current member.
    1143          */
    1144         return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
    1145     }
    1146     add_filter( 'bp_get_member_name', 'wp_filter_kses' );
    1147     add_filter( 'bp_get_member_name', 'stripslashes'   );
    1148     add_filter( 'bp_get_member_name', 'strip_tags'     );
    1149     add_filter( 'bp_get_member_name', 'esc_html'       );
    1150 
    1151 /**
    1152  * Output the current member's last active time.
    1153  *
    1154  * @param array $args See {@link bp_get_member_last_active()}.
    1155  */
    1156 function bp_member_last_active( $args = array() ) {
    1157     echo bp_get_member_last_active( $args );
    1158 }
    1159     /**
    1160      * Return the current member's last active time.
    1161      *
    1162      * @param array $args {
    1163      *     Array of optional arguments.
    1164      *     @type mixed $active_format If true, formatted "active 5 minutes
    1165      *                                ago". If false, formatted "5 minutes ago".
    1166      *                                If string, should be sprintf'able like
    1167      *                                'last seen %s ago'.
    1168      * }
    1169      * @return string
    1170      */
    1171     function bp_get_member_last_active( $args = array() ) {
    1172         global $members_template;
    1173 
    1174         // Parse the activity format.
    1175         $r = bp_parse_args( $args, array(
    1176             'active_format' => true
    1177         ) );
    1178 
    1179         // Backwards compatibility for anyone forcing a 'true' active_format.
    1180         if ( true === $r['active_format'] ) {
    1181             $r['active_format'] = __( 'active %s', 'buddypress' );
    1182         }
    1183 
    1184         // Member has logged in at least one time.
    1185         if ( isset( $members_template->member->last_activity ) ) {
    1186 
    1187             // Backwards compatibility for pre 1.5 'ago' strings.
    1188             $last_activity = ! empty( $r['active_format'] )
    1189                 ? bp_core_get_last_activity( $members_template->member->last_activity, $r['active_format'] )
    1190                 : bp_core_time_since( $members_template->member->last_activity );
    1191 
    1192         // Member has never logged in or been active.
    1193         } else {
    1194             $last_activity = __( 'Never active', 'buddypress' );
    1195         }
    1196 
    1197         /**
    1198          * Filters the current members last active time.
    1199          *
    1200          * @since 1.2.0
    1201          *
    1202          * @param string $last_activity Formatted time since last activity.
    1203          * @param array  $r             Array of parsed arguments for query.
    1204          */
    1205         return apply_filters( 'bp_member_last_active', $last_activity, $r );
    1206     }
    1207 
    1208 /**
    1209  * Output the latest update of the current member in the loop.
    1210  *
    1211  * @param array|string $args Array of arguments for latest update.
    1212  */
    1213 function bp_member_latest_update( $args = '' ) {
    1214     echo bp_get_member_latest_update( $args );
    1215 }
    1216     /**
    1217      * Get the latest update from the current member in the loop.
    1218      *
    1219      * @param array|string $args {
    1220      *     Array of optional arguments.
    1221      *     @type int  $length    Truncation length. Default: 225.
    1222      *     @type bool $view_link Whether to provide a 'View' link for
    1223      *                           truncated entries. Default: false.
    1224      * }
    1225      * @return string
    1226      */
    1227     function bp_get_member_latest_update( $args = '' ) {
    1228         global $members_template;
    1229 
    1230         $defaults = array(
    1231             'length'    => 225,
    1232             'view_link' => true
    1233         );
    1234 
    1235         $r = wp_parse_args( $args, $defaults );
    1236         extract( $r );
    1237 
    1238         if ( !bp_is_active( 'activity' ) || empty( $members_template->member->latest_update ) || !$update = maybe_unserialize( $members_template->member->latest_update ) )
    1239             return false;
    1240 
    1241         /**
    1242          * Filters the excerpt of the latest update for current member in the loop.
    1243          *
    1244          * @since 1.2.5
    1245          *
    1246          * @param string $value Excerpt of the latest update for current member in the loop.
    1247          */
    1248         $update_content = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], $length ) ) ) );
    1249 
    1250         $update_content = sprintf( _x( '- &quot;%s&quot;', 'member latest update in member directory', 'buddypress' ), $update_content );
    1251 
    1252         // If $view_link is true and the text returned by bp_create_excerpt() is different from the original text (ie it's
    1253         // been truncated), add the "View" link.
    1254         if ( $view_link && ( $update_content != $update['content'] ) ) {
    1255             $view = __( 'View', 'buddypress' );
    1256 
    1257             $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
    1258         }
    1259 
    1260         /**
    1261          * Filters the latest update from the current member in the loop.
    1262          *
    1263          * @since 1.2.0
    1264          *
    1265          * @param string $update_content Formatted latest update for current member.
    1266          */
    1267         return apply_filters( 'bp_get_member_latest_update', $update_content );
    1268     }
    1269 
    1270 /**
    1271  * Output a piece of user profile data.
    1272  *
    1273  * @see bp_get_member_profile_data() for a description of params.
    1274  *
    1275  * @param array|string $args See {@link bp_get_member_profile_data()}.
    1276  */
    1277 function bp_member_profile_data( $args = '' ) {
    1278     echo bp_get_member_profile_data( $args );
    1279 }
    1280     /**
    1281      * Get a piece of user profile data.
    1282      *
    1283      * When used in a bp_has_members() loop, this function will attempt
    1284      * to fetch profile data cached in the template global. It is also safe
    1285      * to use outside of the loop.
    1286      *
    1287      * @param array|string $args {
    1288      *     Array of config parameters.
    1289      *     @type string $field   Name of the profile field.
    1290      *     @type int    $user_id ID of the user whose data is being fetched.
    1291      *                           Defaults to the current member in the loop, or if not
    1292      *                           present, to the currently displayed user.
    1293      * }
    1294      * @return string|bool Profile data if found, otherwise false.
    1295      */
    1296     function bp_get_member_profile_data( $args = '' ) {
    1297         global $members_template;
    1298 
    1299         if ( ! bp_is_active( 'xprofile' ) ) {
    1300             return false;
    1301         }
    1302 
    1303         // Declare local variables.
    1304         $data = false;
    1305 
    1306         // Guess at default $user_id.
    1307         $default_user_id = 0;
    1308         if ( ! empty( $members_template->member->id ) ) {
    1309             $default_user_id = $members_template->member->id;
    1310         } elseif ( bp_displayed_user_id() ) {
    1311             $default_user_id = bp_displayed_user_id();
    1312         }
    1313 
    1314         $defaults = array(
    1315             'field'   => false,
    1316             'user_id' => $default_user_id,
    1317         );
    1318 
    1319         $r = wp_parse_args( $args, $defaults );
    1320 
    1321         // If we're in a members loop, get the data from the global.
    1322         if ( ! empty( $members_template->member->profile_data ) ) {
    1323             $profile_data = $members_template->member->profile_data;
    1324         }
    1325 
    1326         // Otherwise query for the data.
    1327         if ( empty( $profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) ) {
    1328             $profile_data = BP_XProfile_ProfileData::get_all_for_user( $r['user_id'] );
    1329         }
    1330 
    1331         // If we're in the members loop, but the profile data has not
    1332         // been loaded into the global, cache it there for later use.
    1333         if ( ! empty( $members_template->member ) && empty( $members_template->member->profile_data ) ) {
    1334             $members_template->member->profile_data = $profile_data;
    1335         }
    1336 
    1337         // Get the data for the specific field requested.
    1338         if ( ! empty( $profile_data ) && ! empty( $profile_data[ $r['field'] ]['field_type'] ) && ! empty( $profile_data[ $r['field'] ]['field_data'] ) ) {
    1339             $data = xprofile_format_profile_field( $profile_data[ $r['field'] ]['field_type'], $profile_data[ $r['field'] ]['field_data'] );
    1340         }
    1341 
    1342         /**
    1343          * Filters resulting piece of member profile data.
    1344          *
    1345          * @since 1.2.0
    1346          *
    1347          * @param string|bool $data Profile data if found, otherwise false.
    1348          */
    1349         return apply_filters( 'bp_get_member_profile_data', $data );
    1350     }
    1351 
    1352 /**
    1353  * Output the 'registered [x days ago]' string for the current member.
    1354  */
    1355 function bp_member_registered() {
    1356     echo bp_get_member_registered();
    1357 }
    1358     /**
    1359      * Get the 'registered [x days ago]' string for the current member.
    1360      *
    1361      * @return string
    1362      */
    1363     function bp_get_member_registered() {
    1364         global $members_template;
    1365 
    1366         $registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, _x( 'registered %s', 'Records the timestamp that the user registered into the activity stream', 'buddypress' ) ) );
    1367 
    1368         /**
    1369          * Filters the 'registered [x days ago]' string for the current member.
    1370          *
    1371          * @since 2.1.0
    1372          *
    1373          * @param string $registered The 'registered [x days ago]' string.
    1374          */
    1375         return apply_filters( 'bp_member_registered', $registered );
    1376     }
    1377 
    1378 /**
    1379  * Output a random piece of profile data for the current member in the loop.
    1380  */
    1381 function bp_member_random_profile_data() {
    1382     global $members_template;
    1383 
    1384     if ( bp_is_active( 'xprofile' ) ) { ?>
    1385         <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
    1386             <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
    1387             <?php echo wp_filter_kses( $random_data[0]->value ) ?>
    1388     <?php }
    1389 }
    1390 
    1391 /**
    1392  * Output hidden input for preserving member search params on form submit.
    1393  */
    1394 function bp_member_hidden_fields() {
    1395     $query_arg = bp_core_get_component_search_query_arg( 'members' );
    1396 
    1397     if ( isset( $_REQUEST[ $query_arg ] ) ) {
    1398         echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST[ $query_arg ] ) . '" name="search_terms" />';
    1399     }
    1400 
    1401     if ( isset( $_REQUEST['letter'] ) ) {
    1402         echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
    1403     }
    1404 
    1405     if ( isset( $_REQUEST['members_search'] ) ) {
    1406         echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />';
    1407     }
    1408 }
    1409 
    1410 /**
    1411  * Output the Members directory search form.
    1412  */
    1413 function bp_directory_members_search_form() {
    1414 
    1415     $query_arg = bp_core_get_component_search_query_arg( 'members' );
    1416 
    1417     if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
    1418         $search_value = stripslashes( $_REQUEST[ $query_arg ] );
    1419     } else {
    1420         $search_value = bp_get_search_default_text( 'members' );
    1421     }
    1422 
    1423     $search_form_html = '<form action="" method="get" id="search-members-form">
    1424         <label for="members_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="members_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
    1425         <input type="submit" id="members_search_submit" name="members_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
    1426     </form>';
    1427 
    1428     /**
    1429      * Filters the Members component search form.
    1430      *
    1431      * @since 1.9.0
    1432      *
    1433      * @param string $search_form_html HTML markup for the member search form.
    1434      */
    1435     echo apply_filters( 'bp_directory_members_search_form', $search_form_html );
    1436 }
    1437 
    1438 /**
    1439  * Output the total member count.
    1440  */
    1441 function bp_total_site_member_count() {
    1442     echo bp_get_total_site_member_count();
    1443 }
    1444     /**
    1445      * Get the total site member count.
    1446      *
    1447      * @return int
    1448      */
    1449     function bp_get_total_site_member_count() {
    1450 
    1451         /**
    1452          * Filters the total site member count.
    1453          *
    1454          * @since 1.2.0
    1455          *
    1456          * @param int $value Number-formatted total site member count.
    1457          */
    1458         return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) );
    1459     }
    1460 
    1461 /** Navigation and other misc template tags ***********************************/
    1462 
    1463 /**
    1464  * Render the navigation markup for the logged-in user.
    1465  *
    1466  * Each component adds to this navigation array within its own
    1467  * [component_name]setup_nav() function.
    1468  *
    1469  * This navigation array is the top level navigation, so it contains items such as:
    1470  *      [Blog, Profile, Messages, Groups, Friends] ...
    1471  *
    1472  * The function will also analyze the current component the user is in, to
    1473  * determine whether or not to highlight a particular nav item.
    1474  *
    1475  * @todo Move to a back-compat file?
    1476  * @deprecated Does not seem to be called anywhere in BP core.
    1477  */
    1478 function bp_get_loggedin_user_nav() {
    1479     $bp = buddypress();
    1480 
    1481     // Loop through each navigation item.
    1482     foreach( (array) $bp->bp_nav as $nav_item ) {
    1483 
    1484         $selected = '';
    1485 
    1486         // If the current component matches the nav item id, then add a highlight CSS class.
    1487         if ( !bp_is_directory() && !empty( $bp->active_components[bp_current_component()] ) && $bp->active_components[bp_current_component()] == $nav_item['css_id'] ) {
    1488             $selected = ' class="current selected"';
    1489         }
    1490 
    1491         // If we are viewing another person (current_userid does not equal
    1492         // loggedin_user->id then check to see if the two users are friends.
    1493         // if they are, add a highlight CSS class to the friends nav item
    1494         // if it exists.
    1495         if ( !bp_is_my_profile() && bp_displayed_user_id() ) {
    1496             $selected = '';
    1497 
    1498             if ( bp_is_active( 'friends' ) ) {
    1499                 if ( $nav_item['css_id'] == $bp->friends->id ) {
    1500                     if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) {
    1501                         $selected = ' class="current selected"';
    1502                     }
    1503                 }
    1504             }
    1505         }
    1506 
    1507         // Echo out the final list item.
    1508         echo apply_filters_ref_array( 'bp_get_loggedin_user_nav_' . $nav_item['css_id'], array( '<li id="li-nav-' . $nav_item['css_id'] . '" ' . $selected . '><a id="my-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a></li>', &$nav_item ) );
    1509     }
    1510 
    1511     // Always add a log out list item to the end of the navigation.
    1512     $logout_link = '<li><a id="wp-logout" href="' .  wp_logout_url( bp_get_root_domain() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
    1513 
    1514     echo apply_filters( 'bp_logout_nav_link', $logout_link );
    1515 }
    1516 
    1517 /**
    1518  * Render the navigation markup for the displayed user.
    1519  */
    1520 function bp_get_displayed_user_nav() {
    1521     $bp = buddypress();
    1522 
    1523     foreach ( (array) $bp->bp_nav as $user_nav_item ) {
    1524         if ( empty( $user_nav_item['show_for_displayed_user'] ) && !bp_is_my_profile() )
    1525             continue;
    1526 
    1527         $selected = '';
    1528         if ( bp_is_current_component( $user_nav_item['slug'] ) ) {
    1529             $selected = ' class="current selected"';
    1530         }
    1531 
    1532         if ( bp_loggedin_user_domain() ) {
    1533             $link = str_replace( bp_loggedin_user_domain(), bp_displayed_user_domain(), $user_nav_item['link'] );
    1534         } else {
    1535             $link = trailingslashit( bp_displayed_user_domain() . $user_nav_item['link'] );
    1536         }
    1537 
    1538         /**
    1539          * Filters the navigation markup for the displayed user.
    1540          *
    1541          * This is a dynamic filter that is dependent on the navigation tab component being rendered.
    1542          *
    1543          * @since 1.1.0
    1544          *
    1545          * @param string $value         Markup for the tab list item including link.
    1546          * @param array  $user_nav_item Array holding parts used to construct tab list item.
    1547          *                              Passed by reference.
    1548          */
    1549         echo apply_filters_ref_array( 'bp_get_displayed_user_nav_' . $user_nav_item['css_id'], array( '<li id="' . $user_nav_item['css_id'] . '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item['css_id'] . '" href="' . $link . '">' . $user_nav_item['name'] . '</a></li>', &$user_nav_item ) );
    1550     }
    1551 }
    1552 
    1553 /** Cover image ***************************************************************/
    1554 
    1555 /**
    1556  * Should we use the cover image header
    1557  *
    1558  * @since 2.4.0
    1559  *
    1560  * @return bool True if the displayed user has a cover image,
    1561  *              False otherwise
    1562  */
    1563 function bp_displayed_user_use_cover_image_header() {
    1564     return (bool) bp_is_active( 'xprofile', 'cover_image' ) && ! bp_disable_cover_image_uploads() && bp_attachments_is_wp_version_supported();
    1565 }
    1566 
    1567 /** Avatars *******************************************************************/
    1568 
    1569 /**
    1570  * Output the logged-in user's avatar.
    1571  *
    1572  * @see bp_get_loggedin_user_avatar() for a description of params.
    1573  *
    1574  * @param array|string $args Array of arguments for logged in user avatar.
    1575  */
    1576 function bp_loggedin_user_avatar( $args = '' ) {
    1577     echo bp_get_loggedin_user_avatar( $args );
    1578 }
    1579     /**
    1580      * Get the logged-in user's avatar.
    1581      *
    1582      * @see bp_core_fetch_avatar() For a description of arguments and
    1583      *      return values.
    1584      *
    1585      * @param array|string $args  {
    1586      *     Arguments are listed here with an explanation of their defaults.
    1587      *     For more information about the arguments, see
    1588      *     {@link bp_core_fetch_avatar()}.
    1589      *     @type string   $alt    Default: 'Profile picture of [user name]'.
    1590      *     @type bool     $html   Default: true.
    1591      *     @type string   $type   Default: 'thumb'.
    1592      *     @type int|bool $width  Default: false.
    1593      *     @type int|bool $height Default: false.
    1594      * }
    1595      * @return string User avatar string.
    1596      */
    1597     function bp_get_loggedin_user_avatar( $args = '' ) {
    1598 
    1599         $r = wp_parse_args( $args, array(
    1600             'item_id' => bp_loggedin_user_id(),
    1601             'type'    => 'thumb',
    1602             'width'   => false,
    1603             'height'  => false,
    1604             'html'    => true,
    1605             'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_loggedin_user_fullname() )
    1606         ) );
    1607 
    1608         /**
    1609          * Filters the logged in user's avatar.
    1610          *
    1611          * @since 1.1.0
    1612          *
    1613          * @param string $value User avatar string.
    1614          */
    1615         return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( $r ), $r, $args );
    1616     }
    1617 
    1618 /**
    1619  * Output the displayed user's avatar.
    1620  *
    1621  * @see bp_get_displayed_user_avatar() for a description of params.
    1622  *
    1623  * @param array|string $args Array of arguments for displayed user avatar.
    1624  */
    1625 function bp_displayed_user_avatar( $args = '' ) {
    1626     echo bp_get_displayed_user_avatar( $args );
    1627 }
    1628     /**
    1629      * Get the displayed user's avatar.
    1630      *
    1631      * @see bp_core_fetch_avatar() For a description of arguments and
    1632      *      return values.
    1633      *
    1634      * @param array|string $args  {
    1635      *     Arguments are listed here with an explanation of their defaults.
    1636      *     For more information about the arguments, see
    1637      *     {@link bp_core_fetch_avatar()}.
    1638      *     @type string   $alt    Default: 'Profile picture of [user name]'.
    1639      *     @type bool     $html   Default: true.
    1640      *     @type string   $type   Default: 'thumb'.
    1641      *     @type int|bool $width  Default: false.
    1642      *     @type int|bool $height Default: false.
    1643      * }
    1644      * @return string User avatar string.
    1645      */
    1646     function bp_get_displayed_user_avatar( $args = '' ) {
    1647 
    1648         $r = wp_parse_args( $args, array(
    1649             'item_id' => bp_displayed_user_id(),
    1650             'type'    => 'thumb',
    1651             'width'   => false,
    1652             'height'  => false,
    1653             'html'    => true,
    1654             'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
    1655         ) );
    1656 
    1657         /**
    1658          * Filters the displayed user's avatar.
    1659          *
    1660          * @since 1.1.0
    1661          *
    1662          * @param string $value User avatar string.
    1663          */
    1664         return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( $r ), $r, $args );
    1665     }
    1666 
    1667 /**
    1668  * Output the email address of the displayed user.
    1669  */
    1670 function bp_displayed_user_email() {
    1671     echo bp_get_displayed_user_email();
    1672 }
    1673     /**
    1674      * Get the email address of the displayed user.
    1675      *
    1676      * @return string
    1677      */
    1678     function bp_get_displayed_user_email() {
    1679         $bp = buddypress();
    1680 
    1681         // If displayed user exists, return email address.
    1682         if ( isset( $bp->displayed_user->userdata->user_email ) )
    1683             $retval = $bp->displayed_user->userdata->user_email;
    1684         else
    1685             $retval = '';
    1686 
    1687         /**
    1688          * Filters the email address of the displayed user.
    1689          *
    1690          * @since 1.5.0
    1691          *
    1692          * @param string $retval Email address for displayed user.
    1693          */
    1694         return apply_filters( 'bp_get_displayed_user_email', esc_attr( $retval ) );
    1695     }
    1696 
    1697 /**
    1698  * Output the "active [x days ago]" string for a user.
    1699  *
    1700  * @see bp_get_last_activity() for a description of parameters.
    1701  *
    1702  * @param int $user_id See {@link bp_get_last_activity()}.
    1703  */
    1704 function bp_last_activity( $user_id = 0 ) {
    1705 
    1706     /**
    1707      * Filters the 'active [x days ago]' string for a user.
    1708      *
    1709      * @since 1.0.0
    1710      *
    1711      * @param string $value Formatted 'active [x days ago]' string.
    1712      */
    1713     echo apply_filters( 'bp_last_activity', bp_get_last_activity( $user_id ) );
    1714 }
    1715     /**
    1716      * Get the "active [x days ago]" string for a user.
    1717      *
    1718      * @param int $user_id ID of the user. Default: displayed user ID.
    1719      * @return string
    1720      */
    1721     function bp_get_last_activity( $user_id = 0 ) {
    1722 
    1723         if ( empty( $user_id ) )
    1724             $user_id = bp_displayed_user_id();
    1725 
    1726         $last_activity = bp_core_get_last_activity( bp_get_user_last_activity( $user_id ), __('active %s', 'buddypress') );
    1727 
    1728         /**
    1729          * Filters the 'active [x days ago]' string for a user.
    1730          *
    1731          * @since 1.5.0
    1732          *
    1733          * @param string $value Formatted 'active [x days ago]' string.
    1734          */
    1735         return apply_filters( 'bp_get_last_activity', $last_activity );
    1736     }
    1737 
    1738 /**
    1739  * Output the calculated first name of the displayed or logged-in user.
    1740  */
    1741 function bp_user_firstname() {
    1742     echo bp_get_user_firstname();
    1743 }
    1744     /**
    1745      * Output the first name of a user.
    1746      *
    1747      * Simply takes all the characters before the first space in a name.
    1748      *
    1749      * @param string|bool $name Full name to use when generating first name.
    1750      *                          Defaults to displayed user's first name, or to
    1751      *                          logged-in user's first name if it's unavailable.
    1752      * @return string
    1753      */
    1754     function bp_get_user_firstname( $name = false ) {
    1755 
    1756         // Try to get displayed user.
    1757         if ( empty( $name ) )
    1758             $name = bp_get_displayed_user_fullname();
    1759 
    1760         // Fall back on logged in user.
    1761         if ( empty( $name ) )
    1762             $name = bp_get_loggedin_user_fullname();
    1763 
    1764         $fullname = (array) explode( ' ', $name );
    1765 
    1766         /**
    1767          * Filters the first name of a user.
    1768          *
    1769          * @since 1.2.0
    1770          *
    1771          * @param string $value    First name of user.
    1772          * @param string $fullname Full name of user.
    1773          */
    1774         return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
    1775     }
    1776 
    1777 /**
    1778  * Output the link for the logged-in user's profile.
    1779  */
    1780 function bp_loggedin_user_link() {
    1781     echo bp_get_loggedin_user_link();
    1782 }
    1783     /**
    1784      * Get the link for the logged-in user's profile.
    1785      *
    1786      * @return string
    1787      */
    1788     function bp_get_loggedin_user_link() {
    1789 
    1790         /**
    1791          * Filters the link for the logged-in user's profile.
    1792          *
    1793          * @since 1.2.4
    1794          *
    1795          * @param string $value Link for the logged-in user's profile.
    1796          */
    1797         return apply_filters( 'bp_get_loggedin_user_link', bp_loggedin_user_domain() );
    1798     }
    1799 
    1800 /**
    1801  * Output the link for the displayed user's profile.
    1802  */
    1803 function bp_displayed_user_link() {
    1804     echo bp_get_displayed_user_link();
    1805 }
    1806     /**
    1807      * Get the link for the displayed user's profile.
    1808      *
    1809      * @return string
    1810      */
    1811     function bp_get_displayed_user_link() {
    1812 
    1813         /**
    1814          * Filters the link for the displayed user's profile.
    1815          *
    1816          * @since 1.2.4
    1817          *
    1818          * @param string $value Link for the displayed user's profile.
    1819          */
    1820         return apply_filters( 'bp_get_displayed_user_link', bp_displayed_user_domain() );
    1821     }
    1822 
    1823     /**
    1824      * Alias of {@link bp_displayed_user_domain()}.
    1825      *
    1826      * @deprecated
    1827      */
    1828     function bp_user_link() { bp_displayed_user_domain(); }
    1829 
    1830 /**
    1831  * Alias of {@link bp_displayed_user_id()}.
    1832  */
    1833 function bp_current_user_id() { return bp_displayed_user_id(); }
    1834 
    1835 /**
    1836  * Generate the link for the displayed user's profile.
    1837  *
    1838  * @return string
    1839  */
    1840 function bp_displayed_user_domain() {
    1841     $bp = buddypress();
    1842 
    1843     /**
    1844      * Filters the generated link for the displayed user's profile.
    1845      *
    1846      * @since 1.0.0
    1847      *
    1848      * @param string $value Generated link for the displayed user's profile.
    1849      */
    1850     return apply_filters( 'bp_displayed_user_domain', isset( $bp->displayed_user->domain ) ? $bp->displayed_user->domain : '' );
    1851 }
    1852 
    1853 /**
    1854  * Generate the link for the logged-in user's profile.
    1855  *
    1856  * @return string
    1857  */
    1858 function bp_loggedin_user_domain() {
    1859     $bp = buddypress();
    1860 
    1861     /**
    1862      * Filters the generated link for the logged-in user's profile.
    1863      *
    1864      * @since 1.0.0
    1865      *
    1866      * @param string $value Generated link for the logged-in user's profile.
    1867      */
    1868     return apply_filters( 'bp_loggedin_user_domain', isset( $bp->loggedin_user->domain ) ? $bp->loggedin_user->domain : '' );
    1869 }
    1870 
    1871 /**
    1872  * Output the displayed user's display name.
    1873  */
    1874 function bp_displayed_user_fullname() {
    1875     echo bp_get_displayed_user_fullname();
    1876 }
    1877     /**
    1878      * Get the displayed user's display name.
    1879      *
    1880      * @return string
    1881      */
    1882     function bp_get_displayed_user_fullname() {
    1883         $bp = buddypress();
    1884 
    1885         /**
    1886          * Filters the displayed user's display name.
    1887          *
    1888          * @since 1.2.0
    1889          *
    1890          * @param string $value Displayed user's display name.
    1891          */
    1892         return apply_filters( 'bp_displayed_user_fullname', isset( $bp->displayed_user->fullname ) ? $bp->displayed_user->fullname : '' );
    1893     }
    1894 
    1895     /**
    1896      * Alias of {@link bp_get_displayed_user_fullname()}.
    1897      */
    1898     function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
    1899 
    1900 
    1901 /**
    1902  * Output the logged-in user's display name.
    1903  */
    1904 function bp_loggedin_user_fullname() {
    1905     echo bp_get_loggedin_user_fullname();
    1906 }
    1907     /**
    1908      * Get the logged-in user's display name.
    1909      *
    1910      * @return string
    1911      */
    1912     function bp_get_loggedin_user_fullname() {
    1913         $bp = buddypress();
    1914 
    1915         /**
    1916          * Filters the logged-in user's display name.
    1917          *
    1918          * @since 1.0.0
    1919          *
    1920          * @param string $value Logged-in user's display name.
    1921          */
    1922         return apply_filters( 'bp_get_loggedin_user_fullname', isset( $bp->loggedin_user->fullname ) ? $bp->loggedin_user->fullname : '' );
    1923     }
    1924 
    1925 /**
    1926  * Output the username of the displayed user.
    1927  */
    1928 function bp_displayed_user_username() {
    1929     echo bp_get_displayed_user_username();
    1930 }
    1931     /**
    1932      * Get the username of the displayed user.
    1933      *
    1934      * @return string
    1935      */
    1936     function bp_get_displayed_user_username() {
    1937         $bp = buddypress();
    1938 
    1939         if ( bp_displayed_user_id() ) {
    1940             $username = bp_core_get_username( bp_displayed_user_id(), $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login );
    1941         } else {
    1942             $username = '';
    1943         }
    1944 
    1945         /**
    1946          * Filters the username of the displayed user.
    1947          *
    1948          * @since 1.2.0
    1949          *
    1950          * @param string $username Username of the displayed user.
    1951          */
    1952         return apply_filters( 'bp_get_displayed_user_username', $username );
    1953     }
    1954 
    1955 /**
    1956  * Output the username of the logged-in user.
    1957  */
    1958 function bp_loggedin_user_username() {
    1959     echo bp_get_loggedin_user_username();
    1960 }
    1961     /**
    1962      * Get the username of the logged-in user.
    1963      *
    1964      * @return string
    1965      */
    1966     function bp_get_loggedin_user_username() {
    1967         $bp = buddypress();
    1968 
    1969         if ( bp_loggedin_user_id() ) {
    1970             $username = bp_core_get_username( bp_loggedin_user_id(), $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login );
    1971         } else {
    1972             $username = '';
    1973         }
    1974 
    1975         /**
    1976          * Filters the username of the logged-in user.
    1977          *
    1978          * @since 1.2.0
    1979          *
    1980          * @param string $username Username of the logged-in user.
    1981          */
    1982         return apply_filters( 'bp_get_loggedin_user_username', $username );
    1983     }
    1984 /**
    1985  * Echo the current member type message.
    1986  *
    1987  * @since 2.3.0
    1988  */
    1989 function bp_current_member_type_message() {
    1990     echo bp_get_current_member_type_message();
    1991 }
    1992     /**
    1993      * Generate the current member type message.
    1994      *
    1995      * @since 2.3.0
    1996      *
    1997      * @return string
    1998      */
    1999     function bp_get_current_member_type_message() {
    2000         $type_object = bp_get_member_type_object( bp_get_current_member_type() );
    2001 
    2002         $message = sprintf( __( 'Viewing members of the type: %s', 'buddypress' ), '<strong>' . $type_object->labels['singular_name'] . '</strong>' );
    2003 
    2004         return apply_filters( 'bp_get_current_member_type_message', $message );
    2005     }
    2006 
    2007 /** Signup Form ***************************************************************/
    2008 
    2009 /**
    2010  * Do we have a working custom sign up page?
    2011  *
    2012  * @since 1.5.0
    2013  *
    2014  * @uses bp_get_signup_slug() To make sure there is a slug assigned to the page.
    2015  * @uses bp_locate_template() To make sure a template exists to provide output.
    2016  *
    2017  * @return bool True if page and template exist, false if not.
    2018  */
    2019 function bp_has_custom_signup_page() {
    2020     static $has_page = false;
    2021 
    2022     if ( empty( $has_page ) )
    2023         $has_page = bp_get_signup_slug() && bp_locate_template( array( 'registration/register.php', 'members/register.php', 'register.php' ), false );
    2024 
    2025     return (bool) $has_page;
    2026 }
    2027 
    2028 /**
    2029  * Output the URL to the signup page.
    2030  */
    2031 function bp_signup_page() {
    2032     echo esc_url( bp_get_signup_page() );
    2033 }
    2034     /**
    2035      * Get the URL to the signup page.
    2036      *
    2037      * @return string
    2038      */
    2039     function bp_get_signup_page() {
    2040         if ( bp_has_custom_signup_page() ) {
    2041             $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_signup_slug() );
    2042         } else {
    2043             $page = bp_get_root_domain() . '/wp-signup.php';
    2044         }
    2045 
    2046         /**
    2047          * Filters the URL to the signup page.
    2048          *
    2049          * @since 1.1.0
    2050          *
    2051          * @param string $page URL to the signup page.
    2052          */
    2053         return apply_filters( 'bp_get_signup_page', $page );
    2054     }
    2055 
    2056 /**
    2057  * Do we have a working custom activation page?
    2058  *
    2059  * @since 1.5.0
    2060  *
    2061  * @uses bp_get_activate_slug() To make sure there is a slug assigned to the page.
    2062  * @uses bp_locate_template() To make sure a template exists to provide output.
    2063  * @return boolean True if page and template exist, false if not.
    2064  */
    2065 function bp_has_custom_activation_page() {
    2066     static $has_page = false;
    2067 
    2068     if ( empty( $has_page ) )
    2069         $has_page = bp_get_activate_slug() && bp_locate_template( array( 'registration/activate.php', 'members/activate.php', 'activate.php' ), false );
    2070 
    2071     return (bool) $has_page;
    2072 }
    2073 
    2074 /**
    2075  * Output the URL of the activation page.
    2076  */
    2077 function bp_activation_page() {
    2078     echo esc_url( bp_get_activation_page() );
    2079 }
    2080     /**
    2081      * Get the URL of the activation page.
    2082      *
    2083      * @return string
    2084      */
    2085     function bp_get_activation_page() {
    2086         if ( bp_has_custom_activation_page() ) {
    2087             $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_activate_slug() );
    2088         } else {
    2089             $page = trailingslashit( bp_get_root_domain() ) . 'wp-activate.php';
    2090         }
    2091 
    2092         /**
    2093          * Filters the URL of the activation page.
    2094          *
    2095          * @since 1.2.0
    2096          *
    2097          * @param string $page URL to the activation page.
    2098          */
    2099         return apply_filters( 'bp_get_activation_page', $page );
    2100     }
    2101 
    2102 /**
    2103  * Output the username submitted during signup.
    2104  */
    2105 function bp_signup_username_value() {
    2106     echo bp_get_signup_username_value();
    2107 }
    2108     /**
    2109      * Get the username submitted during signup.
    2110      *
    2111      * @todo This should be properly escaped.
    2112      *
    2113      * @return string
    2114      */
    2115     function bp_get_signup_username_value() {
    2116         $value = '';
    2117         if ( isset( $_POST['signup_username'] ) )
    2118             $value = $_POST['signup_username'];
    2119 
    2120         /**
    2121          * Filters the username submitted during signup.
    2122          *
    2123          * @since 1.1.0
    2124          *
    2125          * @param string $value Username submitted during signup.
    2126          */
    2127         return apply_filters( 'bp_get_signup_username_value', $value );
    2128     }
    2129 
    2130 /**
    2131  * Output the user email address submitted during signup.
    2132  */
    2133 function bp_signup_email_value() {
    2134     echo bp_get_signup_email_value();
    2135 }
    2136     /**
    2137      * Get the email address submitted during signup.
    2138      *
    2139      * @todo This should be properly escaped.
    2140      *
    2141      * @return string
    2142      */
    2143     function bp_get_signup_email_value() {
    2144         $value = '';
    2145         if ( isset( $_POST['signup_email'] ) )
    2146             $value = $_POST['signup_email'];
    2147 
    2148         /**
    2149          * Filters the email address submitted during signup.
    2150          *
    2151          * @since 1.1.0
    2152          *
    2153          * @param string $value Email address submitted during signup.
    2154          */
    2155         return apply_filters( 'bp_get_signup_email_value', $value );
    2156     }
    2157 
    2158 /**
    2159  * Output the 'signup_with_blog' value submitted during signup.
    2160  */
    2161 function bp_signup_with_blog_value() {
    2162     echo bp_get_signup_with_blog_value();
    2163 }
    2164     /**
    2165      * Get the 'signup_with_blog' value submitted during signup.
    2166      *
    2167      * @return string
    2168      */
    2169     function bp_get_signup_with_blog_value() {
    2170         $value = '';
    2171         if ( isset( $_POST['signup_with_blog'] ) )
    2172             $value = $_POST['signup_with_blog'];
    2173 
    2174         /**
    2175          * Filters the 'signup_with_blog' value submitted during signup.
    2176          *
    2177          * @since 1.1.0
    2178          *
    2179          * @param string $value 'signup_with_blog' value submitted during signup.
    2180          */
    2181         return apply_filters( 'bp_get_signup_with_blog_value', $value );
    2182     }
    2183 
    2184 /**
    2185  * Output the 'signup_blog_url' value submitted at signup.
    2186  */
    2187 function bp_signup_blog_url_value() {
    2188     echo bp_get_signup_blog_url_value();
    2189 }