BP_Blogs_Recent_Posts_Widget

The Recent Networkwide Posts widget.

Defined (1)

The class is defined in the following location(s).

/bp-blogs/classes/class-bp-blogs-recent-posts-widget.php  
  1. class BP_Blogs_Recent_Posts_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Constructor method. 
  5. */ 
  6. public function __construct() { 
  7. $widget_ops = array( 
  8. 'description' => __( 'A list of recently published posts from across your network.', 'buddypress' ),  
  9. 'classname' => 'widget_bp_blogs_widget buddypress widget',  
  10. 'customize_selective_refresh' => true,  
  11. ); 
  12. parent::__construct( false, $name = _x( '(BuddyPress) Recent Networkwide Posts', 'widget name', 'buddypress' ), $widget_ops ); 
  13.  
  14. /** 
  15. * Display the networkwide posts widget. 
  16. * @see WP_Widget::widget() for description of parameters. 
  17. * @param array $args Widget arguments. 
  18. * @param array $instance Widget settings, as saved by the user. 
  19. */ 
  20. public function widget( $args, $instance ) { 
  21. global $activities_template; 
  22.  
  23. $title = ! empty( $instance['title'] ) 
  24. ? esc_html( $instance['title'] ) 
  25. : __( 'Recent Networkwide Posts', 'buddypress' ); 
  26.  
  27. if ( ! empty( $instance['link_title'] ) ) { 
  28. $title = '<a href="' . bp_get_blogs_directory_permalink() . '">' . esc_html( $title ) . '</a>'; 
  29.  
  30. /** 
  31. * Filters the Blogs Recent Posts widget title. 
  32. * @since 2.2.0 
  33. * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. 
  34. * @param string $title The widget title. 
  35. * @param array $instance The settings for the particular instance of the widget. 
  36. * @param string $id_base Root ID for all widgets of this type. 
  37. */ 
  38. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 
  39.  
  40. echo $args['before_widget']; 
  41. echo $args['before_title'] . $title . $args['after_title']; 
  42.  
  43. if ( empty( $instance['max_posts'] ) || empty( $instance['max_posts'] ) ) { 
  44. $instance['max_posts'] = 10; 
  45.  
  46. $after_widget = $args['after_widget']; 
  47.  
  48. // Override some of the contextually set parameters for bp_has_activities(). 
  49. $args = array( 
  50. 'action' => 'new_blog_post',  
  51. 'max' => $instance['max_posts'],  
  52. 'per_page' => $instance['max_posts'],  
  53. 'user_id' => 0,  
  54. 'scope' => false,  
  55. 'object' => false,  
  56. 'primary_id' => false 
  57. ); 
  58.  
  59. // Back up global. 
  60. $old_activities_template = $activities_template; 
  61.  
  62. ?> 
  63.  
  64. <?php if ( bp_has_activities( $args ) ) : ?> 
  65.  
  66. <ul id="blog-post-list" class="activity-list item-list"> 
  67.  
  68. <?php while ( bp_activities() ) : bp_the_activity(); ?> 
  69.  
  70. <li> 
  71. <div class="activity-content" style="margin: 0"> 
  72. <div class="activity-header"><?php bp_activity_action(); ?></div> 
  73.  
  74. <?php if ( bp_get_activity_content_body() ) : ?> 
  75.  
  76. <div class="activity-inner"><?php bp_activity_content_body(); ?></div> 
  77.  
  78. <?php endif; ?> 
  79.  
  80. </div> 
  81. </li> 
  82.  
  83. <?php endwhile; ?> 
  84.  
  85. </ul> 
  86.  
  87. <?php else : ?> 
  88.  
  89. <div id="message" class="info"> 
  90. <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ); ?></p> 
  91. </div> 
  92.  
  93. <?php endif; ?> 
  94.  
  95. <?php echo $after_widget; 
  96.  
  97. // Restore the global. 
  98. $activities_template = $old_activities_template; 
  99.  
  100. /** 
  101. * Update the networkwide posts widget options. 
  102. * @param array $new_instance The new instance options. 
  103. * @param array $old_instance The old instance options. 
  104. * @return array $instance The parsed options to be saved. 
  105. */ 
  106. public function update( $new_instance, $old_instance ) { 
  107. $instance = $old_instance; 
  108. $instance['title'] = strip_tags( $new_instance['title'] ); 
  109. $instance['max_posts'] = strip_tags( $new_instance['max_posts'] ); 
  110. $instance['link_title'] = (bool) $new_instance['link_title']; 
  111.  
  112. return $instance; 
  113.  
  114. /** 
  115. * Output the networkwide posts widget options form. 
  116. * @param array $instance Settings for this widget. 
  117. * @return void 
  118. */ 
  119. public function form( $instance ) { 
  120. $instance = wp_parse_args( (array) $instance, array( 
  121. 'title' => __( 'Recent Networkwide Posts', 'buddypress' ),  
  122. 'max_posts' => 10,  
  123. 'link_title' => false,  
  124. ) ); 
  125.  
  126. $title = strip_tags( $instance['title'] ); 
  127. $max_posts = strip_tags( $instance['max_posts'] ); 
  128. $link_title = (bool) $instance['link_title']; 
  129.  
  130. ?> 
  131.  
  132. <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _ex( 'Title:', 'Label for the Title field of the Recent Networkwide Posts widget', 'buddypress' ); ?> <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> 
  133. <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', 'buddypress' ); ?></label></p> 
  134. <p><label for="<?php echo $this->get_field_id( 'max_posts' ); ?>"><?php _e( 'Max posts to show:', 'buddypress' ); ?> <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> 
  135. <?php