[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/ -> bp-members-widgets.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Members Widgets.
   4   *
   5   * @package BuddyPress
   6   * @subpackage MembersWidgets
   7   * @since 2.2.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Register bp-members widgets.
  15   *
  16   * Previously, these widgets were registered in bp-core.
  17   *
  18   * @since 2.2.0
  19   */
  20  function bp_members_register_widgets() {
  21      add_action(
  22          'widgets_init',
  23          function() {
  24              return register_widget( 'BP_Core_Members_Widget' );
  25          }
  26      );
  27  
  28      add_action(
  29          'widgets_init',
  30          function() {
  31              return register_widget( 'BP_Core_Whos_Online_Widget' );
  32          }
  33      );
  34  
  35      add_action(
  36          'widgets_init',
  37          function() {
  38              return register_widget( 'BP_Core_Recently_Active_Widget' );
  39          }
  40      );
  41  }
  42  add_action( 'bp_register_widgets', 'bp_members_register_widgets' );
  43  
  44  /**
  45   * AJAX request handler for Members widgets.
  46   *
  47   * @since 1.0.0
  48   *
  49   * @see BP_Core_Members_Widget
  50   */
  51  function bp_core_ajax_widget_members() {
  52  
  53      check_ajax_referer( 'bp_core_widget_members' );
  54  
  55      // Setup some variables to check.
  56      $filter      = ! empty( $_POST['filter']      ) ? $_POST['filter']                : 'recently-active-members';
  57      $max_members = ! empty( $_POST['max-members'] ) ? absint( $_POST['max-members'] ) : 5;
  58  
  59      // Determine the type of members query to perform.
  60      switch ( $filter ) {
  61  
  62          // Newest activated.
  63          case 'newest-members' :
  64              $type = 'newest';
  65              break;
  66  
  67          // Popular by friends.
  68          case 'popular-members' :
  69              if ( bp_is_active( 'friends' ) ) {
  70                  $type = 'popular';
  71              } else {
  72                  $type = 'active';
  73              }
  74              break;
  75  
  76          // Default.
  77          case 'recently-active-members' :
  78          default :
  79              $type = 'active';
  80              break;
  81      }
  82  
  83      // Setup args for querying members.
  84      $members_args = array(
  85          'user_id'         => 0,
  86          'type'            => $type,
  87          'per_page'        => $max_members,
  88          'max'             => $max_members,
  89          'populate_extras' => true,
  90          'search_terms'    => false,
  91      );
  92  
  93      // Query for members.
  94      if ( bp_has_members( $members_args ) ) : ?>
  95          <?php echo '0[[SPLIT]]'; // Return valid result. TODO: remove this. ?>
  96          <?php while ( bp_members() ) : bp_the_member(); ?>
  97              <li class="vcard">
  98                  <div class="item-avatar">
  99                      <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
 100                  </div>
 101  
 102                  <div class="item">
 103                      <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div>
 104                      <?php if ( 'active' === $type ) : ?>
 105                          <div class="item-meta"><span class="activity"><?php bp_member_last_active(); ?></span></div>
 106                      <?php elseif ( 'newest' === $type ) : ?>
 107                          <div class="item-meta"><span class="activity"><?php bp_member_registered(); ?></span></div>
 108                      <?php elseif ( bp_is_active( 'friends' ) ) : ?>
 109                          <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count(); ?></span></div>
 110                      <?php endif; ?>
 111                  </div>
 112              </li>
 113  
 114          <?php endwhile; ?>
 115  
 116      <?php else: ?>
 117          <?php echo "-1[[SPLIT]]<li>"; ?>
 118          <?php esc_html_e( 'There were no members found, please try another filter.', 'buddypress' ) ?>
 119          <?php echo "</li>"; ?>
 120      <?php endif;
 121  }
 122  add_action( 'wp_ajax_widget_members', 'bp_core_ajax_widget_members' );
 123  add_action( 'wp_ajax_nopriv_widget_members', 'bp_core_ajax_widget_members' );


Generated: Tue Oct 26 01:00:55 2021 Cross-referenced by PHPXref 0.7.1