| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * BuddyPress Member Template Tags
|
|---|
| 4 | *
|
|---|
| 5 | * Functions that are safe to use inside your template files and themes
|
|---|
| 6 | *
|
|---|
| 7 | * @package BuddyPress
|
|---|
| 8 | * @subpackage Members
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | // Exit if accessed directly
|
|---|
| 12 | if ( !defined( 'ABSPATH' ) ) exit;
|
|---|
| 13 |
|
|---|
| 14 | /**
|
|---|
| 15 | * Output the members component slug
|
|---|
| 16 | *
|
|---|
| 17 | * @package BuddyPress
|
|---|
| 18 | * @subpackage Members Template
|
|---|
| 19 | * @since 1.5
|
|---|
| 20 | *
|
|---|
| 21 | * @uses bp_get_members_slug()
|
|---|
| 22 | */
|
|---|
| 23 | function bp_members_slug() {
|
|---|
| 24 | echo bp_get_members_slug();
|
|---|
| 25 | }
|
|---|
| 26 | /**
|
|---|
| 27 | * Return the members component slug
|
|---|
| 28 | *
|
|---|
| 29 | * @package BuddyPress
|
|---|
| 30 | * @subpackage Members Template
|
|---|
| 31 | * @since 1.5
|
|---|
| 32 | */
|
|---|
| 33 | function bp_get_members_slug() {
|
|---|
| 34 | global $bp;
|
|---|
| 35 | return apply_filters( 'bp_get_members_slug', $bp->members->slug );
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | /**
|
|---|
| 39 | * Output the members component root slug
|
|---|
| 40 | *
|
|---|
| 41 | * @package BuddyPress
|
|---|
| 42 | * @subpackage Members Template
|
|---|
| 43 | * @since 1.5
|
|---|
| 44 | *
|
|---|
| 45 | * @uses bp_get_members_root_slug()
|
|---|
| 46 | */
|
|---|
| 47 | function bp_members_root_slug() {
|
|---|
| 48 | echo bp_get_members_root_slug();
|
|---|
| 49 | }
|
|---|
| 50 | /**
|
|---|
| 51 | * Return the members component root slug
|
|---|
| 52 | *
|
|---|
| 53 | * @package BuddyPress
|
|---|
| 54 | * @subpackage Members Template
|
|---|
| 55 | * @since 1.5
|
|---|
| 56 | */
|
|---|
| 57 | function bp_get_members_root_slug() {
|
|---|
| 58 | global $bp;
|
|---|
| 59 | return apply_filters( 'bp_get_members_root_slug', $bp->members->root_slug );
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * Output member directory permalink
|
|---|
| 64 | *
|
|---|
| 65 | * @package BuddyPress
|
|---|
| 66 | * @subpackage Members Template
|
|---|
| 67 | * @since 1.5
|
|---|
| 68 | * @uses bp_get_members_directory_permalink()
|
|---|
| 69 | */
|
|---|
| 70 | function bp_members_directory_permalink() {
|
|---|
| 71 | echo bp_get_members_directory_permalink();
|
|---|
| 72 | }
|
|---|
| 73 | /**
|
|---|
| 74 | * Return member directory permalink
|
|---|
| 75 | *
|
|---|
| 76 | * @package BuddyPress
|
|---|
| 77 | * @subpackage Members Template
|
|---|
| 78 | * @since 1.5
|
|---|
| 79 | * @uses apply_filters()
|
|---|
| 80 | * @uses traisingslashit()
|
|---|
| 81 | * @uses bp_get_root_domain()
|
|---|
| 82 | * @uses bp_get_members_root_slug()
|
|---|
| 83 | * @return string
|
|---|
| 84 | */
|
|---|
| 85 | function bp_get_members_directory_permalink() {
|
|---|
| 86 | return apply_filters( 'bp_get_members_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) );
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | /**
|
|---|
| 90 | * Output the sign-up slug
|
|---|
| 91 | *
|
|---|
| 92 | * @package BuddyPress
|
|---|
| 93 | * @subpackage Members Template
|
|---|
| 94 | * @since 1.5
|
|---|
| 95 | *
|
|---|
| 96 | * @uses bp_get_signup_slug()
|
|---|
| 97 | */
|
|---|
| 98 | function bp_signup_slug() {
|
|---|
| 99 | echo bp_get_signup_slug();
|
|---|
| 100 | }
|
|---|
| 101 | /**
|
|---|
| 102 | * Return the sign-up slug
|
|---|
| 103 | *
|
|---|
| 104 | * @package BuddyPress
|
|---|
| 105 | * @subpackage Members Template
|
|---|
| 106 | * @since 1.5
|
|---|
| 107 | */
|
|---|
| 108 | function bp_get_signup_slug() {
|
|---|
| 109 | global $bp;
|
|---|
| 110 |
|
|---|
| 111 | if ( !empty( $bp->pages->register->slug ) )
|
|---|
| 112 | $slug = $bp->pages->register->slug;
|
|---|
| 113 | elseif ( defined( 'BP_REGISTER_SLUG' ) )
|
|---|
| 114 | $slug = BP_REGISTER_SLUG;
|
|---|
| 115 | else
|
|---|
| 116 | $slug = 'register';
|
|---|
| 117 |
|
|---|
| 118 | return apply_filters( 'bp_get_signup_slug', $slug );
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /**
|
|---|
| 122 | * Output the activation slug
|
|---|
| 123 | *
|
|---|
| 124 | * @package BuddyPress
|
|---|
| 125 | * @subpackage Members Template
|
|---|
| 126 | * @since 1.5
|
|---|
| 127 | *
|
|---|
| 128 | * @uses bp_get_activate_slug()
|
|---|
| 129 | */
|
|---|
| 130 | function bp_activate_slug() {
|
|---|
| 131 | echo bp_get_activate_slug();
|
|---|
| 132 | }
|
|---|
| 133 | /**
|
|---|
| 134 | * Return the activation slug
|
|---|
| 135 | *
|
|---|
| 136 | * @package BuddyPress
|
|---|
| 137 | * @subpackage Members Template
|
|---|
| 138 | * @since 1.5
|
|---|
| 139 | */
|
|---|
| 140 | function bp_get_activate_slug() {
|
|---|
| 141 | global $bp;
|
|---|
| 142 |
|
|---|
| 143 | if ( !empty( $bp->pages->activate->slug ) )
|
|---|
| 144 | $slug = $bp->pages->activate->slug;
|
|---|
| 145 | elseif ( defined( 'BP_ACTIVATION_SLUG' ) )
|
|---|
| 146 | $slug = BP_ACTIVATION_SLUG;
|
|---|
| 147 | else
|
|---|
| 148 | $slug = 'activate';
|
|---|
| 149 |
|
|---|
| 150 | return apply_filters( 'bp_get_activate_slug', $slug );
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | /***
|
|---|
| 154 | * Members template loop that will allow you to loop all members or friends of a member
|
|---|
| 155 | * if you pass a user_id.
|
|---|
| 156 | */
|
|---|
| 157 |
|
|---|
| 158 | class BP_Core_Members_Template {
|
|---|
| 159 | var $current_member = -1;
|
|---|
| 160 | var $member_count;
|
|---|
| 161 | var $members;
|
|---|
| 162 | var $member;
|
|---|
| 163 |
|
|---|
| 164 | var $in_the_loop;
|
|---|
| 165 |
|
|---|
| 166 | var $pag_page;
|
|---|
| 167 | var $pag_num;
|
|---|
| 168 | var $pag_links;
|
|---|
| 169 | var $total_member_count;
|
|---|
| 170 |
|
|---|
| 171 | function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value ) {
|
|---|
| 172 | $this->__construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value );
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value ) {
|
|---|
| 176 | global $bp;
|
|---|
| 177 |
|
|---|
| 178 | $this->pag_page = !empty( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : (int)$page_number;
|
|---|
| 179 | $this->pag_num = !empty( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : (int)$per_page;
|
|---|
| 180 | $this->type = $type;
|
|---|
| 181 |
|
|---|
| 182 | if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
|
|---|
| 183 | $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude );
|
|---|
| 184 | else if ( false !== $include )
|
|---|
| 185 | $this->members = BP_Core_User::get_specific_users( $include, $this->pag_num, $this->pag_page, $populate_extras );
|
|---|
| 186 | else
|
|---|
| 187 | $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value ) );
|
|---|
| 188 |
|
|---|
| 189 | if ( !$max || $max >= (int)$this->members['total'] )
|
|---|
| 190 | $this->total_member_count = (int)$this->members['total'];
|
|---|
| 191 | else
|
|---|
| 192 | $this->total_member_count = (int)$max;
|
|---|
| 193 |
|
|---|
| 194 | $this->members = $this->members['users'];
|
|---|
| 195 |
|
|---|
| 196 | if ( $max ) {
|
|---|
| 197 | if ( $max >= count( $this->members ) ) {
|
|---|
| 198 | $this->member_count = count( $this->members );
|
|---|
| 199 | } else {
|
|---|
| 200 | $this->member_count = (int)$max;
|
|---|
| 201 | }
|
|---|
| 202 | } else {
|
|---|
| 203 | $this->member_count = count( $this->members );
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | if ( (int)$this->total_member_count && (int)$this->pag_num ) {
|
|---|
| 207 | $this->pag_links = paginate_links( array(
|
|---|
| 208 | 'base' => add_query_arg( 'upage', '%#%' ),
|
|---|
| 209 | 'format' => '',
|
|---|
| 210 | 'total' => ceil( (int)$this->total_member_count / (int)$this->pag_num ),
|
|---|
| 211 | 'current' => (int) $this->pag_page,
|
|---|
| 212 | 'prev_text' => _x( '←', 'Member pagination previous text', 'buddypress' ),
|
|---|
| 213 | 'next_text' => _x( '→', 'Member pagination next text', 'buddypress' ),
|
|---|
| 214 | 'mid_size' => 1
|
|---|
| 215 | ) );
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | function has_members() {
|
|---|
| 220 | if ( $this->member_count )
|
|---|
| 221 | return true;
|
|---|
| 222 |
|
|---|
| 223 | return false;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | function next_member() {
|
|---|
| 227 | $this->current_member++;
|
|---|
| 228 | $this->member = $this->members[$this->current_member];
|
|---|
| 229 |
|
|---|
| 230 | return $this->member;
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | function rewind_members() {
|
|---|
| 234 | $this->current_member = -1;
|
|---|
| 235 | if ( $this->member_count > 0 ) {
|
|---|
| 236 | $this->member = $this->members[0];
|
|---|
| 237 | }
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | function members() {
|
|---|
| 241 | if ( $this->current_member + 1 < $this->member_count ) {
|
|---|
| 242 | return true;
|
|---|
| 243 | } elseif ( $this->current_member + 1 == $this->member_count ) {
|
|---|
| 244 | do_action('member_loop_end');
|
|---|
| 245 | // Do some cleaning up after the loop
|
|---|
| 246 | $this->rewind_members();
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | $this->in_the_loop = false;
|
|---|
| 250 | return false;
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | function the_member() {
|
|---|
| 254 | global $member, $bp;
|
|---|
| 255 |
|
|---|
| 256 | $this->in_the_loop = true;
|
|---|
| 257 | $this->member = $this->next_member();
|
|---|
| 258 |
|
|---|
| 259 | if ( 0 == $this->current_member ) // loop has just started
|
|---|
| 260 | do_action('member_loop_start');
|
|---|
| 261 | }
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | function bp_rewind_members() {
|
|---|
| 265 | global $members_template;
|
|---|
| 266 |
|
|---|
| 267 | return $members_template->rewind_members();
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | function bp_has_members( $args = '' ) {
|
|---|
| 271 | global $bp, $members_template;
|
|---|
| 272 |
|
|---|
| 273 | /***
|
|---|
| 274 | * Set the defaults based on the current page. Any of these will be overridden
|
|---|
| 275 | * if arguments are directly passed into the loop. Custom plugins should always
|
|---|
| 276 | * pass their parameters directly to the loop.
|
|---|
| 277 | */
|
|---|
| 278 | $type = 'active';
|
|---|
| 279 | $user_id = 0;
|
|---|
| 280 | $page = 1;
|
|---|
| 281 | $search_terms = null;
|
|---|
| 282 |
|
|---|
| 283 | // User filtering
|
|---|
| 284 | if ( !empty( $bp->displayed_user->id ) )
|
|---|
| 285 | $user_id = $bp->displayed_user->id;
|
|---|
| 286 |
|
|---|
| 287 | // type: active ( default ) | random | newest | popular | online | alphabetical
|
|---|
| 288 | $defaults = array(
|
|---|
| 289 | 'type' => $type,
|
|---|
| 290 | 'page' => $page,
|
|---|
| 291 | 'per_page' => 20,
|
|---|
| 292 | 'max' => false,
|
|---|
| 293 |
|
|---|
| 294 | 'include' => false, // Pass a user_id or a list (comma-separated or array) of user_ids to only show these users
|
|---|
| 295 | 'exclude' => false, // Pass a user_id or a list (comma-separated or array) of user_ids to exclude these users
|
|---|
| 296 |
|
|---|
| 297 | 'user_id' => $user_id, // Pass a user_id to only show friends of this user
|
|---|
| 298 | 'search_terms' => $search_terms, // Pass search_terms to filter users by their profile data
|
|---|
| 299 |
|
|---|
| 300 | 'meta_key' => false, // Only return users with this usermeta
|
|---|
| 301 | 'meta_value' => false, // Only return users where the usermeta value matches. Requires meta_key
|
|---|
| 302 |
|
|---|
| 303 | 'populate_extras' => true // Fetch usermeta? Friend count, last active etc.
|
|---|
| 304 | );
|
|---|
| 305 |
|
|---|
| 306 | $r = wp_parse_args( $args, $defaults );
|
|---|
| 307 | extract( $r );
|
|---|
| 308 |
|
|---|
| 309 | // Pass a filter if ?s= is set.
|
|---|
| 310 | if ( is_null( $search_terms ) ) {
|
|---|
| 311 | if ( !empty( $_REQUEST['s'] ) )
|
|---|
| 312 | $search_terms = $_REQUEST['s'];
|
|---|
| 313 | else
|
|---|
| 314 | $search_terms = false;
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | // Set per_page to max if max is larger than per_page
|
|---|
| 318 | if ( !empty( $max ) && ( $per_page > $max ) )
|
|---|
| 319 | $per_page = $max;
|
|---|
| 320 |
|
|---|
| 321 | // Make sure we return no members if we looking at friendship requests and there are none.
|
|---|
| 322 | if ( empty( $include ) && bp_is_friends_component() && bp_is_current_action( 'requests' ) )
|
|---|
| 323 | return false;
|
|---|
| 324 |
|
|---|
| 325 | $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras, $exclude, $meta_key, $meta_value );
|
|---|
| 326 | return apply_filters( 'bp_has_members', $members_template->has_members(), $members_template );
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | function bp_the_member() {
|
|---|
| 330 | global $members_template;
|
|---|
| 331 | return $members_template->the_member();
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | function bp_members() {
|
|---|
| 335 | global $members_template;
|
|---|
| 336 | return $members_template->members();
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | function bp_members_pagination_count() {
|
|---|
| 340 | echo bp_get_members_pagination_count();
|
|---|
| 341 | }
|
|---|
| 342 | function bp_get_members_pagination_count() {
|
|---|
| 343 | global $bp, $members_template;
|
|---|
| 344 |
|
|---|
| 345 | if ( empty( $members_template->type ) )
|
|---|
| 346 | $members_template->type = '';
|
|---|
| 347 |
|
|---|
| 348 | $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
|
|---|
| 349 | $from_num = bp_core_number_format( $start_num );
|
|---|
| 350 | $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 ) );
|
|---|
| 351 | $total = bp_core_number_format( $members_template->total_member_count );
|
|---|
| 352 |
|
|---|
| 353 | if ( 'active' == $members_template->type )
|
|---|
| 354 | $pag = sprintf( __( 'Viewing member %1$s to %2$s (of %3$s active members)', 'buddypress' ), $from_num, $to_num, $total );
|
|---|
| 355 | else if ( 'popular' == $members_template->type )
|
|---|
| 356 | $pag = sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members with friends)', 'buddypress' ), $from_num, $to_num, $total );
|
|---|
| 357 | else if ( 'online' == $members_template->type )
|
|---|
| 358 | $pag = sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members online)', 'buddypress' ), $from_num, $to_num, $total );
|
|---|
| 359 | else
|
|---|
| 360 | $pag = sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members)', 'buddypress' ), $from_num, $to_num, $total );
|
|---|
| 361 |
|
|---|
| 362 | return apply_filters( 'bp_members_pagination_count', $pag );
|
|---|
| 363 | }
|
|---|
| 364 |
|
|---|
| 365 | function bp_members_pagination_links() {
|
|---|
| 366 | echo bp_get_members_pagination_links();
|
|---|
| 367 | }
|
|---|
| 368 | function bp_get_members_pagination_links() {
|
|---|
| 369 | global $members_template;
|
|---|
| 370 |
|
|---|
| 371 | return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links );
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | /**
|
|---|
| 375 | * bp_member_user_id()
|
|---|
| 376 | *
|
|---|
| 377 | * Echo id from bp_get_member_user_id()
|
|---|
| 378 | *
|
|---|
| 379 | * @uses bp_get_member_user_id()
|
|---|
| 380 | */
|
|---|
| 381 | function bp_member_user_id() {
|
|---|
| 382 | echo bp_get_member_user_id();
|
|---|
| 383 | }
|
|---|
| 384 | /**
|
|---|
| 385 | * bp_get_member_user_id()
|
|---|
| 386 | *
|
|---|
| 387 | * Get the id of the user in a members loop
|
|---|
| 388 | *
|
|---|
| 389 | * @global object $members_template
|
|---|
| 390 | * @return string Members id
|
|---|
| 391 | */
|
|---|
| 392 | function bp_get_member_user_id() {
|
|---|
| 393 | global $members_template;
|
|---|
| 394 |
|
|---|
| 395 | return apply_filters( 'bp_get_member_user_id', $members_template->member->id );
|
|---|
| 396 | }
|
|---|
| 397 |
|
|---|
| 398 | /**
|
|---|
| 399 | * bp_member_user_nicename()
|
|---|
| 400 | *
|
|---|
| 401 | * Echo nicename from bp_get_member_user_nicename()
|
|---|
| 402 | *
|
|---|
| 403 | * @uses bp_get_member_user_nicename()
|
|---|
| 404 | */
|
|---|
| 405 | function bp_member_user_nicename() {
|
|---|
| 406 | echo bp_get_member_user_nicename();
|
|---|
| 407 | }
|
|---|
| 408 | /**
|
|---|
| 409 | * bp_get_member_user_nicename()
|
|---|
| 410 | *
|
|---|
| 411 | * Get the nicename of the user in a members loop
|
|---|
| 412 | *
|
|---|
| 413 | * @global object $members_template
|
|---|
| 414 | * @return string Members nicename
|
|---|
| 415 | */
|
|---|
| 416 | function bp_get_member_user_nicename() {
|
|---|
| 417 | global $members_template;
|
|---|
| 418 | return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename );
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | /**
|
|---|
| 422 | * bp_member_user_login()
|
|---|
| 423 | *
|
|---|
| 424 | * Echo login from bp_get_member_user_login()
|
|---|
| 425 | *
|
|---|
| 426 | * @uses bp_get_member_user_login()
|
|---|
| 427 | */
|
|---|
| 428 | function bp_member_user_login() {
|
|---|
| 429 | echo bp_get_member_user_login();
|
|---|
| 430 | }
|
|---|
| 431 | /**
|
|---|
| 432 | * bp_get_member_user_login()
|
|---|
| 433 | *
|
|---|
| 434 | * Get the login of the user in a members loop
|
|---|
| 435 | *
|
|---|
| 436 | * @global object $members_template
|
|---|
| 437 | * @return string Members login
|
|---|
| 438 | */
|
|---|
| 439 | function bp_get_member_user_login() {
|
|---|
| 440 | global $members_template;
|
|---|
| 441 | return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login );
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | /**
|
|---|
| 445 | * bp_member_user_email()
|
|---|
| 446 | *
|
|---|
| 447 | * Echo email address from bp_get_member_user_email()
|
|---|
| 448 | *
|
|---|
| 449 | * @uses bp_get_member_user_email()
|
|---|
| 450 | */
|
|---|
| 451 | function bp_member_user_email() {
|
|---|
| 452 | echo bp_get_member_user_email();
|
|---|
| 453 | }
|
|---|
| 454 | /**
|
|---|
| 455 | * bp_get_member_user_email()
|
|---|
| 456 | *
|
|---|
| 457 | * Get the email address of the user in a members loop
|
|---|
| 458 | *
|
|---|
| 459 | * @global object $members_template
|
|---|
| 460 | * @return string Members email address
|
|---|
| 461 | */
|
|---|
| 462 | function bp_get_member_user_email() {
|
|---|
| 463 | global $members_template;
|
|---|
| 464 | return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email );
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | function bp_member_is_loggedin_user() {
|
|---|
| 468 | global $bp, $members_template;
|
|---|
| 469 | return apply_filters( 'bp_member_is_loggedin_user', $bp->loggedin_user->id == $members_template->member->id ? true : false );
|
|---|
| 470 | }
|
|---|
| 471 |
|
|---|
| 472 | function bp_member_avatar( $args = '' ) {
|
|---|
| 473 | echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
|
|---|
| 474 | }
|
|---|
| 475 | function bp_get_member_avatar( $args = '' ) {
|
|---|
| 476 | global $bp, $members_template;
|
|---|
| 477 |
|
|---|
| 478 | $defaults = array(
|
|---|
| 479 | 'type' => 'thumb',
|
|---|
| 480 | 'width' => false,
|
|---|
| 481 | 'height' => false,
|
|---|
| 482 | 'class' => 'avatar',
|
|---|
| 483 | 'id' => false,
|
|---|
| 484 | 'alt' => __( 'Profile picture of %s', 'buddypress' )
|
|---|
| 485 | );
|
|---|
| 486 |
|
|---|
| 487 | $r = wp_parse_args( $args, $defaults );
|
|---|
| 488 | extract( $r, EXTR_SKIP );
|
|---|
| 489 |
|
|---|
| 490 | 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 ) ) );
|
|---|
| 491 | }
|
|---|
| 492 |
|
|---|
| 493 | function bp_member_permalink() {
|
|---|
| 494 | echo bp_get_member_permalink();
|
|---|
| 495 | }
|
|---|
| 496 | function bp_get_member_permalink() {
|
|---|
| 497 | global $members_template;
|
|---|
| 498 |
|
|---|
| 499 | 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 ) );
|
|---|
| 500 | }
|
|---|
| 501 | function bp_member_link() { echo bp_get_member_permalink(); }
|
|---|
| 502 | function bp_get_member_link() { return bp_get_member_permalink(); }
|
|---|
| 503 |
|
|---|
| 504 | /**
|
|---|
| 505 | * Echoes bp_get_member_name()
|
|---|
| 506 | *
|
|---|
| 507 | * @package BuddyPress
|
|---|
| 508 | */
|
|---|
| 509 | function bp_member_name() {
|
|---|
| 510 | echo apply_filters( 'bp_member_name', bp_get_member_name() );
|
|---|
| 511 | }
|
|---|
| 512 | /**
|
|---|
| 513 | * Used inside a bp_has_members() loop, this function returns a user's full name
|
|---|
| 514 | *
|
|---|
| 515 | * Full name is, by default, pulled from xprofile's Full Name field. When this field is
|
|---|
| 516 | * empty, we try to get an alternative name from the WP users table, in the following order
|
|---|
| 517 | * of preference: display_name, user_nicename, user_login.
|
|---|
| 518 | *
|
|---|
| 519 | * @package BuddyPress
|
|---|
| 520 | *
|
|---|
| 521 | * @uses apply_filters() Filter bp_get_the_member_name() to alter the function's output
|
|---|
| 522 | * @return str The user's fullname for display
|
|---|
| 523 | */
|
|---|
| 524 | function bp_get_member_name() {
|
|---|
| 525 | global $members_template;
|
|---|
| 526 |
|
|---|
| 527 | // Generally, this only fires when xprofile is disabled
|
|---|
| 528 | if ( empty( $members_template->member->fullname ) ) {
|
|---|
| 529 | // Our order of preference for alternative fullnames
|
|---|
| 530 | $name_stack = array(
|
|---|
| 531 | 'display_name',
|
|---|
| 532 | 'user_nicename',
|
|---|
| 533 | 'user_login'
|
|---|
| 534 | );
|
|---|
| 535 |
|
|---|
| 536 | foreach ( $name_stack as $source ) {
|
|---|
| 537 | if ( !empty( $members_template->member->{$source} ) ) {
|
|---|
| 538 | // When a value is found, set it as fullname and be done
|
|---|
| 539 | // with it
|
|---|
| 540 | $members_template->member->fullname = $members_template->member->{$source};
|
|---|
| 541 | break;
|
|---|
| 542 | }
|
|---|
| 543 | }
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
|
|---|
| 547 | }
|
|---|
| 548 | add_filter( 'bp_get_member_name', 'wp_filter_kses' );
|
|---|
| 549 | add_filter( 'bp_get_member_name', 'stripslashes' );
|
|---|
| 550 | add_filter( 'bp_get_member_name', 'strip_tags' );
|
|---|
| 551 |
|
|---|
| 552 | function bp_member_last_active() {
|
|---|
| 553 | echo bp_get_member_last_active();
|
|---|
| 554 | }
|
|---|
| 555 | function bp_get_member_last_active() {
|
|---|
| 556 | global $members_template;
|
|---|
| 557 |
|
|---|
| 558 | if ( isset( $members_template->member->last_activity ) )
|
|---|
| 559 | $last_activity = bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s', 'buddypress' ) );
|
|---|
| 560 | else
|
|---|
| 561 | $last_activity = __( 'Never active', 'buddypress' );
|
|---|
| 562 |
|
|---|
| 563 | return apply_filters( 'bp_member_last_active', $last_activity );
|
|---|
| 564 | }
|
|---|
| 565 |
|
|---|
| 566 | function bp_member_latest_update( $args = '' ) {
|
|---|
| 567 | echo bp_get_member_latest_update( $args );
|
|---|
| 568 | }
|
|---|
| 569 | function bp_get_member_latest_update( $args = '' ) {
|
|---|
| 570 | global $bp, $members_template;
|
|---|
| 571 |
|
|---|
| 572 | $defaults = array(
|
|---|
| 573 | 'length' => 225,
|
|---|
| 574 | 'view_link' => true
|
|---|
| 575 | );
|
|---|
| 576 |
|
|---|
| 577 | $r = wp_parse_args( $args, $defaults );
|
|---|
| 578 | extract( $r );
|
|---|
| 579 |
|
|---|
| 580 | if ( !bp_is_active( 'activity' ) || empty( $members_template->member->latest_update ) || !$update = maybe_unserialize( $members_template->member->latest_update ) )
|
|---|
| 581 | return false;
|
|---|
| 582 |
|
|---|
| 583 | $update_content = apply_filters( 'bp_get_activity_latest_update_excerpt', sprintf( _x( '- "%s "', 'member latest update in member directory', 'buddypress' ), trim( strip_tags( bp_create_excerpt( $update['content'], $length ) ) ) ) );
|
|---|
| 584 |
|
|---|
| 585 | // If $view_link is true and the text returned by bp_create_excerpt() is different from the original text (ie it's
|
|---|
| 586 | // been truncated), add the "View" link.
|
|---|
| 587 | if ( $view_link && ( $update_content != $update['content'] ) ) {
|
|---|
| 588 | $view = __( 'View', 'buddypress' );
|
|---|
| 589 |
|
|---|
| 590 | $update_content .= '<span class="activity-read-more"><a href="' . bp_activity_get_permalink( $update['id'] ) . '" rel="nofollow">' . $view . '</a></span>';
|
|---|
| 591 | }
|
|---|
| 592 |
|
|---|
| 593 | return apply_filters( 'bp_get_member_latest_update', $update_content );
|
|---|
| 594 | }
|
|---|
| 595 |
|
|---|
| 596 | function bp_member_profile_data( $args = '' ) {
|
|---|
| 597 | echo bp_get_member_profile_data( $args );
|
|---|
| 598 | }
|
|---|
| 599 | function bp_get_member_profile_data( $args = '' ) {
|
|---|
| 600 | global $bp, $members_template;
|
|---|
| 601 |
|
|---|
| 602 | if ( !bp_is_active( 'xprofile' ) )
|
|---|
| 603 | return false;
|
|---|
| 604 |
|
|---|
| 605 | // Declare local variables
|
|---|
| 606 | $data = false;
|
|---|
| 607 | $user_id = 0;
|
|---|
| 608 |
|
|---|
| 609 | // Guess at default $user_id
|
|---|
| 610 | if ( !empty( $members_template->member->id ) )
|
|---|
| 611 | $user_id = $members_template->member->id;
|
|---|
| 612 | elseif ( !empty( $bp->displayed_user->id ) )
|
|---|
| 613 | $user_id = $bp->displayed_user->id;
|
|---|
| 614 |
|
|---|
| 615 | $defaults = array(
|
|---|
| 616 | 'field' => false, // Field name
|
|---|
| 617 | 'user_id' => $user_id
|
|---|
| 618 | );
|
|---|
| 619 |
|
|---|
| 620 | $r = wp_parse_args( $args, $defaults );
|
|---|
| 621 | extract( $r, EXTR_SKIP );
|
|---|
| 622 |
|
|---|
| 623 | // Populate the user if it hasn't been already.
|
|---|
| 624 | if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
|
|---|
| 625 | $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );
|
|---|
| 626 |
|
|---|
| 627 | // Get the field data if there is data to get
|
|---|
| 628 | if ( !empty( $members_template->member->profile_data ) )
|
|---|
| 629 | $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
|
|---|
| 630 |
|
|---|
| 631 | return apply_filters( 'bp_get_member_profile_data', $data );
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | function bp_member_registered() {
|
|---|
| 635 | echo bp_get_member_registered();
|
|---|
| 636 | }
|
|---|
| 637 | function bp_get_member_registered() {
|
|---|
| 638 | global $members_template;
|
|---|
| 639 |
|
|---|
| 640 | $registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s', 'buddypress' ) ) );
|
|---|
| 641 |
|
|---|
| 642 | return apply_filters( 'bp_member_last_active', $registered );
|
|---|
| 643 | }
|
|---|
| 644 |
|
|---|
| 645 | function bp_member_random_profile_data() {
|
|---|
| 646 | global $members_template;
|
|---|
| 647 |
|
|---|
| 648 | if ( bp_is_active( 'xprofile' ) ) { ?>
|
|---|
| 649 | <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
|
|---|
| 650 | <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
|
|---|
| 651 | <?php echo wp_filter_kses( $random_data[0]->value ) ?>
|
|---|
| 652 | <?php }
|
|---|
| 653 | }
|
|---|
| 654 |
|
|---|
| 655 | function bp_member_hidden_fields() {
|
|---|
| 656 | if ( isset( $_REQUEST['s'] ) )
|
|---|
| 657 | echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ) . '" name="search_terms" />';
|
|---|
| 658 |
|
|---|
| 659 | if ( isset( $_REQUEST['letter'] ) )
|
|---|
| 660 | echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
|
|---|
| 661 |
|
|---|
| 662 | if ( isset( $_REQUEST['members_search'] ) )
|
|---|
| 663 | echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />';
|
|---|
| 664 | }
|
|---|
| 665 |
|
|---|
| 666 | function bp_directory_members_search_form() {
|
|---|
| 667 | global $bp;
|
|---|
| 668 |
|
|---|
| 669 | $default_search_value = bp_get_search_default_text( 'members' );
|
|---|
| 670 | $search_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
|
|---|
| 671 |
|
|---|
| 672 | <form action="" method="get" id="search-members-form">
|
|---|
| 673 | <label><input type="text" name="s" id="members_search" value="<?php echo esc_attr( $search_value ) ?>" onfocus="if (this.value == '<?php echo $default_search_value ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php echo $default_search_value ?>';}" /></label>
|
|---|
| 674 | <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
|
|---|
| 675 | </form>
|
|---|
| 676 |
|
|---|
| 677 | <?php
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | function bp_total_site_member_count() {
|
|---|
| 681 | echo bp_get_total_site_member_count();
|
|---|
| 682 | }
|
|---|
| 683 | function bp_get_total_site_member_count() {
|
|---|
| 684 | return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) );
|
|---|
| 685 | }
|
|---|
| 686 |
|
|---|
| 687 | /** Navigation and other misc template tags **/
|
|---|
| 688 |
|
|---|
| 689 | /**
|
|---|
| 690 | * Uses the $bp->bp_nav global to render out the navigation within a BuddyPress install.
|
|---|
| 691 | * Each component adds to this navigation array within its own [component_name]setup_nav() function.
|
|---|
| 692 | *
|
|---|
| 693 | * This navigation array is the top level navigation, so it contains items such as:
|
|---|
| 694 | * [Blog, Profile, Messages, Groups, Friends] ...
|
|---|
| 695 | *
|
|---|
| 696 | * The function will also analyze the current component the user is in, to determine whether
|
|---|
| 697 | * or not to highlight a particular nav item.
|
|---|
| 698 | *
|
|---|
| 699 | * @package BuddyPress Core
|
|---|
| 700 | * @todo Move to a back-compat file?
|
|---|
| 701 | * @deprecated Does not seem to be called anywhere in the core
|
|---|
| 702 | * @global object $bp Global BuddyPress settings object
|
|---|
| 703 | */
|
|---|
| 704 | function bp_get_loggedin_user_nav() {
|
|---|
| 705 | global $bp;
|
|---|
| 706 |
|
|---|
| 707 | // Loop through each navigation item
|
|---|
| 708 | foreach( (array) $bp->bp_nav as $nav_item ) {
|
|---|
| 709 | // If the current component matches the nav item id, then add a highlight CSS class.
|
|---|
| 710 | if ( !bp_is_directory() && !empty( $bp->current_component ) && $bp->active_components[$bp->current_component] == $nav_item['css_id'] ){
|
|---|
| 711 | $selected = ' class="current selected"';
|
|---|
| 712 | }
|
|---|
| 713 | else
|
|---|
| 714 | $selected = '';
|
|---|
| 715 |
|
|---|
| 716 | /* If we are viewing another person (current_userid does not equal loggedin_user->id)
|
|---|
| 717 | then check to see if the two users are friends. if they are, add a highlight CSS class
|
|---|
| 718 | to the friends nav item if it exists. */
|
|---|
| 719 | if ( !bp_is_my_profile() && $bp->displayed_user->id ) {
|
|---|
| 720 | $selected = '';
|
|---|
| 721 |
|
|---|
| 722 | if ( bp_is_active( 'friends' ) ) {
|
|---|
| 723 | if ( $nav_item['css_id'] == $bp->friends->id ) {
|
|---|
| 724 | if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) )
|
|---|
| 725 | $selected = ' class="current selected"';
|
|---|
| 726 | }
|
|---|
| 727 | }
|
|---|
| 728 | }
|
|---|
| 729 |
|
|---|
| 730 | // echo out the final list item
|
|---|
| 731 | 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 ) );
|
|---|
| 732 | }
|
|---|
| 733 |
|
|---|
| 734 | // Always add a log out list item to the end of the navigation
|
|---|
| 735 | $logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( bp_get_root_domain() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
|
|---|
| 736 |
|
|---|
| 737 | echo apply_filters( 'bp_logout_nav_link', $logout_link );
|
|---|
| 738 | }
|
|---|
| 739 |
|
|---|
| 740 | /**
|
|---|
| 741 | * Uses the $bp->bp_nav global to render out the user navigation when viewing another user other than
|
|---|
| 742 | * yourself.
|
|---|
| 743 | *
|
|---|
| 744 | * @package BuddyPress Core
|
|---|
| 745 | * @global object $bp Global BuddyPress settings object
|
|---|
| 746 | */
|
|---|
| 747 | function bp_get_displayed_user_nav() {
|
|---|
| 748 | global $bp;
|
|---|
| 749 |
|
|---|
| 750 | foreach ( (array)$bp->bp_nav as $user_nav_item ) {
|
|---|
| 751 | if ( !$user_nav_item['show_for_displayed_user'] && !bp_is_my_profile() )
|
|---|
| 752 | continue;
|
|---|
| 753 |
|
|---|
| 754 | if ( $bp->current_component == $user_nav_item['slug'] )
|
|---|
| 755 | $selected = ' class="current selected"';
|
|---|
| 756 | else
|
|---|
| 757 | $selected = '';
|
|---|
| 758 |
|
|---|
| 759 | if ( $bp->loggedin_user->domain )
|
|---|
| 760 | $link = str_replace( $bp->loggedin_user->domain, $bp->displayed_user->domain, $user_nav_item['link'] );
|
|---|
| 761 | else
|
|---|
| 762 | $link = $bp->displayed_user->domain . $user_nav_item['link'];
|
|---|
| 763 |
|
|---|
| 764 | 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 ) );
|
|---|
| 765 | }
|
|---|
| 766 | }
|
|---|
| 767 |
|
|---|
| 768 | /** Avatars *******************************************************************/
|
|---|
| 769 |
|
|---|
| 770 | function bp_loggedin_user_avatar( $args = '' ) {
|
|---|
| 771 | echo bp_get_loggedin_user_avatar( $args );
|
|---|
| 772 | }
|
|---|
| 773 | function bp_get_loggedin_user_avatar( $args = '' ) {
|
|---|
| 774 | global $bp;
|
|---|
| 775 |
|
|---|
| 776 | $defaults = array(
|
|---|
| 777 | 'type' => 'thumb',
|
|---|
| 778 | 'width' => false,
|
|---|
| 779 | 'height' => false,
|
|---|
| 780 | 'html' => true,
|
|---|
| 781 | 'alt' => __( 'Profile picture of %s', 'buddypress' )
|
|---|
| 782 | );
|
|---|
| 783 |
|
|---|
| 784 | $r = wp_parse_args( $args, $defaults );
|
|---|
| 785 | extract( $r, EXTR_SKIP );
|
|---|
| 786 |
|
|---|
| 787 | return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html, 'alt' => $alt ) ) );
|
|---|
| 788 | }
|
|---|
| 789 |
|
|---|
| 790 | function bp_displayed_user_avatar( $args = '' ) {
|
|---|
| 791 | echo bp_get_displayed_user_avatar( $args );
|
|---|
| 792 | }
|
|---|
| 793 | function bp_get_displayed_user_avatar( $args = '' ) {
|
|---|
| 794 | global $bp;
|
|---|
| 795 |
|
|---|
| 796 | $defaults = array(
|
|---|
| 797 | 'type' => 'thumb',
|
|---|
| 798 | 'width' => false,
|
|---|
| 799 | 'height' => false,
|
|---|
| 800 | 'html' => true,
|
|---|
| 801 | 'alt' => __( 'Profile picture of %s', 'buddypress' )
|
|---|
| 802 | );
|
|---|
| 803 |
|
|---|
| 804 | $r = wp_parse_args( $args, $defaults );
|
|---|
| 805 | extract( $r, EXTR_SKIP );
|
|---|
| 806 |
|
|---|
| 807 | return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html, 'alt' => $alt ) ) );
|
|---|
| 808 | }
|
|---|
| 809 |
|
|---|
| 810 | function bp_displayed_user_email() {
|
|---|
| 811 | echo bp_get_displayed_user_email();
|
|---|
| 812 | }
|
|---|
| 813 | function bp_get_displayed_user_email() {
|
|---|
| 814 | global $bp;
|
|---|
| 815 |
|
|---|
| 816 | // If displayed user exists, return email address
|
|---|
| 817 | if ( isset( $bp->displayed_user->userdata->user_email ) )
|
|---|
| 818 | $retval = $bp->displayed_user->userdata->user_email;
|
|---|
| 819 | else
|
|---|
| 820 | $retval = '';
|
|---|
| 821 |
|
|---|
| 822 | return apply_filters( 'bp_get_displayed_user_email', esc_attr( $retval ) );
|
|---|
| 823 | }
|
|---|
| 824 |
|
|---|
| 825 | function bp_last_activity( $user_id = 0 ) {
|
|---|
| 826 | echo apply_filters( 'bp_last_activity', bp_get_last_activity( $user_id ) );
|
|---|
| 827 | }
|
|---|
| 828 | function bp_get_last_activity( $user_id = 0 ) {
|
|---|
| 829 | global $bp;
|
|---|
| 830 |
|
|---|
| 831 | if ( empty( $user_id ) )
|
|---|
| 832 | $user_id = $bp->displayed_user->id;
|
|---|
| 833 |
|
|---|
| 834 | $last_activity = bp_core_get_last_activity( bp_get_user_meta( $user_id, 'last_activity', true ), __('active %s', 'buddypress') );
|
|---|
| 835 |
|
|---|
| 836 | return apply_filters( 'bp_get_last_activity', $last_activity );
|
|---|
| 837 | }
|
|---|
| 838 |
|
|---|
| 839 | function bp_user_firstname() {
|
|---|
| 840 | echo bp_get_user_firstname();
|
|---|
| 841 | }
|
|---|
| 842 | function bp_get_user_firstname( $name = false ) {
|
|---|
| 843 | global $bp;
|
|---|
| 844 |
|
|---|
| 845 | // Try to get displayed user
|
|---|
| 846 | if ( empty( $name ) )
|
|---|
| 847 | $name = $bp->displayed_user->fullname;
|
|---|
| 848 |
|
|---|
| 849 | // Fall back on logged in user
|
|---|
| 850 | if ( empty( $name ) )
|
|---|
| 851 | $name = $bp->loggedin_user->fullname;
|
|---|
| 852 |
|
|---|
| 853 | $fullname = (array)explode( ' ', $name );
|
|---|
| 854 |
|
|---|
| 855 | return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
|
|---|
| 856 | }
|
|---|
| 857 |
|
|---|
| 858 | function bp_loggedin_user_link() {
|
|---|
| 859 | echo bp_get_loggedin_user_link();
|
|---|
| 860 | }
|
|---|
| 861 | function bp_get_loggedin_user_link() {
|
|---|
| 862 | return apply_filters( 'bp_get_loggedin_user_link', bp_loggedin_user_domain() );
|
|---|
| 863 | }
|
|---|
| 864 |
|
|---|
| 865 | function bp_displayed_user_link() {
|
|---|
| 866 | echo bp_get_displayed_user_link();
|
|---|
| 867 | }
|
|---|
| 868 | function bp_get_displayed_user_link() {
|
|---|
| 869 | return apply_filters( 'bp_get_displayed_user_link', bp_displayed_user_domain() );
|
|---|
| 870 | }
|
|---|
| 871 | function bp_user_link() { bp_displayed_user_domain(); } // Deprecated.
|
|---|
| 872 |
|
|---|
| 873 | function bp_displayed_user_id() {
|
|---|
| 874 | global $bp;
|
|---|
| 875 | return apply_filters( 'bp_displayed_user_id', !empty( $bp->displayed_user->id ) ? $bp->displayed_user->id : 0 );
|
|---|
| 876 | }
|
|---|
| 877 | function bp_current_user_id() { return bp_displayed_user_id(); }
|
|---|
| 878 |
|
|---|
| 879 | function bp_loggedin_user_id() {
|
|---|
| 880 | global $bp;
|
|---|
| 881 | return apply_filters( 'bp_loggedin_user_id', !empty( $bp->loggedin_user->id ) ? $bp->loggedin_user->id : 0 );
|
|---|
| 882 | }
|
|---|
| 883 |
|
|---|
| 884 | function bp_displayed_user_domain() {
|
|---|
| 885 | global $bp;
|
|---|
| 886 | return apply_filters( 'bp_displayed_user_domain', isset( $bp->displayed_user->domain ) ? $bp->displayed_user->domain : '' );
|
|---|
| 887 | }
|
|---|
| 888 |
|
|---|
| 889 | function bp_loggedin_user_domain() {
|
|---|
| 890 | global $bp;
|
|---|
| 891 | return apply_filters( 'bp_loggedin_user_domain', isset( $bp->loggedin_user->domain ) ? $bp->loggedin_user->domain : '' );
|
|---|
| 892 | }
|
|---|
| 893 |
|
|---|
| 894 | function bp_displayed_user_fullname() {
|
|---|
| 895 | echo bp_get_displayed_user_fullname();
|
|---|
| 896 | }
|
|---|
| 897 | function bp_get_displayed_user_fullname() {
|
|---|
| 898 | global $bp;
|
|---|
| 899 | return apply_filters( 'bp_displayed_user_fullname', isset( $bp->displayed_user->fullname ) ? $bp->displayed_user->fullname : '' );
|
|---|
| 900 | }
|
|---|
| 901 | function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
|
|---|
| 902 |
|
|---|
| 903 |
|
|---|
| 904 | function bp_loggedin_user_fullname() {
|
|---|
| 905 | echo bp_get_loggedin_user_fullname();
|
|---|
| 906 | }
|
|---|
| 907 | function bp_get_loggedin_user_fullname() {
|
|---|
| 908 | global $bp;
|
|---|
| 909 | return apply_filters( 'bp_get_loggedin_user_fullname', isset( $bp->loggedin_user->fullname ) ? $bp->loggedin_user->fullname : '' );
|
|---|
| 910 | }
|
|---|
| 911 |
|
|---|
| 912 | function bp_displayed_user_username() {
|
|---|
| 913 | echo bp_get_displayed_user_username();
|
|---|
| 914 | }
|
|---|
| 915 | function bp_get_displayed_user_username() {
|
|---|
| 916 | global $bp;
|
|---|
| 917 |
|
|---|
| 918 | if ( !empty( $bp->displayed_user->id ) ) {
|
|---|
| 919 | $username = bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login );
|
|---|
| 920 | } else {
|
|---|
| 921 | $username = '';
|
|---|
| 922 | }
|
|---|
| 923 |
|
|---|
| 924 | return apply_filters( 'bp_get_displayed_user_username', $username );
|
|---|
| 925 | }
|
|---|
| 926 |
|
|---|
| 927 | function bp_loggedin_user_username() {
|
|---|
| 928 | echo bp_get_loggedin_user_username();
|
|---|
| 929 | }
|
|---|
| 930 | function bp_get_loggedin_user_username() {
|
|---|
| 931 | global $bp;
|
|---|
| 932 |
|
|---|
| 933 | if ( !empty( $bp->loggedin_user->id ) ) {
|
|---|
| 934 | $username = bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login );
|
|---|
| 935 | } else {
|
|---|
| 936 | $username = '';
|
|---|
| 937 | }
|
|---|
| 938 |
|
|---|
| 939 | return apply_filters( 'bp_get_loggedin_user_username', $username );
|
|---|
| 940 | }
|
|---|
| 941 |
|
|---|
| 942 | /** Signup Form ***************************************************************/
|
|---|
| 943 |
|
|---|
| 944 | function bp_has_custom_signup_page() {
|
|---|
| 945 | if ( locate_template( array( 'register.php' ), false ) || locate_template( array( '/registration/register.php' ), false ) )
|
|---|
| 946 | return true;
|
|---|
| 947 |
|
|---|
| 948 | return false;
|
|---|
| 949 | }
|
|---|
| 950 |
|
|---|
| 951 | function bp_signup_page() {
|
|---|
| 952 | echo bp_get_signup_page();
|
|---|
| 953 | }
|
|---|
| 954 | function bp_get_signup_page() {
|
|---|
| 955 | global $bp;
|
|---|
| 956 |
|
|---|
| 957 | if ( bp_has_custom_signup_page() ) {
|
|---|
| 958 | $page = trailingslashit( bp_get_root_domain() . '/' . bp_get_signup_slug() );
|
|---|
| 959 | } else {
|
|---|
| 960 | $page = bp_get_root_domain() . '/wp-signup.php';
|
|---|
| 961 | }
|
|---|
| 962 |
|
|---|
| 963 | return apply_filters( 'bp_get_signup_page', $page );
|
|---|
| 964 | }
|
|---|
| 965 |
|
|---|
| 966 | function bp_has_custom_activation_page() {
|
|---|
| 967 | if ( locate_template( array( 'activate.php' ), false ) || locate_template( array( '/registration/activate.php' ), false ) )
|
|---|
| 968 | return true;
|
|---|
| 969 |
|
|---|
| 970 | return false;
|
|---|
| 971 | }
|
|---|
| 972 |
|
|---|
| 973 | function bp_activation_page() {
|
|---|
| 974 | echo bp_get_activation_page();
|
|---|
| 975 | }
|
|---|
| 976 | function bp_get_activation_page() {
|
|---|
| 977 | global $bp;
|
|---|
| 978 |
|
|---|
| 979 | if ( bp_has_custom_activation_page() )
|
|---|
| 980 | $page = trailingslashit( bp_get_root_domain() . '/' . $bp->pages->activate->slug );
|
|---|
| 981 | else
|
|---|
| 982 | $page = trailingslashit( bp_get_root_domain() ) . 'wp-activate.php';
|
|---|
| 983 |
|
|---|
| 984 | return apply_filters( 'bp_get_activation_page', $page );
|
|---|
| 985 | }
|
|---|
| 986 |
|
|---|
| 987 | function bp_signup_username_value() {
|
|---|
| 988 | echo bp_get_signup_username_value();
|
|---|
| 989 | }
|
|---|
| 990 | function bp_get_signup_username_value() {
|
|---|
| 991 | $value = '';
|
|---|
| 992 | if ( isset( $_POST['signup_username'] ) )
|
|---|
| 993 | $value = $_POST['signup_username'];
|
|---|
| 994 |
|
|---|
| 995 | return apply_filters( 'bp_get_signup_username_value', $value );
|
|---|
| 996 | }
|
|---|
| 997 |
|
|---|
| 998 | function bp_signup_email_value() {
|
|---|
| 999 | echo bp_get_signup_email_value();
|
|---|
| 1000 | }
|
|---|
| 1001 | function bp_get_signup_email_value() {
|
|---|
| 1002 | $value = '';
|
|---|
| 1003 | if ( isset( $_POST['signup_email'] ) )
|
|---|
| 1004 | $value = $_POST['signup_email'];
|
|---|
| 1005 |
|
|---|
| 1006 | return apply_filters( 'bp_get_signup_email_value', $value );
|
|---|
| 1007 | }
|
|---|
| 1008 |
|
|---|
| 1009 | function bp_signup_with_blog_value() {
|
|---|
| 1010 | echo bp_get_signup_with_blog_value();
|
|---|
| 1011 | }
|
|---|
| 1012 | function bp_get_signup_with_blog_value() {
|
|---|
| 1013 | $value = '';
|
|---|
| 1014 | if ( isset( $_POST['signup_with_blog'] ) )
|
|---|
| 1015 | $value = $_POST['signup_with_blog'];
|
|---|
| 1016 |
|
|---|
| 1017 | return apply_filters( 'bp_get_signup_with_blog_value', $value );
|
|---|
| 1018 | }
|
|---|
| 1019 |
|
|---|
| 1020 | function bp_signup_blog_url_value() {
|
|---|
| 1021 | echo bp_get_signup_blog_url_value();
|
|---|
| 1022 | }
|
|---|
| 1023 | function bp_get_signup_blog_url_value() {
|
|---|
| 1024 | $value = '';
|
|---|
| 1025 | if ( isset( $_POST['signup_blog_url'] ) )
|
|---|
| 1026 | $value = $_POST['signup_blog_url'];
|
|---|
| 1027 |
|
|---|
| 1028 | return apply_filters( 'bp_get_signup_blog_url_value', $value );
|
|---|
| 1029 | }
|
|---|
| 1030 |
|
|---|
| 1031 | function bp_signup_blog_title_value() {
|
|---|
| 1032 | echo bp_get_signup_blog_title_value();
|
|---|
| 1033 | }
|
|---|
| 1034 | function bp_get_signup_blog_title_value() {
|
|---|
| 1035 | $value = '';
|
|---|
| 1036 | if ( isset( $_POST['signup_blog_title'] ) )
|
|---|
| 1037 | $value = $_POST['signup_blog_title'];
|
|---|
| 1038 |
|
|---|
| 1039 | return apply_filters( 'bp_get_signup_blog_title_value', $value );
|
|---|
| 1040 | }
|
|---|
| 1041 |
|
|---|
| 1042 | function bp_signup_blog_privacy_value() {
|
|---|
| 1043 | echo bp_get_signup_blog_privacy_value();
|
|---|
| 1044 | }
|
|---|
| 1045 | function bp_get_signup_blog_privacy_value() {
|
|---|
| 1046 | $value = '';
|
|---|
| 1047 | if ( isset( $_POST['signup_blog_privacy'] ) )
|
|---|
| 1048 | $value = $_POST['signup_blog_privacy'];
|
|---|
| 1049 |
|
|---|
| 1050 | return apply_filters( 'bp_get_signup_blog_privacy_value', $value );
|
|---|
| 1051 | }
|
|---|
| 1052 |
|
|---|
| 1053 | function bp_signup_avatar_dir_value() {
|
|---|
| 1054 | echo bp_get_signup_avatar_dir_value();
|
|---|
| 1055 | }
|
|---|
| 1056 | function bp_get_signup_avatar_dir_value() {
|
|---|
| 1057 | global $bp;
|
|---|
| 1058 |
|
|---|
| 1059 | // Check if signup_avatar_dir is passed
|
|---|
| 1060 | if ( !empty( $_POST['signup_avatar_dir'] ) )
|
|---|
| 1061 | $signup_avatar_dir = $_POST['signup_avatar_dir'];
|
|---|
| 1062 |
|
|---|
| 1063 | // If not, check if global is set
|
|---|
| 1064 | elseif ( !empty( $bp->signup->avatar_dir ) )
|
|---|
| 1065 | $signup_avatar_dir = $bp->signup->avatar_dir;
|
|---|
| 1066 |
|
|---|
| 1067 | // If not, set false
|
|---|
| 1068 | else
|
|---|
| 1069 | $signup_avatar_dir = false;
|
|---|
| 1070 |
|
|---|
| 1071 | return apply_filters( 'bp_get_signup_avatar_dir_value', $bp->signup->avatar_dir );
|
|---|
| 1072 | }
|
|---|
| 1073 |
|
|---|
| 1074 | function bp_current_signup_step() {
|
|---|
| 1075 | echo bp_get_current_signup_step();
|
|---|
| 1076 | }
|
|---|
| 1077 | function bp_get_current_signup_step() {
|
|---|
| 1078 | global $bp;
|
|---|
| 1079 |
|
|---|
| 1080 | return $bp->signup->step;
|
|---|
| 1081 | }
|
|---|
| 1082 |
|
|---|
| 1083 | function bp_signup_avatar( $args = '' ) {
|
|---|
| 1084 | echo bp_get_signup_avatar( $args );
|
|---|
| 1085 | }
|
|---|
| 1086 | function bp_get_signup_avatar( $args = '' ) {
|
|---|
| 1087 | global $bp;
|
|---|
| 1088 |
|
|---|
| 1089 | $defaults = array(
|
|---|
| 1090 | 'size' => bp_core_avatar_full_width(),
|
|---|
| 1091 | 'class' => 'avatar',
|
|---|
| 1092 | 'alt' => __( 'Your Avatar', 'buddypress' )
|
|---|
| 1093 | );
|
|---|
| 1094 |
|
|---|
| 1095 | $r = wp_parse_args( $args, $defaults );
|
|---|
| 1096 | extract( $r, EXTR_SKIP );
|
|---|
| 1097 |
|
|---|
| 1098 | // Avatar DIR is found
|
|---|
| 1099 | if ( $signup_avatar_dir = bp_get_signup_avatar_dir_value() ) {
|
|---|
| 1100 | $gravatar_img = bp_core_fetch_avatar( array(
|
|---|
| 1101 | 'item_id' => $signup_avatar_dir,
|
|---|
| 1102 | 'object' => 'signup',
|
|---|
| 1103 | 'avatar_dir' => 'avatars/signups',
|
|---|
| 1104 | 'type' => 'full',
|
|---|
| 1105 | 'width' => $size,
|
|---|
| 1106 | 'height' => $size,
|
|---|
| 1107 | 'alt' => $alt,
|
|---|
| 1108 | 'class' => $class
|
|---|
| 1109 | ) );
|
|---|
| 1110 |
|
|---|
| 1111 | // No avatar DIR was found
|
|---|
| 1112 | } else {
|
|---|
| 1113 |
|
|---|
| 1114 | // Set default gravatar type
|
|---|
| 1115 | if ( empty( $bp->grav_default->user ) )
|
|---|
| 1116 | $default_grav = 'wavatar';
|
|---|
| 1117 | else if ( 'mystery' == $bp->grav_default->user )
|
|---|
| 1118 | $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
|
|---|
| 1119 | else
|
|---|
| 1120 | $default_grav = $bp->grav_default->user;
|
|---|
| 1121 |
|
|---|
| 1122 | // Create
|
|---|
| 1123 | $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
|
|---|
| 1124 | $md5_lcase_email = md5( strtolower( bp_get_signup_email_value() ) );
|
|---|
| 1125 | $gravatar_img = '<img src="' . $gravatar_url . $md5_lcase_email . '?d=' . $default_grav . '&s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
|
|---|
| 1126 | }
|
|---|
| 1127 |
|
|---|
| 1128 | return apply_filters( 'bp_get_signup_avatar', $gravatar_img, $args );
|
|---|
| 1129 | }
|
|---|
| 1130 |
|
|---|
| 1131 | function bp_signup_allowed() {
|
|---|
| 1132 | echo bp_get_signup_allowed();
|
|---|
| 1133 | }
|
|---|
| 1134 | function bp_get_signup_allowed() {
|
|---|
| 1135 | global $bp;
|
|---|
| 1136 |
|
|---|
| 1137 | $signup_allowed = false;
|
|---|
| 1138 |
|
|---|
| 1139 | if ( is_multisite() ) {
|
|---|
| 1140 | if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) )
|
|---|
| 1141 | $signup_allowed = true;
|
|---|
| 1142 |
|
|---|
| 1143 | } else {
|
|---|
| 1144 | if ( get_option( 'users_can_register') )
|
|---|
| 1145 | $signup_allowed = true;
|
|---|
| 1146 | }
|
|---|
| 1147 |
|
|---|
| 1148 | return apply_filters( 'bp_get_signup_allowed', $signup_allowed );
|
|---|
| 1149 | }
|
|---|
| 1150 |
|
|---|
| 1151 | /**
|
|---|
| 1152 | * Hook member activity feed to <head>
|
|---|
| 1153 | *
|
|---|
| 1154 | * @since 1.5
|
|---|
| 1155 | */
|
|---|
| 1156 | function bp_members_activity_feed() {
|
|---|
| 1157 | if ( !bp_is_active( 'activity' ) || !bp_is_user() )
|
|---|
| 1158 | return; ?>
|
|---|
| 1159 |
|
|---|
| 1160 | <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() ?>" />
|
|---|
| 1161 |
|
|---|
| 1162 | <?php
|
|---|
| 1163 | }
|
|---|
| 1164 | add_action( 'bp_head', 'bp_members_activity_feed' );
|
|---|
| 1165 |
|
|---|
| 1166 |
|
|---|
| 1167 | function bp_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
|
|---|
| 1168 | echo bp_get_members_component_link( $component, $action, $query_args, $nonce );
|
|---|
| 1169 | }
|
|---|
| 1170 | function bp_get_members_component_link( $component, $action = '', $query_args = '', $nonce = false ) {
|
|---|
| 1171 | global $bp;
|
|---|
| 1172 |
|
|---|
| 1173 | // Must be displayed user
|
|---|
| 1174 | if ( empty( $bp->displayed_user->id ) )
|
|---|
| 1175 | return;
|
|---|
| 1176 |
|
|---|
| 1177 | // Append $action to $url if there is no $type
|
|---|
| 1178 | if ( !empty( $action ) )
|
|---|
| 1179 | $url = $bp->displayed_user->domain . $bp->{$component}->slug . '/' . $action;
|
|---|
| 1180 | else
|
|---|
| 1181 | $url = $bp->displayed_user->domain . $bp->{$component}->slug;
|
|---|
| 1182 |
|
|---|
| 1183 | // Add a slash at the end of our user url
|
|---|
| 1184 | $url = trailingslashit( $url );
|
|---|
| 1185 |
|
|---|
| 1186 | // Add possible query arg
|
|---|
| 1187 | if ( !empty( $query_args ) && is_array( $query_args ) )
|
|---|
| 1188 | $url = add_query_arg( $query_args, $url );
|
|---|
| 1189 |
|
|---|
| 1190 | // To nonce, or not to nonce...
|
|---|
| 1191 | if ( true === $nonce )
|
|---|
| 1192 | $url = wp_nonce_url( $url );
|
|---|
| 1193 | elseif ( is_string( $nonce ) )
|
|---|
| 1194 | $url = wp_nonce_url( $url, $nonce );
|
|---|
| 1195 |
|
|---|
| 1196 | // Return the url, if there is one
|
|---|
| 1197 | if ( !empty( $url ) )
|
|---|
| 1198 | return $url;
|
|---|
| 1199 | }
|
|---|
| 1200 |
|
|---|
| 1201 | ?>
|
|---|