BP_Latest_Activities
A widget to display the latest activities of your community!
Description
Source
File: bp-templates/bp-nouveau/includes/activity/widgets.php
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | class BP_Latest_Activities extends WP_Widget { /** * Construct the widget. * * @since BuddyPress 3.0.0 */ public function __construct() { /** * Filters the widget options for the BP_Latest_Activities widget. * * @since BuddyPress 3.0.0 * * @param array $value Array of widget options. */ $widget_ops = apply_filters( 'bp_latest_activities' , array ( 'classname' => 'bp-latest-activities buddypress' , 'description' => __( 'Select to display the latest activity updates, by type, posted within your community.' , 'buddyboss' ), 'customize_selective_refresh' => true, ) ); parent::__construct( false, __( '(BB) Latest Activities' , 'buddyboss' ), $widget_ops ); } /** * Register the widget. * * @since BuddyPress 3.0.0 */ public static function register_widget() { register_widget( 'BP_Latest_Activities' ); } /** * Display the widget content. * * @since BuddyPress 3.0.0 * * @param array $args Widget arguments. * @param array $instance Widget settings, as saved by the user. */ public function widget( $args , $instance ) { // Default values $title = __( 'Latest updates' , 'buddyboss' ); $type = array ( 'activity_update' ); $max = 5; $bp_nouveau = bp_nouveau(); // Check instance for a custom title if ( ! empty ( $instance [ 'title' ] ) ) { $title = $instance [ 'title' ]; } /** * Filters the BP_Latest_Activities widget title. * * @since BuddyPress 3.0.0 * * @param string $title The widget title. * @param array $instance The settings for the particular instance of the widget. * @param string $id_base Root ID for all widgets of this type. */ $title = apply_filters( 'widget_title' , $title , $instance , $this ->id_base ); // Check instance for custom max number of activities to display if ( ! empty ( $instance [ 'max' ] ) ) { $max = (int) $instance [ 'max' ]; } // Check instance for custom activity types if ( ! empty ( $instance [ 'type' ] ) ) { $type = maybe_unserialize( $instance [ 'type' ] ); $classes = array_map ( 'sanitize_html_class' , array_merge ( $type , array ( 'bp-latest-activities' ) ) ); // Add classes to the container $args [ 'before_widget' ] = str_replace ( 'bp-latest-activities' , join( ' ' , $classes ), $args [ 'before_widget' ] ); } echo $args [ 'before_widget' ]; if ( $title ) { echo $args [ 'before_title' ] . $title . $args [ 'after_title' ]; } $reset_activities_template = null; if ( ! empty ( $GLOBALS [ 'activities_template' ] ) ) { $reset_activities_template = $GLOBALS [ 'activities_template' ]; } /** * Globalize the activity widget arguments. * @see bp_nouveau_activity_widget_query() to override */ $bp_nouveau ->activity->widget_args = array ( 'max' => $max , 'scope' => 'all' , 'user_id' => 0, 'object' => false, 'action' => join( ',' , $type ), 'primary_id' => 0, 'secondary_id' => 0, ); bp_get_template_part( 'activity/widget' ); // Reset the globals $GLOBALS [ 'activities_template' ] = $reset_activities_template ; $bp_nouveau ->activity->widget_args = array (); echo $args [ 'after_widget' ]; } /** * Update the widget settings. * * @since BuddyPress 3.0.0 * * @param array $new_instance The new instance settings. * @param array $old_instance The old instance settings. * * @return array The widget settings. */ public function update( $new_instance , $old_instance ) { $instance = $old_instance ; $instance [ 'title' ] = strip_tags ( $new_instance [ 'title' ] ); $instance [ 'max' ] = 5; if ( ! empty ( $new_instance [ 'max' ] ) ) { $instance [ 'max' ] = $new_instance [ 'max' ]; } $instance [ 'type' ] = maybe_serialize( array ( 'activity_update' ) ); if ( ! empty ( $new_instance [ 'type' ] ) ) { $instance [ 'type' ] = maybe_serialize( $new_instance [ 'type' ] ); } return $instance ; } /** * Display the form to set the widget settings. * * @since BuddyPress 3.0.0 * * @param array $instance Settings for this widget. * * @return string HTML output. */ public function form( $instance ) { $instance = wp_parse_args( ( array ) $instance , array ( 'title' => __( 'Latest updates' , 'buddyboss' ), 'max' => 5, 'type' => '' , ) ); $title = esc_attr( $instance [ 'title' ] ); $max = (int) $instance [ 'max' ]; $type = array ( 'activity_update' ); if ( ! empty ( $instance [ 'type' ] ) ) { $type = maybe_unserialize( $instance [ 'type' ] ); } ?> <p> <label for = "<?php echo $this->get_field_id( 'title' ); ?>" ><?php esc_html_e( 'Title:' , 'buddyboss' ); ?></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> <p> <label for = "<?php echo $this->get_field_id( 'max' ); ?>" ><?php _e( 'Maximum amount to display:' , 'buddyboss' ); ?></label> <input type= "number" class = "widefat" id= "<?php echo $this->get_field_id( 'max' ); ?>" name= "<?php echo $this->get_field_name( 'max' ); ?>" value= "<?php echo intval( $max ); ?>" step= "1" min= "1" max= "20" /> </p> <p> <label for = "<?php echo $this->get_field_id( 'type' ); ?>" ><?php esc_html_e( 'Activity Type:' , 'buddyboss' ); ?></label> <select class = "widefat" multiple= "multiple" id= "<?php echo $this->get_field_id( 'type' ); ?>" name= "<?php echo $this->get_field_name( 'type' ); ?>[]" > <?php foreach ( bp_nouveau_get_activity_filters() as $key => $name ) : ?> <option value= "<?php echo esc_attr( $key ); ?>" <?php selected( in_array( $key , $type ) ); ?>><?php echo esc_html( $name ); ?></option> <?php endforeach ; ?> </select> </p> <?php } } |
Changelog
Version | Description |
---|---|
BuddyPress 3.0.0 | Introduced. |
Methods
- __construct — Construct the widget.
- form — Display the form to set the widget settings.
- register_widget — Register the widget.
- update — Update the widget settings.
- widget — Display the widget content.
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.