Changes from trunk/wp-includes/taxonomy.php at r17443 to branches/3.0/wp-includes/taxonomy.php at r15426
- File:
-
- 1 edited
-
branches/3.0/wp-includes/taxonomy.php (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/wp-includes/taxonomy.php
r17443 r15426 19 19 'hierarchical' => true, 20 20 '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, 26 33 'public' => true, 27 34 'show_ui' => true, … … 29 36 ) ); 30 37 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 43 38 register_taxonomy( 'nav_menu', 'nav_menu_item', array( 44 'public' => false,45 39 'hierarchical' => false, 46 40 'labels' => array( … … 53 47 '_builtin' => true, 54 48 'show_in_nav_menus' => false, 55 ) ) ;49 ) ) ; 56 50 57 51 register_taxonomy( 'link_category', 'link', array( 58 52 'hierarchical' => false, 59 53 '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' ), 72 57 ), 73 58 'query_var' => false, … … 76 61 'show_ui' => false, 77 62 '_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 ) ) ; 99 64 } 100 65 add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority … … 321 286 'slug' => sanitize_title_with_dashes($taxonomy), 322 287 'with_front' => true, 323 'hierarchical' => false324 288 )); 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']); 333 291 } 334 292 … … 361 319 362 320 // 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'); 364 322 } 365 323 … … 410 368 'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ), 411 369 ); 412 $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];413 370 414 371 return _get_custom_object_labels( $tax, $nohier_vs_hier_defaults ); … … 504 461 505 462 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.0512 *513 * @see WP_Tax_Query514 *515 * @param array $tax_query A compact tax query516 * @param string $primary_table517 * @param string $primary_id_column518 * @return array519 */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.0529 */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 queried535 * - 'terms' string|array The list of terms536 * - '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: true544 *545 * @since 3.1.0546 * @access public547 * @var array548 */549 var $queries = array();550 551 /**552 * The relation between the queries. Can be one of 'AND' or 'OR'.553 *554 * @since 3.1.0555 * @access public556 * @var string557 */558 var $relation;559 560 /**561 * PHP4 type constructor.562 *563 * Parses a compact tax query and sets defaults.564 *565 * @since 3.1.0566 * @access public567 *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_Query584 */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.0616 * @access public617 *618 * @param string $primary_table619 * @param string $primary_id_column620 * @return array621 */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 else662 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_id683 FROM $wpdb->term_relationships684 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_id697 FROM $wpdb->term_relationships698 WHERE term_taxonomy_id IN ($terms)699 GROUP BY object_id HAVING COUNT(object_id) = $num_terms700 )";701 }702 703 $i++;704 }705 706 if ( !empty( $where ) )707 $where = ' AND ( ' . implode( " $this->relation ", $where ) . ' )';708 else709 $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.0718 * @access private719 *720 * @param array &$terms The list of terms721 * @param string $taxonomy The taxonomy of the terms722 * @param string $field The initial field723 * @param string $resulting_field The resulting field724 */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_field742 FROM $wpdb->term_taxonomy743 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_field753 FROM $wpdb->term_taxonomy754 WHERE taxonomy = '$taxonomy'755 AND term_id IN ($terms)756 " );757 }758 }759 463 } 760 464 … … 928 632 * @uses get_term_children() Used to get the children of both $taxonomy and the parent $term 929 633 * 930 * @param string $term _idID of Term to get children634 * @param string $term ID of Term to get children 931 635 * @param string $taxonomy Taxonomy Name 932 636 * @return array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist … … 1103 807 * @uses wp_parse_args() Merges the defaults with those defined by $args and allows for strings. 1104 808 * 1105 * @param string|array $taxonomiesTaxonomy name or list of Taxonomy names809 * @param string|array Taxonomy name or list of Taxonomy names 1106 810 * @param string|array $args The values of what to search for when returning terms 1107 811 * @return array|WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies do not exist. … … 1117 821 } 1118 822 1119 foreach ( $taxonomies as $taxonomy ) {823 foreach ( (array) $taxonomies as $taxonomy ) { 1120 824 if ( ! taxonomy_exists($taxonomy) ) { 1121 825 $error = & new WP_Error('invalid_taxonomy', __('Invalid Taxonomy')); … … 1123 827 } 1124 828 } 829 830 $in_taxonomies = "'" . implode("', '", $taxonomies) . "'"; 1125 831 1126 832 $defaults = array('orderby' => 'name', 'order' => 'ASC', … … 1145 851 $args['pad_counts'] = false; 1146 852 } 1147 1148 $args = apply_filters( 'get_terms_args', $args, $taxonomies );1149 1150 853 extract($args, EXTR_SKIP); 1151 854 … … 1198 901 $order = ''; 1199 902 1200 $where = "tt.taxonomy IN ('" . implode("', '", $taxonomies) . "')";903 $where = ''; 1201 904 $inclusions = ''; 1202 905 if ( !empty($include) ) { … … 1220 923 $excluded_trunks = wp_parse_id_list($exclude_tree); 1221 924 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')); 1223 926 $excluded_children[] = $extrunk; 1224 927 foreach( $excluded_children as $exterm ) { … … 1252 955 1253 956 if ( !empty($name__like) ) 1254 $where .= " AND t.name LIKE ' " . like_escape( $name__like ) . "%'";957 $where .= " AND t.name LIKE '{$name__like}%'"; 1255 958 1256 959 if ( '' !== $parent ) { … … 1265 968 if ( ! empty($number) && ! $hierarchical && empty( $child_of ) && '' === $parent ) { 1266 969 if ( $offset ) 1267 $limit s= 'LIMIT ' . $offset . ',' . $number;970 $limit = 'LIMIT ' . $offset . ',' . $number; 1268 971 else 1269 $limit s= 'LIMIT ' . $number;972 $limit = 'LIMIT ' . $number; 1270 973 } else { 1271 $limit s= '';974 $limit = ''; 1272 975 } 1273 976 … … 1279 982 $selects = array(); 1280 983 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': 1285 988 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': 1292 995 $orderby = ''; 1293 996 $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"; 1311 1002 1312 1003 if ( 'count' == $fields ) { … … 1321 1012 1322 1013 if ( empty($terms) ) { 1323 wp_cache_add( $cache_key, array(), 'terms' , 86400 ); // one day1014 wp_cache_add( $cache_key, array(), 'terms' ); 1324 1015 $terms = apply_filters('get_terms', array(), $taxonomies, $args); 1325 1016 return $terms; … … 1372 1063 } 1373 1064 1374 wp_cache_add( $cache_key, $terms, 'terms' , 86400 ); // one day1065 wp_cache_add( $cache_key, $terms, 'terms' ); 1375 1066 1376 1067 $terms = apply_filters('get_terms', $terms, $taxonomies, $args); … … 1533 1224 1534 1225 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); 1537 1228 if ( 'description' == $field ) 1538 $value = esc_html($value); // textarea_escaped1229 $value = format_to_edit($value); 1539 1230 else 1540 1231 $value = esc_attr($value); 1541 1232 } 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); 1544 1235 // Back compat filters 1545 1236 if ( 'slug' == $field ) … … 1547 1238 1548 1239 } 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); 1551 1242 } else { 1552 1243 // 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); 1555 1246 } 1556 1247 … … 1595 1286 1596 1287 /** 1597 * Will unlink the object from the taxonomy or taxonomies.1598 * 1599 * Will remove all relationships between the object and any terms in1600 * a particular taxonomy or taxonomies. Does not remove the term or1601 * 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. 1602 1293 * 1603 1294 * @package WordPress … … 1607 1298 * 1608 1299 * @param int $object_id The term Object Id that refers to the term 1609 * @param string|array $taxonom iesList of Taxonomy Names or single Taxonomy name.1300 * @param string|array $taxonomy List of Taxonomy Names or single Taxonomy name. 1610 1301 */ 1611 1302 function wp_delete_object_term_relationships( $object_id, $taxonomies ) { … … 1665 1356 1666 1357 $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 category1672 }1673 1674 1358 $args = wp_parse_args($args, $defaults); 1675 1359 extract($args, EXTR_SKIP); 1676 1360 1677 if ( isset( $default) ) {1361 if ( isset($default) ) { 1678 1362 $default = (int) $default; 1679 1363 if ( ! term_exists($default, $taxonomy) ) … … 1709 1393 } 1710 1394 1711 // Clean the relationship caches for all object types using this term1712 $tax_object = get_taxonomy( $taxonomy );1713 foreach ( $tax_object->object_type as $object_type )1714 clean_object_term_cache( $objects, $object_type );1715 1716 1395 do_action( 'delete_term_taxonomy', $tt_id ); 1717 1396 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $tt_id ) ); … … 1728 1407 1729 1408 return true; 1730 }1731 1732 /**1733 * Deletes one existing category.1734 *1735 * @since 2.0.01736 * @uses wp_delete_term()1737 *1738 * @param int $cat_ID1739 * @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' );1744 1409 } 1745 1410 … … 1771 1436 * @uses $wpdb 1772 1437 * 1773 * @param int|array $object_id s The ID(s)of the object(s) to retrieve.1438 * @param int|array $object_id The id of the object(s) to retrieve. 1774 1439 * @param string|array $taxonomies The taxonomies to retrieve terms from. 1775 1440 * @param array|string $args Change what is returned … … 2041 1706 * 2042 1707 * @param int $object_id The object to relate to. 2043 * @param array|int|string $term sThe slug or id of the term, will replace all existing1708 * @param array|int|string $term The slug or id of the term, will replace all existing 2044 1709 * related terms in this taxonomy. 2045 1710 * @param array|string $taxonomy The context in which to relate the term to the object. … … 2272 1937 } 2273 1938 2274 // Check $parent to see if it will cause a hierarchy loop2275 $parent = apply_filters( 'wp_update_term_parent', $parent, $term_id, $taxonomy, compact( array_keys( $args ) ), $args );2276 2277 1939 // Check for duplicate slug 2278 1940 $id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms WHERE slug = %s", $slug ) ); … … 2810 2472 * @since 2.5.0 2811 2473 * 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 *2816 2474 * @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 */ 2478 function get_term_link( $term, $taxonomy ) { 2821 2479 global $wp_rewrite; 2822 2480 … … 2835 2493 return $term; 2836 2494 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); 2838 2500 2839 2501 $termlink = $wp_rewrite->get_extra_permastruct($taxonomy); 2840 2502 2841 2503 $slug = $term->slug; 2842 $t = get_taxonomy($taxonomy);2843 2504 2844 2505 if ( empty($termlink) ) { 2506 $t = get_taxonomy($taxonomy); 2845 2507 if ( $t->query_var ) 2846 2508 $termlink = "?$t->query_var=$slug"; … … 2849 2511 $termlink = home_url($termlink); 2850 2512 } 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); 2864 2514 $termlink = home_url( user_trailingslashit($termlink, 'category') ); 2865 2515 } 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 2872 2516 return apply_filters('term_link', $termlink, $term, $taxonomy); 2873 2517 } … … 2885 2529 * 'sep' : default is empty string. Separate every taxonomy with value in this. 2886 2530 * 'after' : default is empty string. Display this after the taxonomies list. 2887 * 'template' : The template to use for displaying the taxonomy terms.2888 2531 * 2889 2532 * @since 2.5.0 … … 2898 2541 'sep' => ' ', 2899 2542 'after' => '', 2900 'template' => '%s: %l.'2901 2543 ); 2902 2544 … … 2904 2546 extract( $r, EXTR_SKIP ); 2905 2547 2906 echo $before . join($sep, get_the_taxonomies($post , $r)) . $after;2548 echo $before . join($sep, get_the_taxonomies($post)) . $after; 2907 2549 } 2908 2550 … … 2916 2558 * 2917 2559 * @param int $post Optional. Post ID or will use Global Post ID (in loop). 2918 * @param array $args Override the defaults.2919 2560 * @return array 2920 2561 */ 2921 function get_the_taxonomies($post = 0 , $args = array()) {2562 function get_the_taxonomies($post = 0) { 2922 2563 if ( is_int($post) ) 2923 2564 $post =& get_post($post); … … 2925 2566 $post =& $GLOBALS['post']; 2926 2567 2927 $args = wp_parse_args( $args, array(2928 'template' => '%s: %l.',2929 ) );2930 extract( $args, EXTR_SKIP );2931 2932 2568 $taxonomies = array(); 2933 2569 2934 2570 if ( !$post ) 2935 2571 return $taxonomies; 2572 2573 $template = apply_filters('taxonomy_template', '%s: %l.'); 2936 2574 2937 2575 foreach ( get_object_taxonomies($post) as $taxonomy ) { … … 2951 2589 2952 2590 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>"; 2954 2592 2955 2593 if ( $links ) … … 2985 2623 * @uses wp_get_object_terms() 2986 2624 * 2987 * @param int $object_id ID of the object (post ID, link ID, ...)2988 * @param string $taxonomy Single taxonomy name2625 * @param int $object_id. ID of the object (post ID, link ID, ...) 2626 * @param string $taxonomy. Single taxonomy name 2989 2627 * @param int|string|array $terms Optional. Term term_id, name, slug or array of said 2990 2628 * @return bool|WP_Error. WP_Error on input error. … … 3031 2669 * 3032 2670 * @param string $object_type Object type string 3033 * @param string $taxonomy Single taxonomy name2671 * @param string $taxonomy. Single taxonomy name 3034 2672 * @return bool True if object is associated with the taxonomy, otherwise false. 3035 2673 */ … … 3045 2683 return false; 3046 2684 } 3047 3048 /**3049 * Get an array of ancestor IDs for a given object.3050 *3051 * @param int $object_id The ID of the object3052 * @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_ID3087 *3088 * @since 3.1.03089 *3090 * @param int $term_id3091 * @param string $taxonomy3092 *3093 * @return int|bool false on error3094 */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.03109 * @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 - bail3119 if ( !$parent )3120 return 0;3121 3122 // Can't be its own parent3123 if ( $parent == $term_id )3124 return 0;3125 3126 // Now look for larger loops3127 3128 if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) )3129 return $parent; // No loop3130 3131 // Setting $parent to the given value causes a loop3132 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.