Skip to:
Content

BuddyPress.org

Changeset 9469


Ignore:
Timestamp:
02/10/2015 12:59:45 AM (5 years ago)
Author:
johnjamesjacoby
Message:

Beautify bp-blogs-widgets.php:

  • Add missing semi-colons
  • Add brackets
  • Use php5 visibility on widget methods
  • Use bp_is_root_blog() rather than direct comparisons to bp_get_root_blog()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-widgets.php

    r9468 r9469  
    1717    global $wpdb;
    1818
    19     if ( bp_is_active( 'activity' ) && (int) $wpdb->blogid == bp_get_root_blog_id() )
     19    if ( bp_is_active( 'activity' ) && bp_is_root_blog( $wpdb->blogid ) ) {
    2020        add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Blogs_Recent_Posts_Widget");' ) );
     21    }
    2122}
    2223add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
     
    3031     * Constructor method.
    3132     */
    32     function __construct() {
     33    public function __construct() {
    3334        $widget_ops = array(
    3435            'description' => __( 'A list of recently published posts from across your network.', 'buddypress' ),
     
    4647     * @param array $instance Widget settings, as saved by the user.
    4748     */
    48     function widget( $args, $instance ) {
     49    public function widget( $args, $instance ) {
    4950
    50         $title = ! empty( $instance['title'] ) ? esc_html( $instance['title'] ) : __( 'Recent Networkwide Posts', 'buddypress' );
     51        $title = ! empty( $instance['title'] )
     52            ? esc_html( $instance['title'] )
     53            : __( 'Recent Networkwide Posts', 'buddypress' );
    5154
    5255        if ( ! empty( $instance['link_title'] ) ) {
     
    6669        echo $args['before_title'] . $title . $args['after_title'];
    6770
    68         if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
    69             $instance['max_posts'] = 10; ?>
     71        if ( empty( $instance['max_posts'] ) || empty( $instance['max_posts'] ) ) {
     72            $instance['max_posts'] = 10;
     73        }
    7074
    71         <?php // Override some of the contextually set parameters for bp_has_activities() ?>
    72         <?php if ( bp_has_activities( array( 'action' => 'new_blog_post', 'max' => $instance['max_posts'], 'per_page' => $instance['max_posts'], 'user_id' => 0, 'scope' => false, 'object' => false, 'primary_id' => false ) ) ) : ?>
     75        // Override some of the contextually set parameters for bp_has_activities()
     76        $args = array(
     77            'action'     => 'new_blog_post',
     78            'max'        => $instance['max_posts'],
     79            'per_page'   => $instance['max_posts'],
     80            'user_id'    => 0,
     81            'scope'      => false,
     82            'object'     => false,
     83            'primary_id' => false
     84        ); ?>
     85
     86        <?php if ( bp_has_activities( $args ) ) : ?>
    7387
    7488            <ul id="blog-post-list" class="activity-list item-list">
     
    7892                    <li>
    7993                        <div class="activity-content" style="margin: 0">
    80 
    81                             <div class="activity-header">
    82                                 <?php bp_activity_action() ?>
    83                             </div>
     94                            <div class="activity-header"><?php bp_activity_action(); ?></div>
    8495
    8596                            <?php if ( bp_get_activity_content_body() ) : ?>
    86                                 <div class="activity-inner">
    87                                     <?php bp_activity_content_body() ?>
    88                                 </div>
     97
     98                                <div class="activity-inner"><?php bp_activity_content_body(); ?></div>
     99
    89100                            <?php endif; ?>
    90101
     
    97108
    98109        <?php else : ?>
     110
    99111            <div id="message" class="info">
    100                 <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ) ?></p>
     112                <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ); ?></p>
    101113            </div>
     114
    102115        <?php endif; ?>
    103116
     
    113126     * @return array $instance The parsed options to be saved.
    114127     */
    115     function update( $new_instance, $old_instance ) {
    116         $instance = $old_instance;
    117         $instance['title'] = strip_tags( $new_instance['title'] );
    118         $instance['max_posts'] = strip_tags( $new_instance['max_posts'] );
     128    public function update( $new_instance, $old_instance ) {
     129        $instance               = $old_instance;
     130        $instance['title']      = strip_tags( $new_instance['title'] );
     131        $instance['max_posts']  = strip_tags( $new_instance['max_posts'] );
    119132        $instance['link_title'] = (bool) $new_instance['link_title'];
    120133
     
    127140     * @param $instance Settings for this widget.
    128141     */
    129     function form( $instance ) {
     142    public function form( $instance ) {
    130143        $instance = wp_parse_args( (array) $instance, array(
    131144            'title'      => __( 'Recent Networkwide Posts', 'buddypress' ),
     
    134147        ) );
    135148
    136         $title = strip_tags( $instance['title'] );
    137         $max_posts = strip_tags( $instance['max_posts'] );
     149        $title      = strip_tags( $instance['title'] );
     150        $max_posts  = strip_tags( $instance['max_posts'] );
    138151        $link_title = (bool) $instance['link_title'];
    139152
    140153        ?>
    141154
    142         <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>
    143         <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>
    144         <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>
     155        <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>
     156        <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>
     157        <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>
    145158        <?php
    146159    }
Note: See TracChangeset for help on using the changeset viewer.