[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Groups Widgets
   4   *
   5   * @package BuddyPress
   6   * @subpackage GroupsWidgets
   7   * @since 1.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Register widgets for groups component.
  15   *
  16   * @since 1.0.0
  17   */
  18  function groups_register_widgets() {
  19      add_action( 'widgets_init', function() { register_widget( 'BP_Groups_Widget' ); } );
  20  }
  21  add_action( 'bp_register_widgets', 'groups_register_widgets' );
  22  
  23  /**
  24   * AJAX callback for the Groups List widget.
  25   *
  26   * @since 1.0.0
  27   */
  28  function groups_ajax_widget_groups_list() {
  29  
  30      check_ajax_referer( 'groups_widget_groups_list' );
  31  
  32      switch ( $_POST['filter'] ) {
  33          case 'newest-groups':
  34              $type = 'newest';
  35          break;
  36          case 'recently-active-groups':
  37              $type = 'active';
  38          break;
  39          case 'popular-groups':
  40              $type = 'popular';
  41          break;
  42          case 'alphabetical-groups':
  43              $type = 'alphabetical';
  44          break;
  45      }
  46  
  47      $per_page = isset( $_POST['max_groups'] ) ? intval( $_POST['max_groups'] ) : 5;
  48  
  49      $groups_args = array(
  50          'user_id'  => 0,
  51          'type'     => $type,
  52          'per_page' => $per_page,
  53          'max'      => $per_page,
  54      );
  55  
  56      if ( bp_has_groups( $groups_args ) ) : ?>
  57          <?php echo "0[[SPLIT]]"; ?>
  58          <?php while ( bp_groups() ) : bp_the_group(); ?>
  59              <li <?php bp_group_class(); ?>>
  60                  <div class="item-avatar">
  61                      <a href="<?php bp_group_permalink() ?>"><?php bp_group_avatar_thumb() ?></a>
  62                  </div>
  63  
  64                  <div class="item">
  65                      <div class="item-title"><?php bp_group_link(); ?></div>
  66                      <div class="item-meta">
  67                          <?php if ( 'newest-groups' === $_POST['filter'] ) : ?>
  68                              <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_group_date_created( 0, array( 'relative' => false ) ) ); ?>"><?php printf( __( 'created %s', 'buddypress' ), bp_get_group_date_created() ); ?></span>
  69                          <?php elseif ( 'popular-groups' === $_POST['filter'] ) : ?>
  70                              <span class="activity"><?php bp_group_member_count(); ?></span>
  71                          <?php else : ?>
  72                              <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_group_last_active( 0, array( 'relative' => false ) ) ); ?>"><?php printf( __( 'active %s', 'buddypress' ), bp_get_group_last_active() ); ?></span>
  73                          <?php endif; ?>
  74                      </div>
  75                  </div>
  76              </li>
  77          <?php endwhile; ?>
  78  
  79          <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?>
  80          <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo esc_attr( $_POST['max_groups'] ); ?>" />
  81  
  82      <?php else: ?>
  83  
  84          <?php echo "-1[[SPLIT]]<li>" . __( "No groups matched the current filter.", 'buddypress' ); ?>
  85  
  86      <?php endif;
  87  
  88  }
  89  add_action( 'wp_ajax_widget_groups_list',        'groups_ajax_widget_groups_list' );
  90  add_action( 'wp_ajax_nopriv_widget_groups_list', 'groups_ajax_widget_groups_list' );


Generated: Wed Jul 24 01:01:43 2019 Cross-referenced by PHPXref 0.7.1