Skip to:
Content

BuddyPress.org


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

Move bp-members classes to their own files.

See #6870.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/classes/class-bp-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 }
    2190     /**
    2191      * Get the 'signup_blog_url' value submitted at signup.
    2192      *
    2193      * @todo Should be properly escaped.
    2194      *
    2195      * @return string
    2196      */
    2197     function bp_get_signup_blog_url_value() {
    2198         $value = '';
    2199         if ( isset( $_POST['signup_blog_url'] ) )
    2200             $value = $_POST['signup_blog_url'];
    2201 
    2202         /**
    2203          * Filters the 'signup_blog_url' value submitted during signup.
    2204          *
    2205          * @since 1.1.0
    2206          *
    2207          * @param string $value 'signup_blog_url' value submitted during signup.
    2208          */
    2209         return apply_filters( 'bp_get_signup_blog_url_value', $value );
    2210     }
    2211 
    2212 /**
    2213  * Output the base URL for subdomain installations of WordPress Multisite.
    2214  *
    2215  * @since 2.1.0
    2216  */
    2217 function bp_signup_subdomain_base() {
    2218     echo bp_signup_get_subdomain_base();
    2219 }
    2220     /**
    2221      * Return the base URL for subdomain installations of WordPress Multisite.
    2222      *
    2223      * Replaces bp_blogs_get_subdomain_base()
    2224      *
    2225      * @since 2.1.0
    2226      *
    2227      * @return string The base URL - eg, 'example.com' for site_url() example.com or www.example.com.
    2228      */
    2229     function bp_signup_get_subdomain_base() {
    2230         global $current_site;
    2231 
    2232         // In case plugins are still using this filter.
    2233         $subdomain_base = apply_filters( 'bp_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path );
    2234 
    2235         /**
    2236          * Filters the base URL for subdomain installations of WordPress Multisite.
    2237          *
    2238          * @since 2.1.0
    2239          *
    2240          * @param string $subdomain_base The base URL - eg, 'example.com' for
    2241          *                               site_url() example.com or www.example.com.
    2242          */
    2243         return apply_filters( 'bp_signup_subdomain_base', $subdomain_base );
    2244     }
    2245 
    2246 /**
    2247  * Output the 'signup_blog_titl' value submitted at signup.
    2248  */
    2249 function bp_signup_blog_title_value() {
    2250     echo bp_get_signup_blog_title_value();
    2251 }
    2252     /**
    2253      * Get the 'signup_blog_title' value submitted at signup.
    2254      *
    2255      * @todo Should be properly escaped.
    2256      *
    2257      * @return string
    2258      */
    2259     function bp_get_signup_blog_title_value() {
    2260         $value = '';
    2261         if ( isset( $_POST['signup_blog_title'] ) )
    2262             $value = $_POST['signup_blog_title'];
    2263 
    2264         /**
    2265          * Filters the 'signup_blog_title' value submitted during signup.
    2266          *
    2267          * @since 1.1.0
    2268          *
    2269          * @param string $value 'signup_blog_title' value submitted during signup.
    2270          */
    2271         return apply_filters( 'bp_get_signup_blog_title_value', $value );
    2272     }
    2273 
    2274 /**
    2275  * Output the 'signup_blog_privacy' value submitted at signup.
    2276  */
    2277 function bp_signup_blog_privacy_value() {
    2278     echo bp_get_signup_blog_privacy_value();
    2279 }
    2280     /**
    2281      * Get the 'signup_blog_privacy' value submitted at signup.
    2282      *
    2283      * @todo Should be properly escaped.
    2284      *
    2285      * @return string
    2286      */
    2287     function bp_get_signup_blog_privacy_value() {
    2288         $value = '';
    2289         if ( isset( $_POST['signup_blog_privacy'] ) )
    2290             $value = $_POST['signup_blog_privacy'];
    2291 
    2292         /**
    2293          * Filters the 'signup_blog_privacy' value submitted during signup.
    2294          *
    2295          * @since 1.1.0
    2296          *
    2297          * @param string $value 'signup_blog_privacy' value submitted during signup.
    2298          */
    2299         return apply_filters( 'bp_get_signup_blog_privacy_value', $value );
    2300     }
    2301 
    2302 /**
    2303  * Output the avatar dir used during signup.
    2304  */
    2305 function bp_signup_avatar_dir_value() {
    2306     echo bp_get_signup_avatar_dir_value();
    2307 }
    2308     /**
    2309      * Get the avatar dir used during signup.
    2310      *
    2311      * @return string
    2312      */
    2313     function bp_get_signup_avatar_dir_value() {
    2314         $bp = buddypress();
    2315 
    2316         // Check if signup_avatar_dir is passed.
    2317         if ( !empty( $_POST['signup_avatar_dir'] ) )
    2318             $signup_avatar_dir = $_POST['signup_avatar_dir'];
    2319 
    2320         // If not, check if global is set.
    2321         elseif ( !empty( $bp->signup->avatar_dir ) )
    2322             $signup_avatar_dir = $bp->signup->avatar_dir;
    2323 
    2324         // If not, set false.
    2325         else
    2326             $signup_avatar_dir = false;
    2327 
    2328         /**
    2329          * Filters the avatar dir used during signup.
    2330          *
    2331          * @since 1.1.0
    2332          *
    2333          * @param string|bool $signup_avatar_dir Avatar dir used during signup or false.
    2334          */
    2335         return apply_filters( 'bp_get_signup_avatar_dir_value', $signup_avatar_dir );
    2336     }
    2337 
    2338 /**
    2339  * Output the current signup step.
    2340  */
    2341 function bp_current_signup_step() {
    2342     echo bp_get_current_signup_step();
    2343 }
    2344     /**
    2345      * Get the current signup step.
    2346      *
    2347      * @return string
    2348      */
    2349     function bp_get_current_signup_step() {
    2350         return buddypress()->signup->step;
    2351     }
    2352 
    2353 /**
    2354  * Output the user avatar during signup.
    2355  *
    2356  * @see bp_get_signup_avatar() for description of arguments.
    2357  *
    2358  * @param array|string $args See {@link bp_get_signup_avatar(}.
    2359  */
    2360 function bp_signup_avatar( $args = '' ) {
    2361     echo bp_get_signup_avatar( $args );
    2362 }
    2363     /**
    2364      * Get the user avatar during signup.
    2365      *
    2366      * @see bp_core_fetch_avatar() for description of arguments.
    2367      *
    2368      * @param array|string $args {
    2369      *     Array of optional arguments.
    2370      *     @type int    $size  Height/weight in pixels. Default: value of
    2371      *                         bp_core_avatar_full_width().
    2372      *     @type string $class CSS class. Default: 'avatar'.
    2373      *     @type string $alt   HTML 'alt' attribute. Default: 'Your Avatar'.
    2374      * }
    2375      * @return string
    2376      */
    2377     function bp_get_signup_avatar( $args = '' ) {
    2378         $bp = buddypress();
    2379 
    2380         $defaults = array(
    2381             'size' => bp_core_avatar_full_width(),
    2382             'class' => 'avatar',
    2383             'alt' => __( 'Your Profile Photo', 'buddypress' )
    2384         );
    2385 
    2386         $r = wp_parse_args( $args, $defaults );
    2387         extract( $r, EXTR_SKIP );
    2388 
    2389         // Avatar DIR is found.
    2390         if ( $signup_avatar_dir = bp_get_signup_avatar_dir_value() ) {
    2391             $gravatar_img = bp_core_fetch_avatar( array(
    2392                 'item_id'    => $signup_avatar_dir,
    2393                 'object'     => 'signup',
    2394                 'avatar_dir' => 'avatars/signups',
    2395                 'type'       => 'full',
    2396                 'width'      => $size,
    2397                 'height'     => $size,
    2398                 'alt'        => $alt,
    2399                 'class'      => $class
    2400             ) );
    2401 
    2402         // No avatar DIR was found.
    2403         } else {
    2404 
    2405             // Set default gravatar type.
    2406             if ( empty( $bp->grav_default->user ) )
    2407                 $default_grav = 'wavatar';
    2408             elseif ( 'mystery' == $bp->grav_default->user )
    2409                 $default_grav = $bp->plugin_url . 'bp-core/images/mystery-man.jpg';
    2410             else
    2411                 $default_grav = $bp->grav_default->user;
    2412 
    2413             /**
    2414              * Filters the base Gravatar url used for signup avatars when no avatar dir found.
    2415              *
    2416              * @since 1.0.2
    2417              *
    2418              * @param string $value Gravatar url to use.
    2419              */
    2420             $gravatar_url    = apply_filters( 'bp_gravatar_url', '//www.gravatar.com/avatar/' );
    2421             $md5_lcase_email = md5( strtolower( bp_get_signup_email_value() ) );
    2422             $gravatar_img    = '<img src="' . $gravatar_url . $md5_lcase_email . '?d=' . $default_grav . '&amp;s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
    2423         }
    2424 
    2425         /**
    2426          * Filters the user avatar during signup.
    2427          *
    2428          * @since 1.1.0
    2429          *
    2430          * @param string $gravatar_img Avatar HTML image tag.
    2431          * @param array  $args         Array of parsed args for avatar query.
    2432          */
    2433         return apply_filters( 'bp_get_signup_avatar', $gravatar_img, $args );
    2434     }
    2435 
    2436 /**
    2437  * Output whether signup is allowed.
    2438  *
    2439  * @todo Remove this function. Echoing a bool is pointless.
    2440  */
    2441 function bp_signup_allowed() {
    2442     echo bp_get_signup_allowed();
    2443 }
    2444     /**
    2445      * Is user signup allowed?
    2446      *
    2447      * @return bool
    2448      */
    2449     function bp_get_signup_allowed() {
    2450         $bp = buddypress();
    2451 
    2452         $signup_allowed = false;
    2453 
    2454         if ( is_multisite() ) {
    2455             $registration = bp_core_get_root_option( 'registration' );
    2456 
    2457             if ( in_array( $registration, array( 'all', 'user' ) ) ) {
    2458                 $signup_allowed = true;
    2459             }
    2460 
    2461         } else {
    2462             if ( bp_get_option( 'users_can_register') ) {
    2463                 $signup_allowed = true;
    2464             }
    2465         }
    2466 
    2467         /**
    2468          * Filters whether or not new signups are allowed.
    2469          *
    2470          * @since 1.5.0
    2471          *
    2472          * @param bool $signup_allowed Whether or not new signups are allowed.
    2473          */
    2474         return apply_filters( 'bp_get_signup_allowed', $signup_allowed );
    2475     }
    2476 
    2477 /**
    2478  * Hook member activity feed to <head>.
    2479  *
    2480  * @since 1.5.0
    2481  */
    2482 function bp_members_activity_feed() {
    2483     if ( !bp_is_active( 'activity' ) || !bp_is_user() )
    2484         return; ?>
    2485 
    2486     <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php bp_displayed_user_fullname() ?> | <?php _e( 'Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_member_activity_feed_link() ?>" />
    2487 
    2488 <?php
    2489 }
    2490 add_action( 'bp_head', 'bp_members_activity_feed' );
    2491 
    2492 /**
    2493  * Output a link to a members component subpage.
    2494  *
    2495  * @see bp_get_members_component_link() for description of parameters.
    2496  *
    2497  * @param string      $component See {@bp_get_members_component_link()}.
    2498  * @param string      $action See {@bp_get_members_component_link()}.
    2499  * @param string      $query_args See {@bp_get_members_component_link()}.
    2500  * @param string|bool $nonce See {@bp_get_members_component_link()}.
    2501  */
    2502 function bp_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
    2503     echo esc_url( bp_get_members_component_link( $component, $action, $query_args, $nonce ) );
    2504 }
    2505     /**
    2506      * Generate a link to a members component subpage.
    2507      *
    2508      * @param string       $component  ID of the component (eg 'friends').
    2509      * @param string       $action     Optional. 'action' slug (eg 'invites').
    2510      * @param array|string $query_args Optional. Array of URL params to add to the
    2511      *                                 URL. See {@link add_query_arg()} for format.
    2512      * @param array|bool   $nonce      Optional. If provided, the URL will be passed
    2513      *                                 through wp_nonce_url() with $nonce as the
    2514      *                                 action string.
    2515      * @return string
    2516      */
    2517     function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
    2518 
    2519         // Must be displayed user.
    2520         if ( !bp_displayed_user_id() )
    2521             return;
    2522 
    2523         $bp = buddypress();
    2524 
    2525         // Append $action to $url if there is no $type.
    2526         if ( !empty( $action ) )
    2527             $url = bp_displayed_user_domain() . $bp->{$component}->slug . '/' . $action;
    2528         else
    2529             $url = bp_displayed_user_domain() . $bp->{$component}->slug;
    2530 
    2531         // Add a slash at the end of our user url.
    2532         $url = trailingslashit( $url );
    2533 
    2534         // Add possible query arg.
    2535         if ( !empty( $query_args ) && is_array( $query_args ) )
    2536             $url = add_query_arg( $query_args, $url );
    2537 
    2538         // To nonce, or not to nonce...
    2539         if ( true === $nonce )
    2540             $url = wp_nonce_url( $url );
    2541         elseif ( is_string( $nonce ) )
    2542             $url = wp_nonce_url( $url, $nonce );
    2543 
    2544         // Return the url, if there is one.
    2545         if ( !empty( $url ) )
    2546             return $url;
    2547     }
Note: See TracChangeset for help on using the changeset viewer.