[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Blogs Recent Posts Widget. 4 * 5 * @package BuddyPress 6 * @subpackage BlogsWidgets 7 * @since 1.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * The Recent Networkwide Posts widget. 15 * 16 * @since 1.0.0 17 */ 18 class BP_Blogs_Recent_Posts_Widget extends WP_Widget { 19 20 /** 21 * Constructor method. 22 * 23 * @since 1.5.0 24 * @since 9.0.0 Adds the `show_instance_in_rest` property to Widget options. 25 */ 26 public function __construct() { 27 $widget_ops = array( 28 'description' => __( 'A list of recently published posts from across your network.', 'buddypress' ), 29 'classname' => 'widget_bp_blogs_widget buddypress widget', 30 'customize_selective_refresh' => true, 31 'show_instance_in_rest' => true, 32 ); 33 parent::__construct( false, $name = _x( '(BuddyPress) Recent Networkwide Posts', 'widget name', 'buddypress' ), $widget_ops ); 34 } 35 36 /** 37 * Display the networkwide posts widget. 38 * 39 * @see WP_Widget::widget() for description of parameters. 40 * 41 * @param array $args Widget arguments. 42 * @param array $instance Widget settings, as saved by the user. 43 */ 44 public function widget( $args, $instance ) { 45 global $activities_template; 46 47 $title = ! empty( $instance['title'] ) 48 ? esc_html( $instance['title'] ) 49 : __( 'Recent Networkwide Posts', 'buddypress' ); 50 51 if ( ! empty( $instance['link_title'] ) ) { 52 $title = '<a href="' . bp_get_blogs_directory_permalink() . '">' . esc_html( $title ) . '</a>'; 53 } 54 55 /** 56 * Filters the Blogs Recent Posts widget title. 57 * 58 * @since 2.2.0 59 * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. 60 * 61 * @param string $title The widget title. 62 * @param array $instance The settings for the particular instance of the widget. 63 * @param string $id_base Root ID for all widgets of this type. 64 */ 65 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 66 67 echo $args['before_widget']; 68 echo $args['before_title'] . $title . $args['after_title']; 69 70 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 71 if ( empty( $instance['max_posts'] ) || $instance['max_posts'] > $max_limit ) { 72 $instance['max_posts'] = 10; 73 } 74 75 $after_widget = $args['after_widget']; 76 77 // Override some of the contextually set parameters for bp_has_activities(). 78 $args = array( 79 'action' => 'new_blog_post', 80 'max' => $instance['max_posts'], 81 'per_page' => $instance['max_posts'], 82 'user_id' => 0, 83 'scope' => false, 84 'object' => false, 85 'primary_id' => false 86 ); 87 88 // Back up global. 89 $old_activities_template = $activities_template; 90 91 ?> 92 93 <?php if ( bp_has_activities( $args ) ) : ?> 94 95 <ul id="blog-post-list" class="activity-list item-list"> 96 97 <?php while ( bp_activities() ) : bp_the_activity(); ?> 98 99 <li> 100 <div class="activity-content" style="margin: 0"> 101 <div class="activity-header"><?php bp_activity_action(); ?></div> 102 103 <?php if ( bp_get_activity_content_body() ) : ?> 104 105 <div class="activity-inner"><?php bp_activity_content_body(); ?></div> 106 107 <?php endif; ?> 108 109 </div> 110 </li> 111 112 <?php endwhile; ?> 113 114 </ul> 115 116 <?php else : ?> 117 118 <div id="message" class="info"> 119 <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ); ?></p> 120 </div> 121 122 <?php endif; ?> 123 124 <?php echo $after_widget; 125 126 // Restore the global. 127 $activities_template = $old_activities_template; 128 } 129 130 /** 131 * Update the networkwide posts widget options. 132 * 133 * @param array $new_instance The new instance options. 134 * @param array $old_instance The old instance options. 135 * @return array $instance The parsed options to be saved. 136 */ 137 public function update( $new_instance, $old_instance ) { 138 $instance = $old_instance; 139 140 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 141 142 $instance['title'] = strip_tags( $new_instance['title'] ); 143 $instance['max_posts'] = $new_instance['max_posts'] > $max_limit ? $max_limit : intval( $new_instance['max_posts'] ); 144 $instance['link_title'] = ! empty( $new_instance['link_title'] ); 145 146 return $instance; 147 } 148 149 /** 150 * Output the networkwide posts widget options form. 151 * 152 * @param array $instance Settings for this widget. 153 */ 154 public function form( $instance ) { 155 $instance = bp_parse_args( 156 (array) $instance, 157 array( 158 'title' => __( 'Recent Networkwide Posts', 'buddypress' ), 159 'max_posts' => 10, 160 'link_title' => false, 161 ) 162 ); 163 164 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 165 166 $title = strip_tags( $instance['title'] ); 167 $max_posts = $instance['max_posts'] > $max_limit ? $max_limit : intval( $instance['max_posts'] ); 168 $link_title = (bool) $instance['link_title']; 169 170 ?> 171 172 <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> 173 <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> 174 <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="number" min="1" max="<?php echo esc_attr( $max_limit ); ?>" value="<?php echo esc_attr( $max_posts ); ?>" style="width: 30%" /></label></p> 175 <?php 176 } 177 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |