Advertisement
abysshorror

BuddyPress Following / Followers widgets

Dec 9th, 2011
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.86 KB | None | 0 0
  1. <?php
  2. /**
  3.  * BP Follow Widgets
  4.  *
  5.  * @package BP-Follow
  6.  * @subpackage Widgets
  7.  */
  8.  
  9. // Exit if accessed directly
  10. if ( !defined( 'ABSPATH' ) ) exit;
  11.  
  12. /**
  13.  * Add a "Users I'm following" widget for the logged-in user
  14.  *
  15.  * @subpackage Widgets
  16.  */
  17. class BP_Follow_Following_Widget extends WP_Widget {
  18.     function bp_follow_following_widget() {
  19.         parent::WP_Widget( false, $name = __( "BP Follow - Following", 'bp-follow' ) );
  20.     }
  21.  
  22.     function widget( $args, $instance ) {
  23.  
  24.         extract( $args );
  25.  
  26.         if ( empty( $instance['max_users'] ) )
  27.             $instance['max_users'] = 25;
  28.  
  29.         if ( !$following = bp_get_following_ids( $displayed_user->id ) )
  30.         {  
  31.             do_action( 'bp_before_follower_widget' );
  32.  
  33.             echo $before_widget;
  34.             echo $before_title
  35.                . __( 'Following', 'bp-follow' )
  36.                . $after_title; ?>
  37.  
  38.             <div class="avatar-block">
  39.                 <?php echo bp_get_displayed_user_fullname() . " " .  __('is not following anyone yet.', 'bp-follow'); ?>
  40.             </div>
  41.  
  42.             <?php echo $after_widget; ?>
  43.  
  44.             <?php do_action( 'bp_after_follower_widget' ); ?>
  45.  
  46.         <?php } ?>
  47.  
  48.  
  49.         <?php
  50.  
  51.         if ( bp_has_members( 'include=' . $following . '&max=' . $instance['max_users'] ) ) {
  52.  
  53.             do_action( 'bp_before_following_widget' );
  54.  
  55.             echo $before_widget;
  56.             echo $before_title
  57.                . __( 'Following', 'bp-follow' )
  58.                . $after_title; ?>
  59.  
  60.             <div class="avatar-block">
  61.                 <?php while ( bp_members() ) : bp_the_member(); ?>
  62.                     <div class="item-avatar">
  63.                         <a title="<?php bp_member_name() ?>" href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
  64.                     </div>
  65.                 <?php endwhile; ?>
  66.             </div>
  67.  
  68.             <?php echo $after_widget; ?>
  69.  
  70.             <?php do_action( 'bp_after_following_widget' ); ?>
  71.  
  72.         <?php } ?>
  73.  
  74.     <?php
  75.     }
  76.  
  77.     function update( $new_instance, $old_instance ) {
  78.         $instance = $old_instance;
  79.         $instance['max_users'] = strip_tags( $new_instance['max_users'] );
  80.  
  81.         return $instance;
  82.     }
  83.  
  84.     function form( $instance ) {
  85.         $instance = wp_parse_args( (array) $instance, array( 'max_users' => 25 ) );
  86.         $max_users = strip_tags( $instance['max_users'] );
  87.         ?>
  88.  
  89.         <p><label for="bp-follow-widget-users-max"><?php _e('Max users to show:', 'bp-follow'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_users' ); ?>" name="<?php echo $this->get_field_name( 'max_users' ); ?>" type="text" value="<?php echo attribute_escape( $max_users ); ?>" style="width: 30%" /></label></p>
  90.     <?php
  91.     }
  92. }
  93. add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Follow_Following_Widget");' ) );
  94.  
  95.  
  96.  
  97.  
  98.  
  99. /**
  100.  * Add a "Users following me" widget for the logged-in user
  101.  *
  102.  * @subpackage Widgets
  103.  */
  104. class BP_Follow_Follower_Widget extends WP_Widget {
  105.     function bp_follow_follower_widget() {
  106.         parent::WP_Widget( false, $name = __( "BP Follow - Followers", 'bp-follow' ) );
  107.     }
  108.  
  109.     function widget( $args, $instance ) {
  110.  
  111.         extract( $args );
  112.  
  113.         if ( empty( $instance['max_users'] ) )
  114.             $instance['max_users'] = 25;
  115.  
  116.         if ( !$follower = bp_get_follower_ids( $displayed_user->id ) )
  117.         {  
  118.             do_action( 'bp_before_follower_widget' );
  119.  
  120.             echo $before_widget;
  121.             echo $before_title
  122.                . __( 'Followers', 'bp-follow' )
  123.                . $after_title; ?>
  124.  
  125.             <div class="avatar-block">
  126.                 <?php echo bp_get_displayed_user_fullname() . " " .  __('has no followers yet.', 'bp-follow'); ?>
  127.             </div>
  128.  
  129.             <?php echo $after_widget; ?>
  130.  
  131.             <?php do_action( 'bp_after_follower_widget' ); ?>
  132.  
  133.         <?php } ?>
  134.  
  135. <?php
  136.         if ( bp_has_members( 'include=' . $follower . '&max=' . $instance['max_users'] ) ) {
  137.  
  138.             do_action( 'bp_before_follower_widget' );
  139.  
  140.             echo $before_widget;
  141.             echo $before_title
  142.                . __( 'Followers', 'bp-follow' )
  143.                . $after_title; ?>
  144.  
  145.             <div class="avatar-block">
  146.                 <?php while ( bp_members() ) : bp_the_member(); ?>
  147.                     <div class="item-avatar">
  148.                         <a title="<?php bp_member_name() ?>" href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
  149.                     </div>
  150.                 <?php endwhile; ?>
  151.             </div>
  152.  
  153.             <?php echo $after_widget; ?>
  154.  
  155.             <?php do_action( 'bp_after_follower_widget' ); ?>
  156.  
  157.         <?php } ?>
  158.  
  159.     <?php
  160.     }
  161.  
  162.     function update( $new_instance, $old_instance ) {
  163.         $instance = $old_instance;
  164.         $instance['max_users'] = strip_tags( $new_instance['max_users'] );
  165.  
  166.         return $instance;
  167.     }
  168.  
  169.     function form( $instance ) {
  170.         $instance = wp_parse_args( (array) $instance, array( 'max_users' => 25 ) );
  171.         $max_users = strip_tags( $instance['max_users'] );
  172.         ?>
  173.  
  174.         <p><label for="bp-follow-widget-users-max"><?php _e('Max users to show:', 'bp-follow'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_users' ); ?>" name="<?php echo $this->get_field_name( 'max_users' ); ?>" type="text" value="<?php echo attribute_escape( $max_users ); ?>" style="width: 30%" /></label></p>
  175.     <?php
  176.     }
  177. }
  178. add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Follow_Follower_Widget");' ) );
  179.  
  180. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement