Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/wp-includes/taxonomy.php

    r17443 r15426  
    1919                'hierarchical' => true,
    2020                'update_count_callback' => '_update_post_term_count',
    21                 'query_var' => 'category_name',
    22                 'rewrite' => did_action( 'init' ) ? array(
    23                                         'hierarchical' => true,
    24                                         'slug' => get_option('category_base') ? get_option('category_base') : 'category',
    25                                         'with_front' => false) : false,
     21                'query_var' => false,
     22                'rewrite' => false,
     23                'public' => true,
     24                'show_ui' => true,
     25                '_builtin' => true,
     26        ) ) ;
     27
     28        register_taxonomy( 'post_tag', 'post', array(
     29                'hierarchical' => false,
     30                'update_count_callback' => '_update_post_term_count',
     31                'query_var' => false,
     32                'rewrite' => false,
    2633                'public' => true,
    2734                'show_ui' => true,
    … …  
    2936        ) );
    3037
    31         register_taxonomy( 'post_tag', 'post', array(
    32                 'hierarchical' => false,
    33                 'update_count_callback' => '_update_post_term_count',
    34                 'query_var' => 'tag',
    35                 'rewrite' => did_action( 'init' ) ? array(
    36                                         'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
    37                                         'with_front' => false) : false,
    38                 'public' => true,
    39                 'show_ui' => true,
    40                 '_builtin' => true,
    41         ) );
    42 
    4338        register_taxonomy( 'nav_menu', 'nav_menu_item', array(
    44                 'public' => false,
    4539                'hierarchical' => false,
    4640                'labels' => array(
    … …  
    5347                '_builtin' => true,
    5448                'show_in_nav_menus' => false,
    55         ) );
     49        ) ) ;
    5650
    5751        register_taxonomy( 'link_category', 'link', array(
    5852                'hierarchical' => false,
    5953                'labels' => array(
    60                         'name' => __( 'Link Categories' ),
    61                         'singular_name' => __( 'Link Category' ),
    62                         'search_items' => __( 'Search Link Categories' ),
    63                         'popular_items' => null,
    64                         'all_items' => __( 'All Link Categories' ),
    65                         'edit_item' => __( 'Edit Link Category' ),
    66                         'update_item' => __( 'Update Link Category' ),
    67                         'add_new_item' => __( 'Add New Link Category' ),
    68                         'new_item_name' => __( 'New Link Category Name' ),
    69                         'separate_items_with_commas' => null,
    70                         'add_or_remove_items' => null,
    71                         'choose_from_most_used' => null,
     54                        'name' => __( 'Categories' ),
     55                        'singular_name' => __( 'Category' ),
     56                        'update_item' => __( 'Update Category' ),
    7257                ),
    7358                'query_var' => false,
    … …  
    7661                'show_ui' => false,
    7762                '_builtin' => true,
    78         ) );
    79 
    80         $rewrite = false;
    81         if ( did_action( 'init' ) ) {
    82                 $rewrite = apply_filters( 'post_format_rewrite_base', 'type' );
    83                 $rewrite = $rewrite ? array( 'slug' => $rewrite ) : false;
    84         }
    85 
    86         register_taxonomy( 'post_format', 'post', array(
    87                 'public' => true,
    88                 'hierarchical' => false,
    89                 'labels' => array(
    90                         'name' => _x( 'Format', 'post format' ),
    91                         'singular_name' => _x( 'Format', 'post format' ),
    92                 ),
    93                 'query_var' => true,
    94                 'rewrite' => $rewrite,
    95                 'show_ui' => false,
    96                 '_builtin' => true,
    97                 'show_in_nav_menus' => false,
    98         ) );
     63        ) ) ;
    9964}
    10065add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
    … …  
    321286                        'slug' => sanitize_title_with_dashes($taxonomy),
    322287                        'with_front' => true,
    323                         'hierarchical' => false
    324288                ));
    325 
    326                 if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] )
    327                         $tag = '(.+?)';
    328                 else
    329                         $tag = '([^/]+)';
    330 
    331                 $wp_rewrite->add_rewrite_tag("%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");
    332                 $wp_rewrite->add_permastruct($taxonomy, "{$wp_rewrite->root}{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']);
     289                $wp_rewrite->add_rewrite_tag("%$taxonomy%", '([^/]+)', $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");
     290                $wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']);
    333291        }
    334292
    … …  
    361319
    362320        // register callback handling for metabox
    363         add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
     321        add_filter('wp_ajax_add-'.$taxonomy, '_wp_ajax_add_hierarchical_term');
    364322}
    365323
    … …  
    410368                'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ),
    411369        );
    412         $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
    413370
    414371        return _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );
    … …  
    504461
    505462        return $object_ids;
    506 }
    507 
    508 /**
    509  * Given a taxonomy query, generates SQL to be appended to a main query.
    510  *
    511  * @since 3.1.0
    512  *
    513  * @see WP_Tax_Query
    514  *
    515  * @param array $tax_query A compact tax query
    516  * @param string $primary_table
    517  * @param string $primary_id_column
    518  * @return array
    519  */
    520 function get_tax_sql( $tax_query, $primary_table, $primary_id_column ) {
    521         $tax_query_obj = new WP_Tax_Query( $tax_query );
    522         return $tax_query_obj->get_sql( $primary_table, $primary_id_column );
    523 }
    524 
    525 /**
    526  * Container class for a multiple taxonomy query.
    527  *
    528  * @since 3.1.0
    529  */
    530 class WP_Tax_Query {
    531 
    532         /**
    533          * List of taxonomy queries. A single taxonomy query is an associative array:
    534          * - 'taxonomy' string The taxonomy being queried
    535          * - 'terms' string|array The list of terms
    536          * - 'field' string (optional) Which term field is being used.
    537          *              Possible values: 'term_id', 'slug' or 'name'
    538          *              Default: 'term_id'
    539          * - 'operator' string (optional)
    540          *              Possible values: 'IN' and 'NOT IN'.
    541          *              Default: 'IN'
    542          * - 'include_children' bool (optional) Whether to include child terms.
    543          *              Default: true
    544          *
    545          * @since 3.1.0
    546          * @access public
    547          * @var array
    548          */
    549         var $queries = array();
    550 
    551         /**
    552          * The relation between the queries. Can be one of 'AND' or 'OR'.
    553          *
    554          * @since 3.1.0
    555          * @access public
    556          * @var string
    557          */
    558         var $relation;
    559 
    560         /**
    561          * PHP4 type constructor.
    562          *
    563          * Parses a compact tax query and sets defaults.
    564          *
    565          * @since 3.1.0
    566          * @access public
    567          *
    568          * @param array $tax_query A compact tax query:
    569          *  array(
    570          *    'relation' => 'OR',
    571          *    array(
    572          *      'taxonomy' => 'tax1',
    573          *      'terms' => array( 'term1', 'term2' ),
    574          *      'field' => 'slug',
    575          *    ),
    576          *    array(
    577          *      'taxonomy' => 'tax2',
    578          *      'terms' => array( 'term-a', 'term-b' ),
    579          *      'field' => 'slug',
    580          *    ),
    581          *  )
    582          *
    583          * @return WP_Tax_Query
    584          */
    585         function WP_Tax_Query( $tax_query ) {
    586                 if ( isset( $tax_query['relation'] ) && strtoupper( $tax_query['relation'] ) == 'OR' ) {
    587                         $this->relation = 'OR';
    588                 } else {
    589                         $this->relation = 'AND';
    590                 }
    591 
    592                 $defaults = array(
    593                         'taxonomy' => '',
    594                         'terms' => array(),
    595                         'include_children' => true,
    596                         'field' => 'term_id',
    597                         'operator' => 'IN',
    598                 );
    599 
    600                 foreach ( $tax_query as $query ) {
    601                         if ( ! is_array( $query ) )
    602                                 continue;
    603 
    604                         $query = array_merge( $defaults, $query );
    605 
    606                         $query['terms'] = (array) $query['terms'];
    607 
    608                         $this->queries[] = $query;
    609                 }
    610         }
    611 
    612         /**
    613          * Generates SQL clauses to be appended to a main query.
    614          *
    615          * @since 3.1.0
    616          * @access public
    617          *
    618          * @param string $primary_table
    619          * @param string $primary_id_column
    620          * @return array
    621          */
    622         function get_sql( $primary_table, $primary_id_column ) {
    623                 global $wpdb;
    624 
    625                 $join = '';
    626                 $where = array();
    627                 $i = 0;
    628 
    629                 foreach ( $this->queries as $query ) {
    630                         extract( $query );
    631 
    632                         if ( ! taxonomy_exists( $taxonomy ) )
    633                                 return array( 'join' => '', 'where' => ' AND 0 = 1');
    634 
    635                         $terms = array_unique( (array) $terms );
    636 
    637                         if ( empty( $terms ) )
    638                                 continue;
    639 
    640                         if ( is_taxonomy_hierarchical( $taxonomy ) && $include_children ) {
    641                                 $this->_transform_terms( $terms, $taxonomy, $field, 'term_id' );
    642 
    643                                 $children = array();
    644                                 foreach ( $terms as $term ) {
    645                                         $children = array_merge( $children, get_term_children( $term, $taxonomy ) );
    646                                         $children[] = $term;
    647                                 }
    648                                 $terms = $children;
    649 
    650                                 $this->_transform_terms( $terms, $taxonomy, 'term_id', 'term_taxonomy_id' );
    651                         }
    652                         else {
    653                                 $this->_transform_terms( $terms, $taxonomy, $field, 'term_taxonomy_id' );
    654                         }
    655 
    656                         if ( 'IN' == $operator ) {
    657 
    658                                 if ( empty( $terms ) ) {
    659                                         if ( 'OR' == $this->relation )
    660                                                 continue;
    661                                         else
    662                                                 return array( 'join' => '', 'where' => ' AND 0 = 1' );
    663                                 }
    664 
    665                                 $terms = implode( ',', $terms );
    666 
    667                                 $alias = $i ? 'tt' . $i : $wpdb->term_relationships;
    668 
    669                                 $join .= " INNER JOIN $wpdb->term_relationships";
    670                                 $join .= $i ? " AS $alias" : '';
    671                                 $join .= " ON ($primary_table.$primary_id_column = $alias.object_id)";
    672 
    673                                 $where[] = "$alias.term_taxonomy_id $operator ($terms)";
    674                         } elseif ( 'NOT IN' == $operator ) {
    675 
    676                                 if ( empty( $terms ) )
    677                                         continue;
    678 
    679                                 $terms = implode( ',', $terms );
    680 
    681                                 $where[] = "$primary_table.$primary_id_column NOT IN (
    682                                         SELECT object_id
    683                                         FROM $wpdb->term_relationships
    684                                         WHERE term_taxonomy_id IN ($terms)
    685                                 )";
    686                         } elseif ( 'AND' == $operator ) {
    687 
    688                                 if ( empty( $terms ) )
    689                                         continue;
    690 
    691                                 $num_terms = count( $terms );
    692 
    693                                 $terms = implode( ',', $terms );
    694 
    695                                 $where[] = "$primary_table.$primary_id_column IN (
    696                                         SELECT object_id
    697                                         FROM $wpdb->term_relationships
    698                                         WHERE term_taxonomy_id IN ($terms)
    699                                         GROUP BY object_id HAVING COUNT(object_id) = $num_terms
    700                                 )";
    701                         }
    702 
    703                         $i++;
    704                 }
    705 
    706                 if ( !empty( $where ) )
    707                         $where = ' AND ( ' . implode( " $this->relation ", $where ) . ' )';
    708                 else
    709                         $where = '';
    710 
    711                 return compact( 'join', 'where' );
    712         }
    713 
    714         /**
    715          * Transforms a list of terms, from one field to another.
    716          *
    717          * @since 3.1.0
    718          * @access private
    719          *
    720          * @param array &$terms The list of terms
    721          * @param string $taxonomy The taxonomy of the terms
    722          * @param string $field The initial field
    723          * @param string $resulting_field The resulting field
    724          */
    725         function _transform_terms( &$terms, $taxonomy, $field, $resulting_field ) {
    726                 global $wpdb;
    727 
    728                 if ( empty( $terms ) )
    729                         return;
    730 
    731                 if ( $field == $resulting_field )
    732                         return;
    733 
    734                 $resulting_field = esc_sql( $resulting_field );
    735 
    736                 switch ( $field ) {
    737                         case 'slug':
    738                         case 'name':
    739                                 $terms = "'" . implode( "','", array_map( 'sanitize_title_for_query', $terms ) ) . "'";
    740                                 $terms = $wpdb->get_col( "
    741                                         SELECT $wpdb->term_taxonomy.$resulting_field
    742                                         FROM $wpdb->term_taxonomy
    743                                         INNER JOIN $wpdb->terms USING (term_id)
    744                                         WHERE taxonomy = '$taxonomy'
    745                                         AND $wpdb->terms.$field IN ($terms)
    746                                 " );
    747                                 break;
    748 
    749                         default:
    750                                 $terms = implode( ',', array_map( 'intval', $terms ) );
    751                                 $terms = $wpdb->get_col( "
    752                                         SELECT $resulting_field
    753                                         FROM $wpdb->term_taxonomy
    754                                         WHERE taxonomy = '$taxonomy'
    755                                         AND term_id IN ($terms)
    756                                 " );
    757                 }
    758         }
    759463}
    760464
    … …  
    928632 * @uses get_term_children() Used to get the children of both $taxonomy and the parent $term
    929633 *
    930  * @param string $term_id ID of Term to get children
     634 * @param string $term ID of Term to get children
    931635 * @param string $taxonomy Taxonomy Name
    932636 * @return array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist
    … …  
    1103807 * @uses wp_parse_args() Merges the defaults with those defined by $args and allows for strings.
    1104808 *
    1105  * @param string|array $taxonomies Taxonomy name or list of Taxonomy names
     809 * @param string|array Taxonomy name or list of Taxonomy names
    1106810 * @param string|array $args The values of what to search for when returning terms
    1107811 * @return array|WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies do not exist.
    … …  
    1117821        }
    1118822
    1119         foreach ( $taxonomies as $taxonomy ) {
     823        foreach ( (array) $taxonomies as $taxonomy ) {
    1120824                if ( ! taxonomy_exists($taxonomy) ) {
    1121825                        $error = & new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    … …  
    1123827                }
    1124828        }
     829
     830        $in_taxonomies = "'" . implode("', '", $taxonomies) . "'";
    1125831
    1126832        $defaults = array('orderby' => 'name', 'order' => 'ASC',
    … …  
    1145851                $args['pad_counts'] = false;
    1146852        }
    1147 
    1148         $args = apply_filters( 'get_terms_args', $args, $taxonomies );
    1149 
    1150853        extract($args, EXTR_SKIP);
    1151854
    … …  
    1198901                $order = '';
    1199902
    1200         $where = "tt.taxonomy IN ('" . implode("', '", $taxonomies) . "')";
     903        $where = '';
    1201904        $inclusions = '';
    1202905        if ( !empty($include) ) {
    … …  
    1220923                $excluded_trunks = wp_parse_id_list($exclude_tree);
    1221924                foreach ( $excluded_trunks as $extrunk ) {
    1222                         $excluded_children = (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids', 'hide_empty' => 0));
     925                        $excluded_children = (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids'));
    1223926                        $excluded_children[] = $extrunk;
    1224927                        foreach( $excluded_children as $exterm ) {
    … …  
    1252955
    1253956        if ( !empty($name__like) )
    1254                 $where .= " AND t.name LIKE '" . like_escape( $name__like ) . "%'";
     957                $where .= " AND t.name LIKE '{$name__like}%'";
    1255958
    1256959        if ( '' !== $parent ) {
    … …  
    1265968        if ( ! empty($number) && ! $hierarchical && empty( $child_of ) && '' === $parent ) {
    1266969                if ( $offset )
    1267                         $limits = 'LIMIT ' . $offset . ',' . $number;
     970                        $limit = 'LIMIT ' . $offset . ',' . $number;
    1268971                else
    1269                         $limits = 'LIMIT ' . $number;
     972                        $limit = 'LIMIT ' . $number;
    1270973        } else {
    1271                 $limits = '';
     974                $limit = '';
    1272975        }
    1273976
    … …  
    1279982        $selects = array();
    1280983        switch ( $fields ) {
    1281                 case 'all':
    1282                         $selects = array('t.*', 'tt.*');
    1283                         break;
    1284                 case 'ids':
     984                case 'all':
     985                        $selects = array('t.*', 'tt.*');
     986                        break;
     987                case 'ids':
    1285988                case 'id=>parent':
    1286                         $selects = array('t.term_id', 'tt.parent', 'tt.count');
    1287                         break;
    1288                 case 'names':
    1289                         $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name');
    1290                         break;
    1291                 case 'count':
     989                        $selects = array('t.term_id', 'tt.parent', 'tt.count');
     990                        break;
     991                case 'names':
     992                        $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name');
     993                        break;
     994                case 'count':
    1292995                        $orderby = '';
    1293996                        $order = '';
    1294                         $selects = array('COUNT(*)');
    1295         }
    1296 
    1297         $_fields = $fields;
    1298 
    1299         $fields = implode(', ', apply_filters( 'get_terms_fields', $selects, $args ));
    1300 
    1301         $join = "INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id";
    1302 
    1303         $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' );
    1304         $clauses = apply_filters( 'terms_clauses', compact( $pieces ), $taxonomies, $args );
    1305         foreach ( $pieces as $piece )
    1306                 $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
    1307 
    1308         $query = "SELECT $fields FROM $wpdb->terms AS t $join WHERE $where $orderby $order $limits";
    1309 
    1310         $fields = $_fields;
     997                        $selects = array('COUNT(*)');
     998        }
     999    $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args ));
     1000
     1001        $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where $orderby $order $limit";
    13111002
    13121003        if ( 'count' == $fields ) {
    … …  
    13211012
    13221013        if ( empty($terms) ) {
    1323                 wp_cache_add( $cache_key, array(), 'terms', 86400 ); // one day
     1014                wp_cache_add( $cache_key, array(), 'terms' );
    13241015                $terms = apply_filters('get_terms', array(), $taxonomies, $args);
    13251016                return $terms;
    … …  
    13721063        }
    13731064
    1374         wp_cache_add( $cache_key, $terms, 'terms', 86400 ); // one day
     1065        wp_cache_add( $cache_key, $terms, 'terms' );
    13751066
    13761067        $terms = apply_filters('get_terms', $terms, $taxonomies, $args);
    … …  
    15331224
    15341225        if ( 'edit' == $context ) {
    1535                 $value = apply_filters("edit_term_{$field}", $value, $term_id, $taxonomy);
    1536                 $value = apply_filters("edit_{$taxonomy}_{$field}", $value, $term_id);
     1226                $value = apply_filters("edit_term_$field", $value, $term_id, $taxonomy);
     1227                $value = apply_filters("edit_${taxonomy}_$field", $value, $term_id);
    15371228                if ( 'description' == $field )
    1538                         $value = esc_html($value); // textarea_escaped
     1229                        $value = format_to_edit($value);
    15391230                else
    15401231                        $value = esc_attr($value);
    15411232        } else if ( 'db' == $context ) {
    1542                 $value = apply_filters("pre_term_{$field}", $value, $taxonomy);
    1543                 $value = apply_filters("pre_{$taxonomy}_{$field}", $value);
     1233                $value = apply_filters("pre_term_$field", $value, $taxonomy);
     1234                $value = apply_filters("pre_${taxonomy}_$field", $value);
    15441235                // Back compat filters
    15451236                if ( 'slug' == $field )
    … …  
    15471238
    15481239        } else if ( 'rss' == $context ) {
    1549                 $value = apply_filters("term_{$field}_rss", $value, $taxonomy);
    1550                 $value = apply_filters("{$taxonomy}_{$field}_rss", $value);
     1240                $value = apply_filters("term_${field}_rss", $value, $taxonomy);
     1241                $value = apply_filters("${taxonomy}_${field}_rss", $value);
    15511242        } else {
    15521243                // Use display filters by default.
    1553                 $value = apply_filters("term_{$field}", $value, $term_id, $taxonomy, $context);
    1554                 $value = apply_filters("{$taxonomy}_{$field}", $value, $term_id, $context);
     1244                $value = apply_filters("term_$field", $value, $term_id, $taxonomy, $context);
     1245                $value = apply_filters("${taxonomy}_$field", $value, $term_id, $context);
    15551246        }
    15561247
    … …  
    15951286
    15961287/**
    1597  * Will unlink the object from the taxonomy or taxonomies.
    1598  *
    1599  * Will remove all relationships between the object and any terms in
    1600  * a particular taxonomy or taxonomies. Does not remove the term or
    1601  * taxonomy itself.
     1288 * Will unlink the term from the taxonomy.
     1289 *
     1290 * Will remove the term's relationship to the taxonomy, not the term or taxonomy
     1291 * itself. The term and taxonomy will still exist. Will require the term's
     1292 * object ID to perform the operation.
    16021293 *
    16031294 * @package WordPress
    … …  
    16071298 *
    16081299 * @param int $object_id The term Object Id that refers to the term
    1609  * @param string|array $taxonomies List of Taxonomy Names or single Taxonomy name.
     1300 * @param string|array $taxonomy List of Taxonomy Names or single Taxonomy name.
    16101301 */
    16111302function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
    … …  
    16651356
    16661357        $defaults = array();
    1667 
    1668         if ( 'category' == $taxonomy ) {
    1669                 $defaults['default'] = get_option( 'default_category' );
    1670                 if ( $defaults['default'] == $term )
    1671                         return 0; // Don't delete the default category
    1672         }
    1673 
    16741358        $args = wp_parse_args($args, $defaults);
    16751359        extract($args, EXTR_SKIP);
    16761360
    1677         if ( isset( $default ) ) {
     1361        if ( isset($default) ) {
    16781362                $default = (int) $default;
    16791363                if ( ! term_exists($default, $taxonomy) )
    … …  
    17091393        }
    17101394
    1711         // Clean the relationship caches for all object types using this term
    1712         $tax_object = get_taxonomy( $taxonomy );
    1713         foreach ( $tax_object->object_type as $object_type )
    1714                 clean_object_term_cache( $objects, $object_type );
    1715 
    17161395        do_action( 'delete_term_taxonomy', $tt_id );
    17171396        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $tt_id ) );
    … …  
    17281407
    17291408        return true;
    1730 }
    1731 
    1732 /**
    1733  * Deletes one existing category.
    1734  *
    1735  * @since 2.0.0
    1736  * @uses wp_delete_term()
    1737  *
    1738  * @param int $cat_ID
    1739  * @return mixed Returns true if completes delete action; false if term doesnt exist;
    1740  *      Zero on attempted deletion of default Category; WP_Error object is also a possibility.
    1741  */
    1742 function wp_delete_category( $cat_ID ) {
    1743         return wp_delete_term( $cat_ID, 'category' );
    17441409}
    17451410
    … …  
    17711436 * @uses $wpdb
    17721437 *
    1773  * @param int|array $object_ids The ID(s) of the object(s) to retrieve.
     1438 * @param int|array $object_id The id of the object(s) to retrieve.
    17741439 * @param string|array $taxonomies The taxonomies to retrieve terms from.
    17751440 * @param array|string $args Change what is returned
    … …  
    20411706 *
    20421707 * @param int $object_id The object to relate to.
    2043  * @param array|int|string $terms The slug or id of the term, will replace all existing
     1708 * @param array|int|string $term The slug or id of the term, will replace all existing
    20441709 * related terms in this taxonomy.
    20451710 * @param array|string $taxonomy The context in which to relate the term to the object.
    … …  
    22721937        }
    22731938
    2274         // Check $parent to see if it will cause a hierarchy loop
    2275         $parent = apply_filters( 'wp_update_term_parent', $parent, $term_id, $taxonomy, compact( array_keys( $args ) ), $args );
    2276 
    22771939        // Check for duplicate slug
    22781940        $id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) );
    … …  
    28102472 * @since 2.5.0
    28112473 *
    2812  * @uses apply_filters() Calls 'term_link' with term link and term object, and taxonomy parameters.
    2813  * @uses apply_filters() For the post_tag Taxonomy, Calls 'tag_link' with tag link and tag ID as parameters.
    2814  * @uses apply_filters() For the category Taxonomy, Calls 'category_link' filter on category link and category ID.
    2815  *
    28162474 * @param object|int|string $term
    2817  * @param string $taxonomy (optional if $term is object)
    2818  * @return string|WP_Error HTML link to taxonomy term archive on success, WP_Error if term does not exist.
    2819  */
    2820 function get_term_link( $term, $taxonomy = '') {
     2475 * @param string $taxonomy
     2476 * @return string HTML link to taxonomy term archive
     2477 */
     2478function get_term_link( $term, $taxonomy ) {
    28212479        global $wp_rewrite;
    28222480
    … …  
    28352493                return $term;
    28362494
    2837         $taxonomy = $term->taxonomy;
     2495        // use legacy functions for core taxonomies until they are fully plugged in
     2496        if ( $taxonomy == 'category' )
     2497                return get_category_link((int) $term->term_id);
     2498        if ( $taxonomy == 'post_tag' )
     2499                return get_tag_link((int) $term->term_id);
    28382500
    28392501        $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
    28402502
    28412503        $slug = $term->slug;
    2842         $t = get_taxonomy($taxonomy);
    28432504
    28442505        if ( empty($termlink) ) {
     2506                $t = get_taxonomy($taxonomy);
    28452507                if ( $t->query_var )
    28462508                        $termlink = "?$t->query_var=$slug";
    … …  
    28492511                $termlink = home_url($termlink);
    28502512        } else {
    2851                 if ( $t->rewrite['hierarchical'] ) {
    2852                         $hierarchical_slugs = array();
    2853                         $ancestors = get_ancestors($term->term_id, $taxonomy);
    2854                         foreach ( (array)$ancestors as $ancestor ) {
    2855                                 $ancestor_term = get_term($ancestor, $taxonomy);
    2856                                 $hierarchical_slugs[] = $ancestor_term->slug;
    2857                         }
    2858                         $hierarchical_slugs = array_reverse($hierarchical_slugs);
    2859                         $hierarchical_slugs[] = $slug;
    2860                         $termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink);
    2861                 } else {
    2862                         $termlink = str_replace("%$taxonomy%", $slug, $termlink);
    2863                 }
     2513                $termlink = str_replace("%$taxonomy%", $slug, $termlink);
    28642514                $termlink = home_url( user_trailingslashit($termlink, 'category') );
    28652515        }
    2866         // Back Compat filters.
    2867         if ( 'post_tag' == $taxonomy )
    2868                 $termlink = apply_filters( 'tag_link', $termlink, $term->term_id );
    2869         elseif ( 'category' == $taxonomy )
    2870                 $termlink = apply_filters( 'category_link', $termlink, $term->term_id );
    2871 
    28722516        return apply_filters('term_link', $termlink, $term, $taxonomy);
    28732517}
    … …  
    28852529 * 'sep' : default is empty string. Separate every taxonomy with value in this.
    28862530 * 'after' : default is empty string. Display this after the taxonomies list.
    2887  * 'template' : The template to use for displaying the taxonomy terms.
    28882531 *
    28892532 * @since 2.5.0
    … …  
    28982541                'sep' => ' ',
    28992542                'after' => '',
    2900                 'template' => '%s: %l.'
    29012543        );
    29022544
    … …  
    29042546        extract( $r, EXTR_SKIP );
    29052547
    2906         echo $before . join($sep, get_the_taxonomies($post, $r)) . $after;
     2548        echo $before . join($sep, get_the_taxonomies($post)) . $after;
    29072549}
    29082550
    … …  
    29162558 *
    29172559 * @param int $post Optional. Post ID or will use Global Post ID (in loop).
    2918  * @param array $args Override the defaults.
    29192560 * @return array
    29202561 */
    2921 function get_the_taxonomies($post = 0, $args = array() ) {
     2562function get_the_taxonomies($post = 0) {
    29222563        if ( is_int($post) )
    29232564                $post =& get_post($post);
    … …  
    29252566                $post =& $GLOBALS['post'];
    29262567
    2927         $args = wp_parse_args( $args, array(
    2928                 'template' => '%s: %l.',
    2929         ) );
    2930         extract( $args, EXTR_SKIP );
    2931 
    29322568        $taxonomies = array();
    29332569
    29342570        if ( !$post )
    29352571                return $taxonomies;
     2572
     2573        $template = apply_filters('taxonomy_template', '%s: %l.');
    29362574
    29372575        foreach ( get_object_taxonomies($post) as $taxonomy ) {
    … …  
    29512589
    29522590                foreach ( $terms as $term )
    2953                         $links[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>";
     2591                        $links[] = "<a href='" . esc_attr(get_term_link($term, $taxonomy)) . "'>$term->name</a>";
    29542592
    29552593                if ( $links )
    … …  
    29852623 * @uses wp_get_object_terms()
    29862624 *
    2987  * @param int $object_id ID of the object (post ID, link ID, ...)
    2988  * @param string $taxonomy Single taxonomy name
     2625 * @param int $object_id. ID of the object (post ID, link ID, ...)
     2626 * @param string $taxonomy. Single taxonomy name
    29892627 * @param int|string|array $terms Optional.  Term term_id, name, slug or array of said
    29902628 * @return bool|WP_Error. WP_Error on input error.
    … …  
    30312669 *
    30322670 * @param string $object_type Object type string
    3033  * @param string $taxonomy Single taxonomy name
     2671 * @param string $taxonomy. Single taxonomy name
    30342672 * @return bool True if object is associated with the taxonomy, otherwise false.
    30352673 */
    … …  
    30452683        return false;
    30462684}
    3047 
    3048 /**
    3049  * Get an array of ancestor IDs for a given object.
    3050  *
    3051  * @param int $object_id The ID of the object
    3052  * @param string $object_type The type of object for which we'll be retrieving ancestors.
    3053  * @return array of ancestors from lowest to highest in the hierarchy.
    3054  */
    3055 function get_ancestors($object_id = 0, $object_type = '') {
    3056         $object_id = (int) $object_id;
    3057 
    3058         $ancestors = array();
    3059 
    3060         if ( empty( $object_id ) ) {
    3061                 return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
    3062         }
    3063 
    3064         if ( is_taxonomy_hierarchical( $object_type ) ) {
    3065                 $term = get_term($object_id, $object_type);
    3066                 while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
    3067                         $ancestors[] = (int) $term->parent;
    3068                         $term = get_term($term->parent, $object_type);
    3069                 }
    3070         } elseif ( null !== get_post_type_object( $object_type ) ) {
    3071                 $object = get_post($object_id);
    3072                 if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) )
    3073                         $ancestors = $object->ancestors;
    3074                 else {
    3075                         while ( ! is_wp_error($object) && ! empty( $object->post_parent ) && ! in_array( $object->post_parent, $ancestors ) ) {
    3076                                 $ancestors[] = (int) $object->post_parent;
    3077                                 $object = get_post($object->post_parent);
    3078                         }
    3079                 }
    3080         }
    3081 
    3082         return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);
    3083 }
    3084 
    3085 /**
    3086  * Returns the term's parent's term_ID
    3087  *
    3088  * @since 3.1.0
    3089  *
    3090  * @param int $term_id
    3091  * @param string $taxonomy
    3092  *
    3093  * @return int|bool false on error
    3094  */
    3095 function wp_get_term_taxonomy_parent_id( $term_id, $taxonomy ) {
    3096         $term = get_term( $term_id, $taxonomy );
    3097         if ( !$term || is_wp_error( $term ) )
    3098                 return false;
    3099         return (int) $term->parent;
    3100 }
    3101 
    3102 /**
    3103  * Checks the given subset of the term hierarchy for hierarchy loops.
    3104  * Prevents loops from forming and breaks those that it finds.
    3105  *
    3106  * Attached to the wp_update_term_parent filter.
    3107  *
    3108  * @since 3.1.0
    3109  * @uses wp_find_hierarchy_loop()
    3110  *
    3111  * @param int $parent term_id of the parent for the term we're checking.
    3112  * @param int $term_id The term we're checking.
    3113  * @param string $taxonomy The taxonomy of the term we're checking.
    3114  *
    3115  * @return int The new parent for the term.
    3116  */
    3117 function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) {
    3118         // Nothing fancy here - bail
    3119         if ( !$parent )
    3120                 return 0;
    3121 
    3122         // Can't be its own parent
    3123         if ( $parent == $term_id )
    3124                 return 0;
    3125 
    3126         // Now look for larger loops
    3127 
    3128         if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) )
    3129                 return $parent; // No loop
    3130 
    3131         // Setting $parent to the given value causes a loop
    3132         if ( isset( $loop[$term_id] ) )
    3133                 return 0;
    3134 
    3135         // There's a loop, but it doesn't contain $term_id.  Break the loop.
    3136         foreach ( array_keys( $loop ) as $loop_member )
    3137                 wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) );
    3138 
    3139         return $parent;
    3140 }
Note: See TracChangeset for help on using the changeset viewer.