Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/17/2012 02:01:16 PM (12 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-core/bp-core-functions.php

    r5992 r5993  
    952952
    953953    return apply_filters( 'bp_use_wp_admin_bar', $use_admin_bar );
     954}
     955
     956/**
     957 * A utility for parsing individual function arguments into an array.
     958 *
     959 * The purpose of this function is to help with backward compatibility in cases where
     960 *
     961 *   function foo( $bar = 1, $baz = false, $barry = array(), $blip = false ) { // ...
     962 *
     963 * is deprecated in favor of
     964 *
     965 *   function foo( $args = array() ) {
     966 *       $defaults = array(
     967 *           'bar'  => 1,
     968 *           'arg2' => false,
     969 *           'arg3' => array(),
     970 *           'arg4' => false,
     971 *       );
     972 *       $r = wp_parse_args( $args, $defaults ); // ...
     973 *
     974 * The first argument, $old_args_keys, is an array that matches the parameter positions (keys) to
     975 * the new $args keys (values):
     976 *
     977 *   $old_args_keys = array(
     978 *       0 => 'bar', // because $bar was the 0th parameter for foo()
     979 *       1 => 'baz', // because $baz was the 1st parameter for foo()
     980 *       2 => 'barry', // etc
     981 *       3 => 'blip'
     982 *   );
     983 *
     984 * For the second argument, $func_args, you should just pass func_get_args().
     985 *
     986 * @since BuddyPress (1.6)
     987 * @param array $old_args_keys
     988 * @param array $func_args
     989 * @return array $new_args
     990 */
     991function bp_core_parse_args_array( $old_args_keys, $func_args ) {
     992    $new_args = array();
     993
     994    foreach( $old_args_keys as $arg_num => $arg_key ) {
     995        if ( isset( $func_args[$arg_num] ) ) {
     996            $new_args[$arg_key] = $func_args[$arg_num];
     997        }
     998    }
     999
     1000    return $new_args;
    9541001}
    9551002
Note: See TracChangeset for help on using the changeset viewer.