Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Provides an implementation of BuddyPress sitewide message function in a widget for use in site sidebars, can replace BP legacy_theme wp_footer rendering.
add_action('widgets_init', create_function('', 'return register_widget("HNLA_bp_sitewide_messages_Widget");') );
class HNLA_bp_sitewide_messages_Widget extends WP_Widget {
function __construct() {
parent::__construct(
'HNLA_bp_sitewide_messages_Widget', //the ID?
'HNLA BP Sitewide Messages', //the widget name
array( 'description' => __('Displays the BP admin \'all users\' sitewide messages', 'meson'), )
);
}
public function widget( $args, $instance ) {
global $bp, $wp, $wpdb;
if( !is_user_logged_in() || is_super_admin() )
return;
extract( $args );
$title = apply_filters( 'widget_title', empty($instance['title']) ? $widget_name : $instance['title'], $instance );
echo $before_widget;
echo $before_title .
$title .
$after_title;
// output content to display ?>
<?php if ( bp_is_active( 'messages' ) ) : ?>
<div class="bp-site-wide-message">
<?php bp_message_get_notices(); ?>
</div>
<?php endif; ?>
<?php
//end markup output
echo $after_widget;
}// close function widget
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
$title = strip_tags($instance['title']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
</p>
<?php }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.