Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function bp_enhanced_widgets_popular_init() {
- add_action('widgets_init', create_function('', 'return register_widget("BP_Enhanced_Groups_Widget_Popular");') );
- }
- add_action( 'plugins_loaded', 'bp_enhanced_widgets_popular_init', 15 );
- class BP_Enhanced_Groups_Widget_Popular extends WP_Widget {
- function bp_enhanced_groups_widget_popular() {
- parent::WP_Widget( false, $name = __( 'Most Popular Resturants', 'buddypress' ) );
- if ( is_active_widget( false, false, $this->id_base ) )
- wp_enqueue_script( 'groups_widget_groups_list-js', BP_PLUGIN_URL . 'widget-groups-popular.js', array('jquery') );
- }
- function widget($args, $instance) {
- global $bp;
- extract( $args );
- echo $before_widget;
- echo $before_title
- . $widget_name
- . $after_title; ?>
- <?php if ( bp_has_groups( 'type=' . $instance['group_default'] . '&max=' . $instance['max_groups'] ) ) : ?>
- <ul id="groups-list" class="item-list">
- <?php while ( bp_groups() ) : bp_the_group(); ?>
- <li>
- <div class="item-avatar">
- <a href="<?php bp_group_permalink() ?>"><?php bp_group_avatar_thumb() ?></a>
- </div>
- <div class="item">
- <div class="item-title"><a href="<?php bp_group_permalink() ?>" title="<?php bp_group_name() ?>"><?php bp_group_name() ?></a></div>
- <div class="item-meta"><span class="activity">
- <?php
- if ( $instance['group_default'] == 'newest') {
- echo "Created " . bp_get_group_date_created() . " ago";
- }
- if ( $instance['group_default'] == 'active')
- echo bp_get_group_last_active();
- if ( $instance['group_default'] == 'popular')
- echo bp_group_member_count();
- ?></span></div>
- </div>
- </li>
- <?php endwhile; ?>
- </ul>
- <?php wp_nonce_field( 'groups_widget_groups_list', '_wpnonce-groups' ); ?>
- <input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php echo attribute_escape( $instance['max_groups'] ); ?>" />
- <?php else: ?>
- <div class="widget-error">
- <?php _e('There are no resturants to display.', 'buddypress') ?>
- </div>
- <?php endif; ?>
- <?php echo $after_widget; ?>
- <?php
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['max_groups'] = strip_tags( $new_instance['max_groups'] );
- $instance['group_default'] = strip_tags( $new_instance['group_default'] );
- return $instance;
- }
- function form( $instance ) {
- $instance = wp_parse_args( (array) $instance, array( 'max_groups' => 5, 'group_default' => 'popular' ) );
- $max_groups = strip_tags( $instance['max_groups'] );
- $group_default = strip_tags( $instance['group_default'] );
- ?>
- <p><label for="bp-groups-widget-groups-max"><?php _e('Max groups to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_groups' ); ?>" name="<?php echo $this->get_field_name( 'max_groups' ); ?>" type="text" value="<?php echo attribute_escape( $max_groups ); ?>" style="width: 30%" /></label></p>
- <p><label for="bp-groups-widget-groups-default"><?php _e('Default groups to show:', 'buddypress'); ?> <br />
- <input id="<?php echo $this->get_field_id( 'group_default' )-newest; ?>" name="<?php echo $this->get_field_name( 'group_default' ); ?>" type="radio" value="newest" <?php if ($group_default == "newest") echo "checked"; ?> /></label> Newest<br />
- <input id="<?php echo $this->get_field_id( 'group_default' )-active; ?>" name="<?php echo $this->get_field_name( 'group_default' ); ?>" type="radio" value="active" <?php if ($group_default == "active") echo "checked"; ?>/></label> Recently Active<br />
- <input id="<?php echo $this->get_field_id( 'group_default' )-popular; ?>" name="<?php echo $this->get_field_name( 'group_default' ); ?>" type="radio" value="popular" <?php if ($group_default == "popular") echo "checked"; ?>/></label> Popular
- </p>
- <?php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment