bp_core_ajax_widget_members

AJAX request handler for Members widgets.

Description

bp_core_ajax_widget_members(); 

Usage

  1. if ( !function_exists( 'bp_core_ajax_widget_members' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-widgets.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_core_ajax_widget_members(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-members/bp-members-widgets.php  
  1. function bp_core_ajax_widget_members() { 
  2.  
  3. check_ajax_referer( 'bp_core_widget_members' ); 
  4.  
  5. // Setup some variables to check. 
  6. $filter = ! empty( $_POST['filter'] ) ? $_POST['filter'] : 'recently-active-members'; 
  7. $max_members = ! empty( $_POST['max-members'] ) ? absint( $_POST['max-members'] ) : 5; 
  8.  
  9. // Determine the type of members query to perform. 
  10. switch ( $filter ) { 
  11.  
  12. // Newest activated. 
  13. case 'newest-members' : 
  14. $type = 'newest'; 
  15. break; 
  16.  
  17. // Popular by friends. 
  18. case 'popular-members' : 
  19. if ( bp_is_active( 'friends' ) ) { 
  20. $type = 'popular'; 
  21. } else { 
  22. $type = 'active'; 
  23. break; 
  24.  
  25. // Default. 
  26. case 'recently-active-members' : 
  27. default : 
  28. $type = 'active'; 
  29. break; 
  30.  
  31. // Setup args for querying members. 
  32. $members_args = array( 
  33. 'user_id' => 0,  
  34. 'type' => $type,  
  35. 'per_page' => $max_members,  
  36. 'max' => $max_members,  
  37. 'populate_extras' => true,  
  38. 'search_terms' => false,  
  39. ); 
  40.  
  41. // Query for members. 
  42. if ( bp_has_members( $members_args ) ) : ?> 
  43. <?php echo '0[[SPLIT]]'; // Return valid result. TODO: remove this. ?> 
  44. <?php while ( bp_members() ) : bp_the_member(); ?> 
  45. <li class="vcard"> 
  46. <div class="item-avatar"> 
  47. <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a> 
  48. </div> 
  49.  
  50. <div class="item"> 
  51. <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div> 
  52. <?php if ( 'active' === $type ) : ?> 
  53. <div class="item-meta"><span class="activity"><?php bp_member_last_active(); ?></span></div> 
  54. <?php elseif ( 'newest' === $type ) : ?> 
  55. <div class="item-meta"><span class="activity"><?php bp_member_registered(); ?></span></div> 
  56. <?php elseif ( bp_is_active( 'friends' ) ) : ?> 
  57. <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count(); ?></span></div> 
  58. <?php endif; ?> 
  59. </div> 
  60. </li> 
  61.  
  62. <?php endwhile; ?> 
  63.  
  64. <?php else: ?> 
  65. <?php echo "-1[[SPLIT]]<li>"; ?> 
  66. <?php esc_html_e( 'There were no members found, please try another filter.', buddypress ) ?> 
  67. <?php echo "</li>"; ?> 
  68. <?php endif;