Advertisement
Guest User

Untitled

a guest
Apr 19th, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Plugin Name: BP-featured groups widget
  5. Plugin URI:
  6. Description:
  7. Version: 1.0
  8. Author: Charl Kruger
  9. Author URI:
  10. License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
  11. */
  12.  
  13. function custom_register_widgets() { /* rename this or incorporate into your own custom scheme as nec */
  14. global $current_blog;
  15.  
  16. /* Featured Groups Widget */
  17. register_sidebar_widget( __('Featured Groups', 'buddypress'), 'groups_widget_groups_featured');
  18. register_widget_control( __('Featured Groups', 'buddypress'), 'groups_widget_groups_featured_control' );
  19. }
  20. add_action( 'plugins_loaded', 'custom_register_widgets' );
  21.  
  22.  
  23.  
  24.  
  25. function groups_widget_groups_featured($args) {
  26. global $current_blog, $bp;
  27.  
  28. extract($args);
  29. $options = get_option('widget_groups_featured' );
  30. $title = empty( $options['featured_title'] ) ? __( 'Featured Groups' ) : apply_filters('widget_title', $options['featured_title']);
  31. $includes = empty( $options['featured_include'] ) ? '' : $options['featured_include'];
  32. $includes = explode(",", $includes);
  33.  
  34. ?>
  35. <?php echo $before_widget; ?>
  36. <?php echo $before_title . $title . $after_title; ?>
  37.  
  38.  
  39.  
  40. <?php if ( $includes[0] != "" ) : ?>
  41.  
  42.  
  43. <ul id="featured-groups-list" class="item-list">
  44. <?php foreach ( $includes as $include ) : ?>
  45. <?php $group = new BP_Groups_Group( $include, false ); ?>
  46.  
  47. <li>
  48. <div class="item-avatar">
  49. <a href="<?php echo bp_get_group_permalink( $group ) ?>" title="<?php echo $group->name ?>"><img src="<?php echo $group->avatar_thumb ?>" alt="<?php echo $group->name ?> Avatar" class="avatar" /></a>
  50. </div>
  51.  
  52. <div class="item">
  53. <div class="item-title"><a href="<?php echo bp_get_group_permalink( $group ) ?>" title="<?php echo $group->name ?>"><?php echo $group->name ?></a></div>
  54. <div class="item-meta">
  55. <span class="activity">
  56. <?php
  57. if ( $group->total_member_count == 1 )
  58. echo $group->total_member_count . __(' member', 'buddypress');
  59. else
  60. echo $group->total_member_count . __(' members', 'buddypress');
  61. ?>
  62. </span></div>
  63. </div>
  64. </li>
  65. <?php $counter++; ?>
  66. <?php endforeach; ?>
  67. </ul>
  68.  
  69. <?php
  70. if ( function_exists('wp_nonce_field') )
  71. wp_nonce_field( 'widget_groups_featured', '_wpnonce-featured-groups' );
  72. ?>
  73.  
  74. <?php else: ?>
  75. <div class="widget-error">
  76. <?php _e('There are no featured groups to display.', 'buddypress') ?>
  77. </div>
  78. <?php endif; ?>
  79.  
  80. <?php echo $after_widget; ?>
  81. <?php
  82. }
  83.  
  84. function groups_widget_groups_featured_control() {
  85. global $current_blog;
  86.  
  87. $options = $newoptions = get_option('widget_groups_featured');
  88.  
  89. if ( isset($_POST['featured-submit']) ) {
  90. $newoptions['featured_title'] = strip_tags(stripslashes($_POST['featured-title']));
  91. $newoptions['featured_include'] = strip_tags( stripslashes( $_POST['featured-include'] ) );
  92. }
  93. if ( $options != $newoptions ) {
  94. $options = $newoptions;
  95. update_option( 'widget_groups_featured', $options );
  96. }
  97. $title = attribute_escape($options['featured_title']);
  98. $include = attribute_escape( $options['featured_include'] );
  99. ?>
  100. <p><label for="featured-title"><?php _e('Title:'); ?> <input class="widefat" id="featured-title" name="featured-title" type="text" value="<?php echo $title; ?>" /></label></p>
  101. <p>
  102. <label for="featured-include"><?php _e( 'Include:'); ?> <input type="text" value="<?php echo $include; ?>" name="featured-include" id="featured-include" class="widefat" /></label>
  103. <br />
  104. <small><?php _e( 'Group IDs, separated by commas.' ); ?></small>
  105. </p>
  106. <input type="hidden" id="featured-submit" name="featured-submit" value="1" />
  107. <?php
  108.  
  109. }
  110.  
  111. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement