[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Friends Widgets.
   4   *
   5   * @package BuddyPress
   6   * @subpackage FriendsWidgets
   7   * @since 1.9.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Register the friends widget.
  15   *
  16   * @since 1.9.0
  17   */
  18  function bp_friends_register_widgets() {
  19      if ( ! bp_is_active( 'friends' ) ) {
  20          return;
  21      }
  22  
  23      // The Friends widget works only when looking an a displayed user,
  24      // and the concept of "displayed user" doesn't exist on non-root blogs,
  25      // so we don't register the widget there.
  26      if ( ! bp_is_root_blog() ) {
  27          return;
  28      }
  29  
  30      add_action(
  31          'widgets_init',
  32          function() {
  33              register_widget( 'BP_Core_Friends_Widget' );
  34          }
  35      );
  36  }
  37  add_action( 'bp_register_widgets', 'bp_friends_register_widgets' );
  38  
  39  /** Widget AJAX ***************************************************************/
  40  
  41  /**
  42   * Process AJAX pagination or filtering for the Friends widget.
  43   *
  44   * @since 1.9.0
  45   */
  46  function bp_core_ajax_widget_friends() {
  47  
  48      check_ajax_referer( 'bp_core_widget_friends' );
  49  
  50      switch ( $_POST['filter'] ) {
  51          case 'newest-friends':
  52              $type = 'newest';
  53              break;
  54  
  55          case 'recently-active-friends':
  56              $type = 'active';
  57              break;
  58  
  59          case 'popular-friends':
  60              $type = 'popular';
  61              break;
  62      }
  63  
  64      $members_args = array(
  65          'user_id'         => bp_displayed_user_id(),
  66          'type'            => $type,
  67          'max'             => absint( $_POST['max-friends'] ),
  68          'populate_extras' => 1,
  69      );
  70  
  71      if ( bp_has_members( $members_args ) ) : ?>
  72          <?php echo '0[[SPLIT]]'; // Return valid result. TODO: remove this. ?>
  73          <?php while ( bp_members() ) : bp_the_member(); ?>
  74              <li class="vcard">
  75                  <div class="item-avatar">
  76                      <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
  77                  </div>
  78  
  79                  <div class="item">
  80                      <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div>
  81                      <?php if ( 'active' == $type ) : ?>
  82                          <div class="item-meta"><span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_last_active( array( 'relative' => false ) ) ); ?>"><?php bp_member_last_active(); ?></span></div>
  83                      <?php elseif ( 'newest' == $type ) : ?>
  84                          <div class="item-meta"><span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_registered( array( 'relative' => false ) ) ); ?>"><?php bp_member_registered(); ?></span></div>
  85                      <?php elseif ( bp_is_active( 'friends' ) ) : ?>
  86                          <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count(); ?></span></div>
  87                      <?php endif; ?>
  88                  </div>
  89              </li>
  90          <?php endwhile; ?>
  91  
  92      <?php else: ?>
  93          <?php echo "-1[[SPLIT]]<li>"; ?>
  94          <?php esc_html_e( 'There were no members found, please try another filter.', 'buddypress' ); ?>
  95          <?php echo "</li>"; ?>
  96      <?php endif;
  97  }
  98  add_action( 'wp_ajax_widget_friends', 'bp_core_ajax_widget_friends' );
  99  add_action( 'wp_ajax_nopriv_widget_friends', 'bp_core_ajax_widget_friends' );


Generated: Thu Oct 28 01:00:59 2021 Cross-referenced by PHPXref 0.7.1