Skip to:
Content

BuddyPress.org

Ticket #4802: bp-messages-widget.php

File bp-messages-widget.php, 1.8 KB (added by imath, 14 years ago)

The widget file

Line 
1<?php
2
3/**
4 * BuddyPress Site Wide Notice widget
5 *
6 * Adds a widget only if BP Theme Compat is used.
7 *
8 * @package BuddyPress
9 * @subpackage BP Messages Widget
10 */
11
12// Exit if accessed directly
13if ( !defined( 'ABSPATH' ) ) exit;
14
15
16/**
17 * Adds a widget to display site wide notices
18 *
19 * @uses WP_Widget
20 */
21class BP_Messages_Widget extends WP_Widget {
22
23 function __construct() {
24
25 $widget_ops = array( 'description' => __( 'Displays site wide notices if any', 'buddypress' ) );
26 parent::__construct( false, $name = __( '(BuddyPress) Site Wide Notices', 'buddypress' ), $widget_ops );
27
28 }
29
30 /**
31 * Register the widget
32 *
33 * @uses register_widget()
34 */
35 function register_widget() {
36 register_widget( 'BP_Messages_Widget' );
37 }
38
39 /**
40 * Displays the output, the notices if any
41 *
42 * @param mixed $args Arguments
43 * @param array $instance Instance
44 * @uses bp_message_get_notices() to display the notices if any
45 */
46 function widget( $args, $instance ) {
47
48
49 extract( $args );
50
51 //we dont need $title, $before_title and $after_title.
52
53 //displays the notices if any.
54 if( is_user_logged_in() )
55 bp_message_get_notices( $before_widget, $after_widget );
56
57 }
58
59 /**
60 * Updates the widget options
61 *
62 * @param array $new_instance The new instance options
63 * @param array $old_instance The old instance options
64 */
65 function update( $new_instance, $old_instance ) {
66 $instance = $old_instance;
67
68 // no option to set..
69
70 return $instance;
71 }
72
73
74 /**
75 * Output the widget options form
76 *
77 * @param $instance Instance
78 */
79 function form( $instance ) {
80 ?>
81
82 <p>
83 <?php _e( 'Displays site wide notices if any', 'buddypress' );?>
84 </p>
85 <?php
86 }
87
88}
89
90add_action( 'bp_widgets_init', array( 'BP_Messages_Widget', 'register_widget' ), 10 );
91?>