Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/08/2012 03:12:39 AM (14 years ago)
Author:
boonebgorges
Message:

Converts bp_has_groups() stack to accept parameters as an array.

Arguments passed in the old style are converted to an array automatically, for
backward compatibility.

See #3797

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-template.php

    r6259 r6321  
    108108        var $order;
    109109
    110         function __construct( $user_id, $type, $page, $per_page, $max, $slug, $search_terms, $populate_extras, $include = false, $exclude = false, $show_hidden = false, $page_arg = 'grpage' ){
     110        function __construct( $args = array() ){
     111
     112                // Backward compatibility with old method of passing arguments
     113                if ( ! is_array( $args ) || func_num_args() > 1 ) {
     114                        _deprecated_argument( __METHOD__, '1.7', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     115
     116                        $old_args_keys = array(
     117                                0  => 'user_id',
     118                                1  => 'type',
     119                                2  => 'page',
     120                                3  => 'per_page',
     121                                4  => 'max',
     122                                5  => 'slug',
     123                                6  => 'search_terms',
     124                                7  => 'populate_extras',
     125                                8  => 'include',
     126                                9  => 'exclude',
     127                                10 => 'show_hidden',
     128                                11 => 'page_arg',
     129                        );
     130
     131                        $func_args = func_get_args();
     132                        $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
     133                }
     134
     135                $defaults = array(
     136                        'type'            => 'active',
     137                        'page'            => 1,
     138                        'per_page'        => 20,
     139                        'max'             => false,
     140                        'show_hidden'     => false,
     141                        'page_arg'        => 'grpage',
     142                        'user_id'         => 0,
     143                        'slug'            => false,
     144                        'include'         => false,
     145                        'exclude'         => false,
     146                        'search_terms'    => '',
     147                        'populate_extras' => true
     148                );
     149
     150                $r = wp_parse_args( $args, $defaults );
     151                extract( $r );
    111152
    112153                $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
     
    274315
    275316        $r = wp_parse_args( $args, $defaults );
    276         extract( $r );
    277 
    278         if ( empty( $search_terms ) ) {
     317
     318        if ( empty( $r['search_terms'] ) ) {
    279319                if ( isset( $_REQUEST['group-filter-box'] ) && !empty( $_REQUEST['group-filter-box'] ) )
    280                         $search_terms = $_REQUEST['group-filter-box'];
     320                        $r['search_terms'] = $_REQUEST['group-filter-box'];
    281321                elseif ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
    282                         $search_terms = $_REQUEST['s'];
     322                        $r['search_terms'] = $_REQUEST['s'];
    283323                else
    284                         $search_terms = false;
    285         }
    286 
    287         $groups_template = new BP_Groups_Template( (int) $user_id, $type, (int) $page, (int) $per_page, (int) $max, $slug, $search_terms, (bool)$populate_extras, $include, $exclude, $show_hidden, $page_arg );
    288         return apply_filters( 'bp_has_groups', $groups_template->has_groups(), $groups_template );
     324                        $r['search_terms'] = false;
     325        }
     326
     327        $groups_template = new BP_Groups_Template( array(
     328                'type'            => $r['type'],
     329                'page'            => (int) $r['page'],
     330                'per_page'        => (int) $r['per_page'],
     331                'max'             => (int) $r['max'],
     332                'show_hidden'     => $r['show_hidden'],
     333                'page_arg'        => $r['page_arg'],
     334                'user_id'         => (int) $r['user_id'],
     335                'slug'            => $r['slug'],
     336                'search_terms'    => $r['search_terms'],
     337                'include'         => $r['include'],
     338                'exclude'         => $r['exclude'],
     339                'populate_extras' => (bool) $r['populate_extras']
     340        ) );
     341
     342        return apply_filters( 'bp_has_groups', $groups_template->has_groups(), $groups_template, $r );
    289343}
    290344
Note: See TracChangeset for help on using the changeset viewer.