Make WordPress Core


Ignore:
Timestamp:
04/16/2010 02:08:58 PM (15 years ago)
Author:
nacin
Message:

Introduce the wp_filter_object_list() helper, with an $operator arg. Fixes an intersection bug in get_post_types() and get_taxonomies(). Also switches $operator default from 'or' to 'and' for get_post_stati(). props scribu, fixes #12966.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r14077 r14108  
    6868 * @see register_taxonomy
    6969 *
    70  * @param array $args An array of key => value arguments to match against the taxonomies.
    71  *  Only taxonomies having attributes that match all arguments are returned.
     70 * @param array $args An array of key => value arguments to match against the taxonomy objects.
    7271 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
     72 * @param string $operator The logical operation to perform. 'or' means only one element
     73 *  from the array needs to match; 'and' means all elements must match. The default is 'and'.
    7374 * @return array A list of taxonomy names or objects
    7475 */
    75 function get_taxonomies( $args = array(), $output = 'names' ) {
     76function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) {
    7677    global $wp_taxonomies;
    7778
    78     $taxonomies = array();
    79     foreach ( (array) $wp_taxonomies as $taxname => $taxobj )
    80         if ( empty($args) || array_intersect_assoc((array) $taxobj, $args) )
    81             $taxonomies[$taxname] = $taxobj;
    82 
    83     if ( 'names' == $output )
    84         return array_keys($taxonomies);
    85 
    86     return $taxonomies;
    87 }
     79    $field = ('names' == $output) ? 'name' : false;
     80
     81    return wp_filter_object_list($wp_taxonomies, $args, $operator, $field);
     82}
     83
    8884
    8985/**
Note: See TracChangeset for help on using the changeset viewer.