Changeset 15825
- Timestamp:
- 10/17/2010 05:41:22 AM (14 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/category-template.php
r15677 r15825 11 11 * 12 12 * @since 1.0.0 13 * @ uses apply_filters() Calls 'category_link' filter on category link and category ID.13 * @see get_term_link() 14 14 * 15 15 * @param int $category_id Category ID. … … 17 17 */ 18 18 function get_category_link( $category_id ) { 19 global $wp_rewrite; 20 $catlink = $wp_rewrite->get_category_permastruct(); 21 22 if ( empty( $catlink ) ) { 23 $catlink = home_url('?cat=' . $category_id); 24 } else { 25 $category = &get_category( $category_id ); 26 if ( is_wp_error( $category ) ) 27 return $category; 28 $category_nicename = $category->slug; 29 30 if ( $category->parent == $category_id ) // recursive recursion 31 $category->parent = 0; 32 elseif ($category->parent != 0 ) 33 $category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename; 34 35 $catlink = str_replace( '%category%', $category_nicename, $catlink ); 36 $catlink = home_url( user_trailingslashit( $catlink, 'category' ) ); 37 } 38 return apply_filters( 'category_link', $catlink, $category_id ); 19 return get_term_link((int)$category_id, 'category'); 39 20 } 40 21 … … 771 752 * 772 753 * @since 2.3.0 773 * @ uses apply_filters() Calls 'tag_link' with tag link and tag ID as parameters.754 * @see get_term_link() 774 755 * 775 756 * @param int $tag_id Tag (term) ID. … … 777 758 */ 778 759 function get_tag_link( $tag_id ) { 779 global $wp_rewrite; 780 $taglink = $wp_rewrite->get_tag_permastruct(); 781 782 $tag = &get_term( $tag_id, 'post_tag' ); 783 if ( is_wp_error( $tag ) ) 784 return $tag; 785 $slug = $tag->slug; 786 787 if ( empty( $taglink ) ) { 788 $file = get_option( 'home' ) . '/'; 789 $taglink = $file . '?tag=' . $slug; 790 } else { 791 $taglink = str_replace( '%tag%', $slug, $taglink ); 792 $taglink = get_option( 'home' ) . user_trailingslashit( $taglink, 'category' ); 793 } 794 return apply_filters( 'tag_link', $taglink, $tag_id ); 760 return get_term_link( (int)$tag_id, 'post_tag'); 795 761 } 796 762 -
trunk/wp-includes/classes.php
r15796 r15825 385 385 @header("{$name}: {$field_value}"); 386 386 387 if ( $exit_required)387 if ( $exit_required ) 388 388 exit(); 389 389 -
trunk/wp-includes/query.php
r15824 r15825 1458 1458 ); 1459 1459 1460 if ( $t->rewrite['hierarchical'] ) { 1461 $q[$t->query_var] = basename($q[$t->query_var]); 1462 if ( $taxonomy == $q['taxonomy'] ) 1463 $q['term'] = basename($q['term']); 1464 } 1465 1460 1466 $term = $q[$t->query_var]; 1461 1467 1462 if ( $t->rewrite['hierarchical'] ) { 1463 $tax_query[] = array_merge( $tax_query_defaults, array( 1464 'terms' => array( basename( $term ) ) 1465 ) ); 1466 } elseif ( strpos($term, '+') !== false ) { 1468 if ( strpos($term, '+') !== false ) { 1467 1469 $terms = preg_split( '/[+\s]+/', $term ); 1468 1470 foreach ( $terms as $term ) { -
trunk/wp-includes/rewrite.php
r15590 r15825 380 380 */ 381 381 var $use_trailing_slashes; 382 383 /**384 * Customized or default category permalink base ( example.com/xx/tagname ).385 *386 * @since 1.5.0387 * @access private388 * @var string389 */390 var $category_base;391 392 /**393 * Customized or default tag permalink base ( example.com/xx/tagname ).394 *395 * @since 2.3.0396 * @access private397 * @var string398 */399 var $tag_base;400 401 /**402 * Permalink request structure for categories.403 *404 * @since 1.5.0405 * @access private406 * @var string407 */408 var $category_structure;409 410 /**411 * Permalink request structure for tags.412 *413 * @since 2.3.0414 * @access private415 * @var string416 */417 var $tag_structure;418 382 419 383 /** … … 682 646 '([^/]+)', 683 647 '([0-9]+)', 684 '(.+?)',685 '(.+?)',686 648 '([^/]+)', 687 649 '([^/]+?)', … … 706 668 'name=', 707 669 'p=', 708 'category_name=',709 'tag=',710 670 'author_name=', 711 671 'pagename=', … … 1029 989 */ 1030 990 function get_category_permastruct() { 1031 if ( isset($this->category_structure) ) 1032 return $this->category_structure; 1033 1034 if ( empty($this->permalink_structure) ) { 1035 $this->category_structure = ''; 1036 return false; 1037 } 1038 1039 if ( empty($this->category_base) ) 1040 $this->category_structure = trailingslashit( $this->front . 'category' ); 1041 else 1042 $this->category_structure = trailingslashit( '/' . $this->root . $this->category_base ); 1043 1044 $this->category_structure .= '%category%'; 1045 1046 return $this->category_structure; 991 return $this->get_extra_permastruct('category'); 1047 992 } 1048 993 … … 1061 1006 */ 1062 1007 function get_tag_permastruct() { 1063 if ( isset($this->tag_structure) ) 1064 return $this->tag_structure; 1065 1066 if ( empty($this->permalink_structure) ) { 1067 $this->tag_structure = ''; 1068 return false; 1069 } 1070 1071 if ( empty($this->tag_base) ) 1072 $this->tag_structure = trailingslashit( $this->front . 'tag' ); 1073 else 1074 $this->tag_structure = trailingslashit( '/' . $this->root . $this->tag_base ); 1075 1076 $this->tag_structure .= '%tag%'; 1077 1078 return $this->tag_structure; 1008 return $this->get_extra_permastruct('post_tag'); 1079 1009 } 1080 1010 … … 1614 1544 $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite); 1615 1545 1616 // Categories1617 $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);1618 $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);1619 1620 // Tags1621 $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);1622 $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite);1623 1624 1546 // Authors 1625 1547 $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS); … … 1631 1553 1632 1554 // Extra permastructs 1633 foreach ( $this->extra_permastructs as $permastruct ) {1555 foreach ( $this->extra_permastructs as $permastructname => $permastruct ) { 1634 1556 if ( is_array($permastruct) ) 1635 $ this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct[0], $permastruct[1]));1557 $rules = $this->generate_rewrite_rules($permastruct[0], $permastruct[1]); 1636 1558 else 1637 $this->extra_rules_top = array_merge($this->extra_rules_top, $this->generate_rewrite_rules($permastruct, EP_NONE)); 1559 $rules = $this->generate_rewrite_rules($permastruct, EP_NONE); 1560 1561 $rules = apply_filters($permastructname . '_rewrite_rules', $rules); 1562 if ( 'post_tag' == $permastructname ) 1563 $rules = apply_filters('tag_rewrite_rules', $rules); 1564 1565 $this->extra_rules_top = array_merge($this->extra_rules_top, $rules); 1638 1566 } 1639 1567 1640 1568 // Put them together. 1641 1569 if ( $this->use_verbose_page_rules ) 1642 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $registration_pages, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite,$author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules);1570 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $registration_pages, $page_rewrite, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $this->extra_rules); 1643 1571 else 1644 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $category_rewrite, $tag_rewrite,$author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);1572 $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $default_feeds, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules); 1645 1573 1646 1574 do_action_ref_array('generate_rewrite_rules', array(&$this)); … … 1979 1907 if ( $this->using_index_permalinks() ) 1980 1908 $this->root = $this->index . '/'; 1981 $this->category_base = get_option( 'category_base' );1982 $this->tag_base = get_option( 'tag_base' );1983 unset($this->category_structure);1984 1909 unset($this->author_structure); 1985 1910 unset($this->date_structure); … … 2033 1958 */ 2034 1959 function set_category_base($category_base) { 2035 if ( $category_base != $this->category_base) {1960 if ( $category_base != get_option('category_base') ) { 2036 1961 update_option('category_base', $category_base); 2037 1962 $this->init(); … … 2052 1977 */ 2053 1978 function set_tag_base( $tag_base ) { 2054 if ( $tag_base != $this->tag_base) {1979 if ( $tag_base != get_option( 'tag_base') ) { 2055 1980 update_option( 'tag_base', $tag_base ); 2056 1981 $this->init(); -
trunk/wp-includes/taxonomy.php
r15824 r15825 20 20 'update_count_callback' => '_update_post_term_count', 21 21 'query_var' => 'category_name', 22 'rewrite' => false, 22 'rewrite' => array( 23 'hierarchical' => true, 24 'slug' => get_option('category_base') ? get_option('category_base') : 'category', 25 'with_front' => false), 23 26 'public' => true, 24 27 'show_ui' => true, … … 30 33 'update_count_callback' => '_update_post_term_count', 31 34 'query_var' => 'tag', 32 'rewrite' => false, 35 'rewrite' => array( 36 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag' , 37 'with_front' => false), 33 38 'public' => true, 34 39 'show_ui' => true, … … 314 319 315 320 if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] ) 316 $tag = '(. *?)';321 $tag = '(.+?)'; 317 322 else 318 323 $tag = '([^/]+)'; … … 350 355 351 356 // register callback handling for metabox 352 add_filter('wp_ajax_add-' .$taxonomy, '_wp_ajax_add_hierarchical_term');357 add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term'); 353 358 } 354 359 … … 2582 2587 * @since 2.5.0 2583 2588 * 2589 * @uses apply_filters() Calls 'term_link' with term link and term object, and taxonomy parameters. 2590 * @uses apply_filters() For the post_tag Taxonomy, Calls 'tag_link' with tag link and tag ID as parameters. 2591 * @uses apply_filters() For the category Taxonomy, Calls 'category_link' filter on category link and category ID. 2592 * 2584 2593 * @param object|int|string $term 2585 2594 * @param string $taxonomy (optional if $term is object) … … 2604 2613 2605 2614 $taxonomy = $term->taxonomy; 2606 2607 // use legacy functions for core taxonomies until they are fully plugged in2608 if ( $taxonomy == 'category' )2609 return get_category_link((int) $term->term_id);2610 if ( $taxonomy == 'post_tag' )2611 return get_tag_link((int) $term->term_id);2612 2615 2613 2616 $termlink = $wp_rewrite->get_extra_permastruct($taxonomy); … … 2638 2641 $termlink = home_url( user_trailingslashit($termlink, 'category') ); 2639 2642 } 2643 // Back Compat filters. 2644 if ( 'post_tag' == $taxonomy ) 2645 $termlink = apply_filters( 'tag_link', $termlink, $term->term_id ); 2646 elseif ( 'category' == $taxonomy ) 2647 $termlink = apply_filters( 'category_link', $termlink, $term->term_id ); 2648 2640 2649 return apply_filters('term_link', $termlink, $term, $taxonomy); 2641 2650 }
Note: See TracChangeset
for help on using the changeset viewer.