Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/17/2012 02:01:16 PM (14 years ago)
Author:
boonebgorges
Message:

Refactors bp_has_activities() stack to support the passing of arguments as associative arrays.

  • Maintains backward compatibility by parsing old-style parameters using bp_core_parse_args_array(), converting to new-style array, and throwing _deprecated_argument() error
  • Changes calls to BP_Activity_Template::construct() and BP_Activity_Activity::get() to use the new format throughout BuddyPress
  • See #3797
File:
1 edited

Legend:

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

    r5973 r5993  
    105105    var $full_name;
    106106
    107     function __construct( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude = false, $in = false, $spam = 'ham_only', $page_arg = 'acpage' ) {
     107    /**
     108     * Constructor method
     109     *
     110     * See definition of $defaults below, as well as $defaults in bp_has_activities(), for
     111     * description of $args array
     112     *
     113     * @param array $args
     114     */
     115    function __construct( $args ) {
    108116        global $bp;
    109117
     118        // Backward compatibility with old method of passing arguments
     119        if ( !is_array( $args ) || func_num_args() > 1 ) {
     120            _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %s should be in an associative array. See the inline documentation for more details.', 'buddypress' ), __METHOD__ ) );
     121       
     122            $old_args_keys = array(
     123                0 => 'page',
     124                1 => 'per_page',
     125                2 => 'max',
     126                3 => 'include',
     127                4 => 'sort',
     128                5 => 'filter',
     129                6 => 'search_terms',
     130                7 => 'display_comments',
     131                8 => 'show_hidden',
     132                9 => 'exclude',
     133                10 => 'in',
     134                11 => 'spam',
     135                12 => 'page_arg'
     136            );
     137           
     138            $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     139        }
     140       
     141        $defaults = array(
     142            'page'             => 1,
     143            'per_page'         => 20,
     144            'page_arg'         => 'acpage',
     145            'max'              => false,
     146            'sort'             => false,
     147            'include'          => false,
     148            'exclude'          => false,
     149            'in'               => false,
     150            'filter'           => false,
     151            'search_terms'     => false,
     152            'display_comments' => 'threaded',
     153            'show_hidden'      => false,
     154            'spam'             => 'ham_only',
     155        );
     156        $r = wp_parse_args( $args, $defaults );
     157        extract( $r );
     158       
    110159        $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
    111160        $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
     
    390439        $spam = 'all';
    391440
    392     $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude, $in, $spam, $page_arg );
    393 
    394     return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template );
     441    $template_args = array(
     442        'page'             => $page,
     443        'per_page'         => $per_page,
     444        'page_arg'         => $page_arg,
     445        'max'              => $max,
     446        'sort'             => $sort,
     447        'include'          => $include,
     448        'exclude'          => $exclude,
     449        'in'               => $in,
     450        'filter'           => $filter,
     451        'search_terms'     => $search_terms,
     452        'display_comments' => $display_comments,
     453        'show_hidden'      => $show_hidden,
     454        'spam'             => $spam
     455    );
     456
     457    $activities_template = new BP_Activity_Template( $template_args );
     458
     459    return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $template_args );
    395460}
    396461
Note: See TracChangeset for help on using the changeset viewer.