WordPress.org

Make WordPress Core

Ticket #27238: 27238.diff

File 27238.diff, 13.9 KB (added by davidjlaietta, 7 years ago)
  • wp-includes/taxonomy.php

     
    123123/**
    124124 * Get a list of registered taxonomy objects.
    125125 *
     126 * @package WordPress
     127 * @subpackage Taxonomy
    126128 * @since 3.0.0
    127129 * @uses $wp_taxonomies
    128130 * @see register_taxonomy
     
    150152 * <code><?php $taxonomies = get_object_taxonomies('post'); ?></code> Should
    151153 * result in <code>Array('category', 'post_tag')</code>
    152154 *
     155 * @package WordPress
     156 * @subpackage Taxonomy
    153157 * @since 2.3.0
    154158 *
    155159 * @uses $wp_taxonomies
     
    188192 * The get_taxonomy function will first check that the parameter string given
    189193 * is a taxonomy object and if it is, it will return it.
    190194 *
     195 * @package WordPress
     196 * @subpackage Taxonomy
    191197 * @since 2.3.0
    192198 *
    193199 * @uses $wp_taxonomies
     
    210216 *
    211217 * Formerly is_taxonomy(), introduced in 2.3.0.
    212218 *
     219 * @package WordPress
     220 * @subpackage Taxonomy
    213221 * @since 3.0.0
    214222 *
    215223 * @uses $wp_taxonomies
     
    231239 *
    232240 * A false return value might also mean that the taxonomy does not exist.
    233241 *
     242 * @package WordPress
     243 * @subpackage Taxonomy
    234244 * @since 2.3.0
    235245 *
    236246 * @uses taxonomy_exists() Checks whether taxonomy exists
     
    279289 *     * If not set, the default is inherited from public.
    280290 * - show_tagcloud - Whether to list the taxonomy in the Tag Cloud Widget.
    281291 *     * If not set, the default is inherited from show_ui.
    282  * - show_admin_column - Whether to display a column for the taxonomy on its post type listing screens.
    283  *     * Defaults to false.
    284292 * - meta_box_cb - Provide a callback function for the meta box display.
    285293 *     * If not set, defaults to post_categories_meta_box for hierarchical taxonomies
    286294 *     and post_tags_meta_box for non-hierarchical.
     
    328336                'show_in_menu'          => null,
    329337                'show_in_nav_menus'     => null,
    330338                'show_tagcloud'         => null,
    331                 'show_admin_column'     => false,
    332339                'meta_box_cb'           => null,
    333340                'capabilities'          => array(),
    334341                'rewrite'               => true,
     
    478485/**
    479486 * Add an already registered taxonomy to an object type.
    480487 *
     488 * @package WordPress
     489 * @subpackage Taxonomy
    481490 * @since 3.0.0
    482491 * @uses $wp_taxonomies Modifies taxonomy object
    483492 *
     
    545554 * using PHP sort family functions or using the database by using $args with
    546555 * either ASC or DESC array. The value should be in the key named 'order'.
    547556 *
     557 * @package WordPress
     558 * @subpackage Taxonomy
    548559 * @since 2.3.0
    549560 *
    550561 * @uses $wpdb
     
    904915 * example, if 'category', it would be 'get_category' as the filter name. Useful
    905916 * for custom taxonomies or plugging into default taxonomies.
    906917 *
     918 * @package WordPress
     919 * @subpackage Taxonomy
    907920 * @since 2.3.0
    908921 *
    909922 * @uses $wpdb
     
    919932 */
    920933function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') {
    921934        global $wpdb;
     935        $null = null;
    922936
    923937        if ( empty($term) ) {
    924938                $error = new WP_Error('invalid_term', __('Empty Term'));
     
    937951                if ( is_object($term) )
    938952                        $term = $term->term_id;
    939953                if ( !$term = (int) $term )
    940                         return null;
     954                        return $null;
    941955                if ( ! $_term = wp_cache_get($term, $taxonomy) ) {
    942956                        $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term) );
    943957                        if ( ! $_term )
    944                                 return null;
     958                                return $null;
    945959                        wp_cache_add($term, $_term, $taxonomy);
    946960                }
    947961        }
     
    975989 * If $value does not exist, the return value will be false. If $taxonomy exists
    976990 * and $field and $value combinations exist, the Term will be returned.
    977991 *
     992 * @package WordPress
     993 * @subpackage Taxonomy
    978994 * @since 2.3.0
    979995 *
    980996 * @uses $wpdb
     
    10421058 *
    10431059 * Will return an empty array if $term does not exist in $taxonomy.
    10441060 *
     1061 * @package WordPress
     1062 * @subpackage Taxonomy
    10451063 * @since 2.3.0
    10461064 *
    10471065 * @uses $wpdb
     
    10801098 * reasons and for simplicity of usage. See sanitize_term_field() for more
    10811099 * information.
    10821100 *
     1101 * @package WordPress
     1102 * @subpackage Taxonomy
    10831103 * @since 2.3.0
    10841104 *
    10851105 * @uses sanitize_term_field() Passes the return value in sanitize_term_field on success.
     
    11111131 * Return value is sanitize_term() and usage is for sanitizing the term for
    11121132 * editing. Function is for contextual and simplicity.
    11131133 *
     1134 * @package WordPress
     1135 * @subpackage Taxonomy
    11141136 * @since 2.3.0
    11151137 *
    11161138 * @uses sanitize_term() Passes the return value on success
     
    12201242 * query (such as 'terms_clauses'), setting 'cache_domain' to a unique value will not overwrite
    12211243 * the cache for similar queries. Default value is 'core'.
    12221244 *
     1245 * @package WordPress
     1246 * @subpackage Taxonomy
    12231247 * @since 2.3.0
    12241248 *
    12251249 * @uses $wpdb
     
    12531277        $args['number'] = absint( $args['number'] );
    12541278        $args['offset'] = absint( $args['offset'] );
    12551279        if ( !$single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ||
    1256                 ( '' !== $args['parent'] && 0 !== $args['parent'] ) ) {
     1280                '' !== $args['parent'] ) {
    12571281                $args['child_of'] = 0;
    12581282                $args['hierarchical'] = false;
    12591283                $args['pad_counts'] = false;
     
    15251549 *
    15261550 * Formerly is_term(), introduced in 2.3.0.
    15271551 *
     1552 * @package WordPress
     1553 * @subpackage Taxonomy
    15281554 * @since 3.0.0
    15291555 *
    15301556 * @uses $wpdb
     
    16191645 *
    16201646 * The $term is expected to be either an array or an object.
    16211647 *
     1648 * @package WordPress
     1649 * @subpackage Taxonomy
    16221650 * @since 2.3.0
    16231651 *
    16241652 * @uses sanitize_term_field Used to sanitize all fields in a term
     
    16671695 * without creating your own filter function. Simply create a function that
    16681696 * hooks into the filter you need.
    16691697 *
     1698 * @package WordPress
     1699 * @subpackage Taxonomy
    16701700 * @since 2.3.0
    16711701 *
    16721702 * @uses $wpdb
     
    17251755 *
    17261756 * Default $args is 'hide_empty' which can be 'hide_empty=true' or array('hide_empty' => true).
    17271757 *
     1758 * @package WordPress
     1759 * @subpackage Taxonomy
    17281760 * @since 2.3.0
    17291761 *
    17301762 * @uses get_terms()
     
    17561788 * a particular taxonomy or taxonomies. Does not remove the term or
    17571789 * taxonomy itself.
    17581790 *
     1791 * @package WordPress
     1792 * @subpackage Taxonomy
    17591793 * @since 2.3.0
    17601794 * @uses wp_remove_object_terms()
    17611795 *
     
    17861820 *
    17871821 * The $args 'force_default' will force the term supplied as default to be
    17881822 * assigned even if the object was not going to be termless
    1789  *
     1823 * @package WordPress
     1824 * @subpackage Taxonomy
    17901825 * @since 2.3.0
    17911826 *
    17921827 * @uses $wpdb
     
    19161951 * terms objects will be returned. If either 'ids' or 'names' is used, then an
    19171952 * array of all matching term ids or term names will be returned respectively.
    19181953 *
     1954 * @package WordPress
     1955 * @subpackage Taxonomy
    19191956 * @since 2.3.0
    19201957 * @uses $wpdb
    19211958 *
     
    19331970        if ( !is_array($taxonomies) )
    19341971                $taxonomies = array($taxonomies);
    19351972
    1936         foreach ( $taxonomies as $taxonomy ) {
     1973        foreach ( (array) $taxonomies as $taxonomy ) {
    19371974                if ( ! taxonomy_exists($taxonomy) )
    19381975                        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    19391976        }
     
    22022239 * A term has no meaning until it is given context by defining which taxonomy it
    22032240 * exists under.
    22042241 *
     2242 * @package WordPress
     2243 * @subpackage Taxonomy
    22052244 * @since 2.3.0
    22062245 * @uses wp_remove_object_terms()
    22072246 *
     
    22962335/**
    22972336 * Add term(s) associated with a given object.
    22982337 *
    2299  * @since 3.6.0
     2338 * @package WordPress
     2339 * @subpackage Taxonomy
     2340 * @since 3.6
    23002341 * @uses wp_set_object_terms()
    23012342 *
    23022343 * @param int $object_id The ID of the object to which the terms will be added.
     
    23112352/**
    23122353 * Remove term(s) associated with a given object.
    23132354 *
    2314  * @since 3.6.0
     2355 * @package WordPress
     2356 * @subpackage Taxonomy
     2357 * @since 3.6
    23152358 * @uses $wpdb
    23162359 *
    23172360 * @uses apply_filters() Calls 'delete_term_relationships' hook with object_id and tt_ids as parameters.
     
    23842427 *
    23852428 * The only purpose for $term is for appending a parent, if one exists.
    23862429 *
     2430 * @package WordPress
     2431 * @subpackage Taxonomy
    23872432 * @since 2.3.0
    23882433 * @uses $wpdb
    23892434 *
     
    24552500 * For what can be overrode in $args, check the term scheme can contain and stay
    24562501 * away from the term keys.
    24572502 *
     2503 * @package WordPress
     2504 * @subpackage Taxonomy
    24582505 * @since 2.3.0
    24592506 *
    24602507 * @uses $wpdb
     
    25452592        $wpdb->update( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ), array( 'term_taxonomy_id' => $tt_id ) );
    25462593        do_action( 'edited_term_taxonomy', $tt_id, $taxonomy );
    25472594
    2548         // Clean the relationship caches for all object types using this term
    2549         $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );
    2550         $tax_object = get_taxonomy( $taxonomy );
    2551         foreach ( $tax_object->object_type as $object_type )
    2552                 clean_object_term_cache( $objects, $object_type );
    2553 
    25542595        do_action("edit_term", $term_id, $tt_id, $taxonomy);
    25552596        do_action("edit_$taxonomy", $term_id, $tt_id);
    25562597
     
    25942635 * The default action is to count what the amount of terms have the relationship
    25952636 * of term ID. Once that is done, then update the database.
    25962637 *
     2638 * @package WordPress
     2639 * @subpackage Taxonomy
    25972640 * @since 2.3.0
    25982641 * @uses $wpdb
    25992642 *
     
    26762719 * term IDs have to exist within the taxonomy $object_type for the deletion to
    26772720 * take place.
    26782721 *
     2722 * @package WordPress
     2723 * @subpackage Taxonomy
    26792724 * @since 2.3.0
    26802725 *
    26812726 * @see get_object_taxonomies() for more on $object_type
     
    26912736
    26922737        $taxonomies = get_object_taxonomies( $object_type );
    26932738
    2694         foreach ( $object_ids as $id ) {
    2695                 foreach ( $taxonomies as $taxonomy ) {
     2739        foreach ( $object_ids as $id )
     2740                foreach ( $taxonomies as $taxonomy )
    26962741                        wp_cache_delete($id, "{$taxonomy}_relationships");
    2697                 }
    2698         }
    26992742
    27002743        do_action('clean_object_term_cache', $object_ids, $object_type);
    27012744}
     
    27032746/**
    27042747 * Will remove all of the term ids from the cache.
    27052748 *
     2749 * @package WordPress
     2750 * @subpackage Taxonomy
    27062751 * @since 2.3.0
    27072752 * @uses $wpdb
    27082753 *
     
    27122757 */
    27132758function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
    27142759        global $wpdb;
     2760        static $cleaned = array();
    27152761
    27162762        if ( !is_array($ids) )
    27172763                $ids = array($ids);
     
    27392785        }
    27402786
    27412787        foreach ( $taxonomies as $taxonomy ) {
     2788                if ( isset($cleaned[$taxonomy]) )
     2789                        continue;
     2790                $cleaned[$taxonomy] = true;
     2791
    27422792                if ( $clean_taxonomy ) {
    27432793                        wp_cache_delete('all_ids', $taxonomy);
    27442794                        wp_cache_delete('get', $taxonomy);
     
    27562806/**
    27572807 * Retrieves the taxonomy relationship to the term object id.
    27582808 *
     2809 * @package WordPress
     2810 * @subpackage Taxonomy
    27592811 * @since 2.3.0
    27602812 *
    27612813 * @uses wp_cache_get() Retrieves taxonomy relationship from cache
     
    27822834 * lot of terms that exist in a lot of taxonomies. The amount of time increases
    27832835 * for each term and it also increases for each taxonomy the term belongs to.
    27842836 *
     2837 * @package WordPress
     2838 * @subpackage Taxonomy
    27852839 * @since 2.3.0
    27862840 * @uses wp_get_object_terms() Used to get terms from the database to update
    27872841 *
     
    28392893/**
    28402894 * Updates Terms to Taxonomy in cache.
    28412895 *
     2896 * @package WordPress
     2897 * @subpackage Taxonomy
    28422898 * @since 2.3.0
    28432899 *
    28442900 * @param array $terms List of Term objects to change
     
    28612917/**
    28622918 * Retrieves children of taxonomy as Term IDs.
    28632919 *
     2920 * @package WordPress
     2921 * @subpackage Taxonomy
    28642922 * @access private
    28652923 * @since 2.3.0
    28662924 *
     
    28942952 * If $terms is an array of objects, then _get_term_children returns an array of objects.
    28952953 * If $terms is an array of IDs, then _get_term_children returns an array of IDs.
    28962954 *
     2955 * @package WordPress
     2956 * @subpackage Taxonomy
    28972957 * @access private
    28982958 * @since 2.3.0
    28992959 *
     
    29222982                        $use_id = true;
    29232983                }
    29242984
    2925                 if ( $term->term_id == $term_id ) {
    2926                         if ( isset( $has_children[$term_id] ) ) {
    2927                                 $current_id = $term_id;
    2928                                 while ( $current_id > 0 ) {
    2929                                         foreach ( $has_children[$current_id] as $t_id ) {
    2930                                                 if ( $use_id ) {
    2931                                                         $term_list[] = $t_id;
    2932                                                 } else {
    2933                                                         $term_list[] = get_term( $t_id, $taxonomy );
    2934                                                 }
    2935                                         }
    2936 
    2937                                         $current_id = isset( $has_children[$t_id] ) ? $t_id : 0;
    2938                                 }
    2939                         }
     2985                if ( $term->term_id == $term_id )
    29402986                        continue;
    2941                 }
    29422987
    29432988                if ( $term->parent == $term_id ) {
    29442989                        if ( $use_id )
     
    29633008 * Recalculates term counts by including items from child terms. Assumes all
    29643009 * relevant children are already in the $terms argument.
    29653010 *
     3011 * @package WordPress
     3012 * @subpackage Taxonomy
    29663013 * @access private
    29673014 * @since 2.3.0
    29683015 * @uses $wpdb
     
    30273074 * Private function for the default callback for post_tag and category
    30283075 * taxonomies.
    30293076 *
     3077 * @package WordPress
     3078 * @subpackage Taxonomy
    30303079 * @access private
    30313080 * @since 2.3.0
    30323081 * @uses $wpdb
     
    30733122 *
    30743123 * Default callback for the link_category taxonomy.
    30753124 *
     3125 * @package WordPress
     3126 * @subpackage Taxonomy
    30763127 * @since 3.3.0
    30773128 * @uses $wpdb
    30783129 *
     
    31863237                'before' => '',
    31873238                'sep' => ' ',
    31883239                'after' => '',
    3189                 'template' => '%s: %l.'
     3240                'template' => '%s: %l.',
     3241                'links' => true,
    31903242        );
    31913243
    31923244        $r = wp_parse_args( $args, $defaults );
     
    32123264
    32133265        $args = wp_parse_args( $args, array(
    32143266                'template' => '%s: %l.',
     3267                'links' => true,
    32153268        ) );
    32163269        extract( $args, EXTR_SKIP );
    32173270
     
    32333286                if ( false === $terms )
    32343287                        $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
    32353288
    3236                 $links = array();
    32373289
    3238                 foreach ( $terms as $term )
    3239                         $links[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>";
     3290                $list = array();
     3291               
     3292                if ( $links ) {
    32403293
    3241                 if ( $links )
    3242                         $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms);
     3294                        foreach ( $terms as $term )
     3295                                $list[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>";
     3296
     3297                } else {
     3298
     3299                        foreach ( $terms as $term )
     3300                                $list[] = $term->name;
     3301
     3302                }
     3303
     3304                if ( $list )
     3305                        $taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $list, $terms);
    32433306        }
     3307
     3308        // return $args;
    32443309        return $taxonomies;
    32453310}
    32463311
     
    34153480                wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) );
    34163481
    34173482        return $parent;
    3418 }
    3419  No newline at end of file
     3483}