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


Generated: Fri May 20 01:00:54 2022 Cross-referenced by PHPXref 0.7.1