Make WordPress Core

Ticket #12516: get_taxonomies.diff

File get_taxonomies.diff, 1.5 KB (added by ptahdunbar, 15 years ago)
  • wp-includes/taxonomy.php

     
    5656add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
    5757
    5858/**
     59 * Get a list of all registered taxonomy objects.
     60 *
     61 * @package WordPress
     62 * @subpackage Taxonomy
     63 * @since 2.9.0
     64 * @uses $wp_taxonomies
     65 * @see register_taxonomy
     66 *
     67 * @param array|string $args An array of key => value arguments to match against the taxonomies.
     68 *  Only taxonomies having attributes that match all arguments are returned.
     69 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
     70 * @return array A list of taxonomy names or objects
     71 */
     72function get_taxonomies( $args = array(), $output = 'names' ) {
     73        global $wp_taxonomies;
     74
     75        $do_names = false;
     76        if ( 'names' == $output )
     77                $do_names = true;
     78
     79        $taxonomies = array();
     80        foreach ( (array) $wp_taxonomies as $taxonomy ) {
     81                if ( empty($args) ) {
     82                        if ( $do_names )
     83                                $taxonomies[] = $taxonomy->name;
     84                        else
     85                                $taxonomies[] = $taxonomy;
     86                } elseif ( array_intersect_assoc((array) $taxonomy, $args) ) {
     87                        if ( $do_names )
     88                                $taxonomies[] = $taxonomy->name;
     89                        else
     90                                $taxonomies[] = $taxonomy;
     91                }
     92        }
     93
     94        return $taxonomies;
     95}
     96
     97/**
    5998 * Return all of the taxonomy names that are of $object_type.
    6099 *
    61100 * It appears that this function can be used to find all of the names inside of