Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/11/2019 02:37:16 AM (8 years ago)
Author:
boonebgorges
Message:

Widgets: Place an upper bound on item counts in widget forms.

This prevents widgets from triggering performance problems when initialized
with unreasonably high max item counts.

Use the bp_get_widget_max_count_limit filter to increase the default
ceiling of 50.

Fixes #8036.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-widget.php

    r12323 r12324  
    103103                echo $before_title . $title . $after_title;
    104104
     105                $max_limit  = bp_get_widget_max_count_limit( __CLASS__ );
    105106                $max_groups = ! empty( $instance['max_groups'] ) ? (int) $instance['max_groups'] : 5;
     107
     108                if ( $max_groups > $max_limit ) {
     109                        $max_groups = $max_limit;
     110                }
    106111
    107112                $group_args = array(
    … …  
    184189                $instance = $old_instance;
    185190
     191                $max_limit = bp_get_widget_max_count_limit( __CLASS__ );
     192
    186193                $instance['title']         = strip_tags( $new_instance['title'] );
    187                 $instance['max_groups']    = strip_tags( $new_instance['max_groups'] );
     194                $instance['max_groups']    = $new_instance['max_groups'] > $max_limit ? $max_limit : intval( $new_instance['max_groups'] );
    188195                $instance['group_default'] = strip_tags( $new_instance['group_default'] );
    189196                $instance['link_title']    = ! empty( $new_instance['link_title'] );
    … …  
    209216                $instance = bp_parse_args( (array) $instance, $defaults, 'groups_widget_form' );
    210217
     218                $max_limit = bp_get_widget_max_count_limit( __CLASS__ );
     219
    211220                $title         = strip_tags( $instance['title'] );
    212                 $max_groups    = strip_tags( $instance['max_groups'] );
     221                $max_groups    = $instance['max_groups'] > $max_limit ? $max_limit : intval( $instance['max_groups'] );
    213222                $group_default = strip_tags( $instance['group_default'] );
    214223                $link_title    = (bool) $instance['link_title'];
    … …  
    219228                <p><label for="<?php echo $this->get_field_id('link_title') ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title') ?>" id="<?php echo $this->get_field_id('link_title') ?>" value="1" <?php checked( $link_title ) ?> /> <?php _e( 'Link widget title to Groups directory', 'buddypress' ) ?></label></p>
    220229
    221                 <p><label for="<?php echo $this->get_field_id( 'max_groups' ); ?>"><?php _e('Max groups to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_groups' ); ?>" name="<?php echo $this->get_field_name( 'max_groups' ); ?>" type="text" value="<?php echo esc_attr( $max_groups ); ?>" style="width: 30%" /></label></p>
     230                <p><label for="<?php echo $this->get_field_id( 'max_groups' ); ?>"><?php _e( 'Max groups to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_groups' ); ?>" name="<?php echo $this->get_field_name( 'max_groups' ); ?>" type="number" min="1" max="<?php echo esc_attr( $max_limit ); ?>" value="<?php echo esc_attr( $max_groups ); ?>" style="width: 30%" /></label></p>
    222231
    223232                <p>
Note: See TracChangeset for help on using the changeset viewer.