Make WordPress Core

Ticket #14084: garyc40.14084.2.diff

File garyc40.14084.2.diff, 4.0 KB (added by garyc40, 14 years ago)

use get_taxonomies() in get_object_taxonomies()

  • wp-includes/post.php

    diff --git wp-includes/post.php wp-includes/post.php
    index cea834b..85d812a 100644
    function wp_get_single_post($postid = 0, $mode = OBJECT) { 
    23282328        )
    23292329                return ( OBJECT == $mode ? null : array() );
    23302330
     2331        // get custom taxonomies
     2332        $taxonomies = get_object_taxonomies( $post, 'names', array( '_builtin' => false ) );
     2333        $tax_input = array();
     2334
     2335        if ( ! empty( $taxonomies ) ) {
     2336                foreach ( $taxonomies as $taxonomy ) {
     2337                        $post_terms = wp_get_post_terms( $postid, $taxonomy, array( 'fields' => 'ids' ) );
     2338                        if ( ! empty( $post_terms ) )
     2339                                $tax_input[$taxonomy] = $post_terms;
     2340                }
     2341        }
     2342
    23312343        // Set categories and tags
    23322344        if ( $mode == OBJECT ) {
    23332345                $post->post_category = array();
    function wp_get_single_post($postid = 0, $mode = OBJECT) { 
    23362348                $post->tags_input = array();
    23372349                if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
    23382350                        $post->tags_input = wp_get_post_tags($postid, array('fields' => 'names'));
     2351                $post->tax_input = $tax_input;
    23392352        } else {
    23402353                $post['post_category'] = array();
    23412354                if ( is_object_in_taxonomy($post['post_type'], 'category') )
    function wp_get_single_post($postid = 0, $mode = OBJECT) { 
    23432356                $post['tags_input'] = array();
    23442357                if ( is_object_in_taxonomy($post['post_type'], 'post_tag') )
    23452358                        $post['tags_input'] = wp_get_post_tags($postid, array('fields' => 'names'));
     2359                $post['tax_input'] = $tax_input;
    23462360        }
    2347 
    23482361        return $post;
    23492362}
    23502363
  • wp-includes/taxonomy.php

    diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php
    index 60068c5..a8c3bed 100644
    function get_taxonomies( $args = array(), $output = 'names', $operator = 'and' ) 
    140140 *
    141141 * @param array|string|object $object Name of the type of taxonomy object, or an object (row from posts)
    142142 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
     143 * @param array $args An array of key => value arguments to match against the taxonomy objects.
    143144 * @return array The names of all taxonomy of $object_type.
    144145 */
    145 function get_object_taxonomies($object, $output = 'names') {
    146         global $wp_taxonomies;
     146function get_object_taxonomies( $object, $output = 'names', $args = array() ) {
    147147
    148148        if ( is_object($object) ) {
    149149                if ( $object->post_type == 'attachment' )
    function get_object_taxonomies($object, $output = 'names') { 
    152152        }
    153153
    154154        $object = (array) $object;
    155 
    156         $taxonomies = array();
    157         foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) {
    158                 if ( array_intersect($object, (array) $tax_obj->object_type) ) {
    159                         if ( 'names' == $output )
    160                                 $taxonomies[] = $tax_name;
    161                         else
    162                                 $taxonomies[ $tax_name ] = $tax_obj;
    163                 }
     155       
     156        $list = get_taxonomies( $args, 'objects' );
     157       
     158        foreach ( $list as $tax_name => $tax_obj ) {
     159                if ( ! array_intersect($object, (array) $tax_obj->object_type) )
     160                        unset( $list[$tax_name] );
    164161        }
    165162
    166         return $taxonomies;
     163        if ( 'names' == $output )
     164                $list = array_values( wp_list_pluck( $list, 'name' ) );
     165
     166        return $list;
    167167}
    168168
    169169/**
    function is_taxonomy_hierarchical($taxonomy) { 
    256256 * boolean value.
    257257 *
    258258 * update_count_callback - works much like a hook, in that it will be called
    259  * when the count is updated.
     259 * when the count is updated; if not defined and show_ui is true, defaults to '_update_post_term_count'.
     260 * To suppress default callback in any cases, set update_count_callback to false.
    260261 *
    261262 * rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize
    262263 * permastruct; default will use $taxonomy as slug.
    function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 
    335336        if ( is_null($args['show_ui']) )
    336337                $args['show_ui'] = $args['public'];
    337338
     339        if ( $args['show_ui'] && $args['update_count_callback'] === '' ) {
     340                $args['update_count_callback'] = '_update_post_term_count';
     341        }
     342
    338343        // Whether to show this type in nav-menus.php. Defaults to the setting for public.
    339344        if ( null === $args['show_in_nav_menus'] )
    340345                $args['show_in_nav_menus'] = $args['public'];