[ 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( 'widgets_init', function() { return register_widget( 'BP_Core_Members_Widget' );         } );
  22      add_action( 'widgets_init', function() { return register_widget( 'BP_Core_Whos_Online_Widget' );     } );
  23      add_action( 'widgets_init', function() { return register_widget( 'BP_Core_Recently_Active_Widget' ); } );
  24  }
  25  add_action( 'bp_register_widgets', 'bp_members_register_widgets' );
  26  
  27  /**
  28   * AJAX request handler for Members widgets.
  29   *
  30   * @since 1.0.0
  31   *
  32   * @see BP_Core_Members_Widget
  33   */
  34  function bp_core_ajax_widget_members() {
  35  
  36      check_ajax_referer( 'bp_core_widget_members' );
  37  
  38      // Setup some variables to check.
  39      $filter      = ! empty( $_POST['filter']      ) ? $_POST['filter']                : 'recently-active-members';
  40      $max_members = ! empty( $_POST['max-members'] ) ? absint( $_POST['max-members'] ) : 5;
  41  
  42      // Determine the type of members query to perform.
  43      switch ( $filter ) {
  44  
  45          // Newest activated.
  46          case 'newest-members' :
  47              $type = 'newest';
  48              break;
  49  
  50          // Popular by friends.
  51          case 'popular-members' :
  52              if ( bp_is_active( 'friends' ) ) {
  53                  $type = 'popular';
  54              } else {
  55                  $type = 'active';
  56              }
  57              break;
  58  
  59          // Default.
  60          case 'recently-active-members' :
  61          default :
  62              $type = 'active';
  63              break;
  64      }
  65  
  66      // Setup args for querying members.
  67      $members_args = array(
  68          'user_id'         => 0,
  69          'type'            => $type,
  70          'per_page'        => $max_members,
  71          'max'             => $max_members,
  72          'populate_extras' => true,
  73          'search_terms'    => false,
  74      );
  75  
  76      // Query for members.
  77      if ( bp_has_members( $members_args ) ) : ?>
  78          <?php echo '0[[SPLIT]]'; // Return valid result. TODO: remove this. ?>
  79          <?php while ( bp_members() ) : bp_the_member(); ?>
  80              <li class="vcard">
  81                  <div class="item-avatar">
  82                      <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
  83                  </div>
  84  
  85                  <div class="item">
  86                      <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div>
  87                      <?php if ( 'active' === $type ) : ?>
  88                          <div class="item-meta"><span class="activity"><?php bp_member_last_active(); ?></span></div>
  89                      <?php elseif ( 'newest' === $type ) : ?>
  90                          <div class="item-meta"><span class="activity"><?php bp_member_registered(); ?></span></div>
  91                      <?php elseif ( bp_is_active( 'friends' ) ) : ?>
  92                          <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count(); ?></span></div>
  93                      <?php endif; ?>
  94                  </div>
  95              </li>
  96  
  97          <?php endwhile; ?>
  98  
  99      <?php else: ?>
 100          <?php echo "-1[[SPLIT]]<li>"; ?>
 101          <?php esc_html_e( 'There were no members found, please try another filter.', 'buddypress' ) ?>
 102          <?php echo "</li>"; ?>
 103      <?php endif;
 104  }
 105  add_action( 'wp_ajax_widget_members',        'bp_core_ajax_widget_members' );
 106  add_action( 'wp_ajax_nopriv_widget_members', 'bp_core_ajax_widget_members' );


Generated: Mon Jul 15 01:01:40 2019 Cross-referenced by PHPXref 0.7.1