[ 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 Friends
   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( 'widgets_init', function() { register_widget( 'BP_Core_Friends_Widget' ); } );
  31  }
  32  add_action( 'bp_register_widgets', 'bp_friends_register_widgets' );
  33  
  34  /** Widget AJAX ***************************************************************/
  35  
  36  /**
  37   * Process AJAX pagination or filtering for the Friends widget.
  38   *
  39   * @since 1.9.0
  40   */
  41  function bp_core_ajax_widget_friends() {
  42  
  43      check_ajax_referer( 'bp_core_widget_friends' );
  44  
  45      switch ( $_POST['filter'] ) {
  46          case 'newest-friends':
  47              $type = 'newest';
  48              break;
  49  
  50          case 'recently-active-friends':
  51              $type = 'active';
  52              break;
  53  
  54          case 'popular-friends':
  55              $type = 'popular';
  56              break;
  57      }
  58  
  59      $members_args = array(
  60          'user_id'         => bp_displayed_user_id(),
  61          'type'            => $type,
  62          'max'             => absint( $_POST['max-friends'] ),
  63          'populate_extras' => 1,
  64      );
  65  
  66      if ( bp_has_members( $members_args ) ) : ?>
  67          <?php echo '0[[SPLIT]]'; // Return valid result. TODO: remove this. ?>
  68          <?php while ( bp_members() ) : bp_the_member(); ?>
  69              <li class="vcard">
  70                  <div class="item-avatar">
  71                      <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
  72                  </div>
  73  
  74                  <div class="item">
  75                      <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div>
  76                      <?php if ( 'active' == $type ) : ?>
  77                          <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>
  78                      <?php elseif ( 'newest' == $type ) : ?>
  79                          <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>
  80                      <?php elseif ( bp_is_active( 'friends' ) ) : ?>
  81                          <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count(); ?></span></div>
  82                      <?php endif; ?>
  83                  </div>
  84              </li>
  85          <?php endwhile; ?>
  86  
  87      <?php else: ?>
  88          <?php echo "-1[[SPLIT]]<li>"; ?>
  89          <?php _e( 'There were no members found, please try another filter.', 'buddypress' ); ?>
  90          <?php echo "</li>"; ?>
  91      <?php endif;
  92  }
  93  add_action( 'wp_ajax_widget_friends', 'bp_core_ajax_widget_friends' );
  94  add_action( 'wp_ajax_nopriv_widget_friends', 'bp_core_ajax_widget_friends' );


Generated: Wed Jul 17 01:01:40 2019 Cross-referenced by PHPXref 0.7.1