Changeset 10517 for trunk/src/bp-blogs/bp-blogs-widgets.php
- Timestamp:
- 02/05/2016 04:08:04 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-blogs/bp-blogs-widgets.php
r10417 r10517 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 require dirname( __FILE__ ) . '/classes/class-bp-blogs-recent-posts-widget.php'; 14 13 15 /** 14 16 * Register the widgets for the Blogs component. … … 22 24 } 23 25 add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' ); 24 25 /**26 * The Recent Networkwide Posts widget.27 */28 class BP_Blogs_Recent_Posts_Widget extends WP_Widget {29 30 /**31 * Constructor method.32 */33 public function __construct() {34 $widget_ops = array(35 'description' => __( 'A list of recently published posts from across your network.', 'buddypress' ),36 'classname' => 'widget_bp_blogs_widget buddypress widget',37 );38 parent::__construct( false, $name = _x( '(BuddyPress) Recent Networkwide Posts', 'widget name', 'buddypress' ), $widget_ops );39 }40 41 /**42 * Display the networkwide posts widget.43 *44 * @see WP_Widget::widget() for description of parameters.45 *46 * @param array $args Widget arguments.47 * @param array $instance Widget settings, as saved by the user.48 */49 public function widget( $args, $instance ) {50 51 $title = ! empty( $instance['title'] )52 ? esc_html( $instance['title'] )53 : __( 'Recent Networkwide Posts', 'buddypress' );54 55 if ( ! empty( $instance['link_title'] ) ) {56 $title = '<a href="' . bp_get_blogs_directory_permalink() . '">' . esc_html( $title ) . '</a>';57 }58 59 /**60 * Filters the Blogs Recent Posts widget title.61 *62 * @since 2.2.063 * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.64 *65 * @param string $title The widget title.66 * @param array $instance The settings for the particular instance of the widget.67 * @param string $id_base Root ID for all widgets of this type.68 */69 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );70 71 echo $args['before_widget'];72 echo $args['before_title'] . $title . $args['after_title'];73 74 if ( empty( $instance['max_posts'] ) || empty( $instance['max_posts'] ) ) {75 $instance['max_posts'] = 10;76 }77 78 $after_widget = $args['after_widget'];79 80 // Override some of the contextually set parameters for bp_has_activities().81 $args = array(82 'action' => 'new_blog_post',83 'max' => $instance['max_posts'],84 'per_page' => $instance['max_posts'],85 'user_id' => 0,86 'scope' => false,87 'object' => false,88 'primary_id' => false89 ); ?>90 91 <?php if ( bp_has_activities( $args ) ) : ?>92 93 <ul id="blog-post-list" class="activity-list item-list">94 95 <?php while ( bp_activities() ) : bp_the_activity(); ?>96 97 <li>98 <div class="activity-content" style="margin: 0">99 <div class="activity-header"><?php bp_activity_action(); ?></div>100 101 <?php if ( bp_get_activity_content_body() ) : ?>102 103 <div class="activity-inner"><?php bp_activity_content_body(); ?></div>104 105 <?php endif; ?>106 107 </div>108 </li>109 110 <?php endwhile; ?>111 112 </ul>113 114 <?php else : ?>115 116 <div id="message" class="info">117 <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ); ?></p>118 </div>119 120 <?php endif; ?>121 122 <?php echo $after_widget; ?>123 <?php124 }125 126 /**127 * Update the networkwide posts widget options.128 *129 * @param array $new_instance The new instance options.130 * @param array $old_instance The old instance options.131 * @return array $instance The parsed options to be saved.132 */133 public function update( $new_instance, $old_instance ) {134 $instance = $old_instance;135 $instance['title'] = strip_tags( $new_instance['title'] );136 $instance['max_posts'] = strip_tags( $new_instance['max_posts'] );137 $instance['link_title'] = (bool) $new_instance['link_title'];138 139 return $instance;140 }141 142 /**143 * Output the networkwide posts widget options form.144 *145 * @param array $instance Settings for this widget.146 *147 * @return void148 */149 public function form( $instance ) {150 $instance = wp_parse_args( (array) $instance, array(151 'title' => __( 'Recent Networkwide Posts', 'buddypress' ),152 'max_posts' => 10,153 'link_title' => false,154 ) );155 156 $title = strip_tags( $instance['title'] );157 $max_posts = strip_tags( $instance['max_posts'] );158 $link_title = (bool) $instance['link_title'];159 160 ?>161 162 <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>163 <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>164 <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>165 <?php166 }167 }
Note: See TracChangeset
for help on using the changeset viewer.