BP_Blogs_Recent_Posts_Widget
The Recent Networkwide Posts widget.
Description
Source
File: bp-blogs/classes/class-bp-blogs-recent-posts-widget.php
15 16 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 | class BP_Blogs_Recent_Posts_Widget extends WP_Widget { /** * Constructor method. */ public function __construct() { $widget_ops = array ( 'description' => __( 'A list of recently published posts from across your network.' , 'buddyboss' ), 'classname' => 'widget_bp_blogs_widget buddypress widget' , 'customize_selective_refresh' => true, ); parent::__construct( false, $name = __( '(BB) Recent Networkwide Posts' , 'buddyboss' ), $widget_ops ); } /** * Display the networkwide posts widget. * * @see WP_Widget::widget() for description of parameters. * * @param array $args Widget arguments. * @param array $instance Widget settings, as saved by the user. */ public function widget( $args , $instance ) { global $activities_template ; $title = ! empty ( $instance [ 'title' ] ) ? esc_html( $instance [ 'title' ] ) : __( 'Recent Networkwide Posts' , 'buddyboss' ); if ( ! empty ( $instance [ 'link_title' ] ) ) { $title = '<a href="' . bp_get_blogs_directory_permalink() . '">' . esc_html( $title ) . '</a>' ; } /** * Filters the Blogs Recent Posts widget title. * * @since BuddyPress 2.2.0 * @since BuddyPress 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. * * @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 ); echo $args [ 'before_widget' ]; echo $args [ 'before_title' ] . $title . $args [ 'after_title' ]; if ( empty ( $instance [ 'max_posts' ] ) || empty ( $instance [ 'max_posts' ] ) ) { $instance [ 'max_posts' ] = 10; } $after_widget = $args [ 'after_widget' ]; // Override some of the contextually set parameters for bp_has_activities(). $args = array ( 'action' => 'new_blog_post' , 'max' => $instance [ 'max_posts' ], 'per_page' => $instance [ 'max_posts' ], 'user_id' => 0, 'scope' => false, 'object' => false, 'primary_id' => false ); // Back up global. $old_activities_template = $activities_template ; ?> <?php if ( bp_has_activities( $args ) ) : ?> <ul id= "blog-post-list" class = "activity-list item-list" > <?php while ( bp_activities() ) : bp_the_activity(); ?> <li> <div class = "activity-content" style= "margin: 0" > <div class = "activity-header" ><?php bp_activity_action(); ?></div> <?php if ( bp_get_activity_content_body() ) : ?> <div class = "activity-inner" ><?php bp_activity_content_body(); ?></div> <?php endif ; ?> </div> </li> <?php endwhile ; ?> </ul> <?php else : ?> <div id= "message" class = "info" > <p><?php _e( 'Sorry, there were no posts found. Why not write one?' , 'buddyboss' ); ?></p> </div> <?php endif ; ?> <?php echo $after_widget ; // Restore the global. $activities_template = $old_activities_template ; } /** * Update the networkwide posts widget options. * * @param array $new_instance The new instance options. * @param array $old_instance The old instance options. * @return array $instance The parsed options to be saved. */ public function update( $new_instance , $old_instance ) { $instance = $old_instance ; $instance [ 'title' ] = strip_tags ( $new_instance [ 'title' ] ); $instance [ 'max_posts' ] = strip_tags ( $new_instance [ 'max_posts' ] ); $instance [ 'link_title' ] = (bool) $new_instance [ 'link_title' ]; return $instance ; } /** * Output the networkwide posts widget options form. * * @param array $instance Settings for this widget. * * @return void */ public function form( $instance ) { $instance = wp_parse_args( ( array ) $instance , array ( 'title' => __( 'Recent Networkwide Posts' , 'buddyboss' ), 'max_posts' => 10, 'link_title' => false, ) ); $title = strip_tags ( $instance [ 'title' ] ); $max_posts = strip_tags ( $instance [ 'max_posts' ] ); $link_title = (bool) $instance [ 'link_title' ]; ?> <p><label for = "<?php echo $this->get_field_id( 'title' ); ?>" ><?php _ex( 'Title:' , 'Label for the Title field of the Recent Networkwide Posts widget' , 'buddyboss' ); ?> <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 ); ?>" style= "width: 100%;" /></label></p> <p><label for = "<?php echo $this->get_field_id( 'link_title' ); ?>" ><input type= "checkbox" name= "<?php echo $this->get_field_name( 'link_title' ); ?>" value= "1" <?php checked( $link_title ); ?> /> <?php _e( 'Link widget title to Blogs directory' , 'buddyboss' ); ?></label></p> <p><label for = "<?php echo $this->get_field_id( 'max_posts' ); ?>" ><?php _e( 'Max posts to show:' , 'buddyboss' ); ?> <input class = "widefat" id= "<?php echo $this->get_field_id( 'max_posts' ); ?>" name= "<?php echo $this->get_field_name( 'max_posts' ); ?>" type= "text" value= "<?php echo esc_attr( $max_posts ); ?>" style= "width: 30%" /></label></p> <?php } } |
Methods
- __construct — Constructor method.
- form — Output the networkwide posts widget options form.
- update — Update the networkwide posts widget options.
- widget — Display the networkwide posts widget.
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.