[ 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   * Registers the Groups Legacy Widget.
  15   *
  16   * @since 10.0.0
  17   */
  18  function bp_groups_register_groups_widget() {
  19      register_widget( 'BP_Groups_Widget' );
  20  }
  21  
  22  /**
  23   * Register widgets for groups component.
  24   *
  25   * @since 1.0.0
  26   */
  27  function groups_register_widgets() {
  28      add_action( 'widgets_init', 'bp_groups_register_groups_widget' );
  29  }
  30  add_action( 'bp_register_widgets', 'groups_register_widgets' );
  31  
  32  /**
  33   * AJAX callback for the Groups List widget.
  34   *
  35   * @since 1.0.0
  36   */
  37  function groups_ajax_widget_groups_list() {
  38  
  39      check_ajax_referer( 'groups_widget_groups_list' );
  40  
  41      switch ( $_POST['filter'] ) {
  42          case 'newest-groups':
  43              $type = 'newest';
  44          break;
  45          case 'recently-active-groups':
  46              $type = 'active';
  47          break;
  48          case 'popular-groups':
  49              $type = 'popular';
  50          break;
  51          case 'alphabetical-groups':
  52              $type = 'alphabetical';
  53          break;
  54      }
  55  
  56      $per_page = isset( $_POST['max_groups'] ) ? intval( $_POST['max_groups'] ) : 5;
  57  
  58      $groups_args = array(
  59          'user_id'  => 0,
  60          'type'     => $type,
  61          'per_page' => $per_page,
  62          'max'      => $per_page,
  63      );
  64  
  65      if ( bp_has_groups( $groups_args ) ) : ?>
  66          <?php echo "0[[SPLIT]]"; ?>
  67          <?php while ( bp_groups() ) : bp_the_group(); ?>
  68              <li <?php bp_group_class(); ?>>
  69                  <div class="item-avatar">
  70                      <a href="<?php bp_group_permalink() ?>"><?php bp_group_avatar_thumb() ?></a>
  71                  </div>
  72  
  73                  <div class="item">
  74                      <div class="item-title"><?php bp_group_link(); ?></div>
  75                      <div class="item-meta">
  76                          <?php if ( 'newest-groups' === $_POST['filter'] ) : ?>
  77                              <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_group_date_created( 0, array( 'relative' => false ) ) ); ?>">
  78                                  <?php
  79                                  /* translators: %s: date */
  80                                  printf( __( 'created %s', 'buddypress' ), bp_get_group_date_created() );
  81                                  ?>
  82                              </span>
  83                          <?php elseif ( 'popular-groups' === $_POST['filter'] ) : ?>
  84                              <span class="activity"><?php bp_group_member_count(); ?></span>
  85                          <?php else : ?>
  86                              <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_group_last_active( 0, array( 'relative' => false ) ) ); ?>">
  87                                  <?php
  88                                  /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */
  89                                  printf( _x( 'Active %s', 'last time the group was active', 'buddypress' ), bp_get_group_last_active() );
  90                                  ?>
  91                              </span>
  92                          <?php endif; ?>
  93                      </div>
  94                  </div>
  95              </li>
  96          <?php endwhile; ?>
  97  
  98          <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?>
  99          <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo esc_attr( $_POST['max_groups'] ); ?>" />
 100  
 101      <?php else: ?>
 102  
 103          <?php echo "-1[[SPLIT]]<li>" . __( "No groups matched the current filter.", 'buddypress' ); ?>
 104  
 105      <?php endif;
 106  
 107  }
 108  add_action( 'wp_ajax_widget_groups_list',        'groups_ajax_widget_groups_list' );
 109  add_action( 'wp_ajax_nopriv_widget_groups_list', 'groups_ajax_widget_groups_list' );


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1