WordPress.org

Make WordPress Core

Changeset 15825


Ignore:
Timestamp:
10/17/2010 05:41:22 AM (8 years ago)
Author:
dd32
Message:

Merge Category/Tag URL creation/rewriting into general Taxonomy system. Removes the legacy handling for these url's. See #12659

Location:
trunk/wp-includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r15677 r15825  
    1111 *
    1212 * @since 1.0.0
    13  * @uses apply_filters() Calls 'category_link' filter on category link and category ID.
     13 * @see get_term_link()
    1414 *
    1515 * @param int $category_id Category ID.
     
    1717 */
    1818function 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');
    3920}
    4021
     
    771752 *
    772753 * @since 2.3.0
    773  * @uses apply_filters() Calls 'tag_link' with tag link and tag ID as parameters.
     754 * @see get_term_link()
    774755 *
    775756 * @param int $tag_id Tag (term) ID.
     
    777758 */
    778759function 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');
    795761}
    796762
  • trunk/wp-includes/classes.php

    r15796 r15825  
    385385            @header("{$name}: {$field_value}");
    386386
    387         if ($exit_required)
     387        if ( $exit_required )
    388388            exit();
    389389
  • trunk/wp-includes/query.php

    r15824 r15825  
    14581458                );
    14591459
     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
    14601466                $term = $q[$t->query_var];
    14611467
    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 ) {
    14671469                    $terms = preg_split( '/[+\s]+/', $term );
    14681470                    foreach ( $terms as $term ) {
  • trunk/wp-includes/rewrite.php

    r15590 r15825  
    380380     */
    381381    var $use_trailing_slashes;
    382 
    383     /**
    384      * Customized or default category permalink base ( example.com/xx/tagname ).
    385      *
    386      * @since 1.5.0
    387      * @access private
    388      * @var string
    389      */
    390     var $category_base;
    391 
    392     /**
    393      * Customized or default tag permalink base ( example.com/xx/tagname ).
    394      *
    395      * @since 2.3.0
    396      * @access private
    397      * @var string
    398      */
    399     var $tag_base;
    400 
    401     /**
    402      * Permalink request structure for categories.
    403      *
    404      * @since 1.5.0
    405      * @access private
    406      * @var string
    407      */
    408     var $category_structure;
    409 
    410     /**
    411      * Permalink request structure for tags.
    412      *
    413      * @since 2.3.0
    414      * @access private
    415      * @var string
    416      */
    417     var $tag_structure;
    418382
    419383    /**
     
    682646                    '([^/]+)',
    683647                    '([0-9]+)',
    684                     '(.+?)',
    685                     '(.+?)',
    686648                    '([^/]+)',
    687649                    '([^/]+?)',
     
    706668                    'name=',
    707669                    'p=',
    708                     'category_name=',
    709                     'tag=',
    710670                    'author_name=',
    711671                    'pagename=',
     
    1029989     */
    1030990    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');
    1047992    }
    1048993
     
    10611006     */
    10621007    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');
    10791009    }
    10801010
     
    16141544        $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
    16151545
    1616         // Categories
    1617         $category_rewrite = $this->generate_rewrite_rules($this->get_category_permastruct(), EP_CATEGORIES);
    1618         $category_rewrite = apply_filters('category_rewrite_rules', $category_rewrite);
    1619 
    1620         // Tags
    1621         $tag_rewrite = $this->generate_rewrite_rules($this->get_tag_permastruct(), EP_TAGS);
    1622         $tag_rewrite = apply_filters('tag_rewrite_rules', $tag_rewrite);
    1623 
    16241546        // Authors
    16251547        $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
     
    16311553
    16321554        // Extra permastructs
    1633         foreach ( $this->extra_permastructs as $permastruct ) {
     1555        foreach ( $this->extra_permastructs as $permastructname => $permastruct ) {
    16341556            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]);
    16361558            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);
    16381566        }
    16391567
    16401568        // Put them together.
    16411569        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);
    16431571        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);
    16451573
    16461574        do_action_ref_array('generate_rewrite_rules', array(&$this));
     
    19791907        if ( $this->using_index_permalinks() )
    19801908            $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);
    19841909        unset($this->author_structure);
    19851910        unset($this->date_structure);
     
    20331958     */
    20341959    function set_category_base($category_base) {
    2035         if ( $category_base != $this->category_base ) {
     1960        if ( $category_base != get_option('category_base') ) {
    20361961            update_option('category_base', $category_base);
    20371962            $this->init();
     
    20521977     */
    20531978    function set_tag_base( $tag_base ) {
    2054         if ( $tag_base != $this->tag_base ) {
     1979        if ( $tag_base != get_option( 'tag_base') ) {
    20551980            update_option( 'tag_base', $tag_base );
    20561981            $this->init();
  • trunk/wp-includes/taxonomy.php

    r15824 r15825  
    2020        'update_count_callback' => '_update_post_term_count',
    2121        '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),
    2326        'public' => true,
    2427        'show_ui' => true,
     
    3033        'update_count_callback' => '_update_post_term_count',
    3134        'query_var' => 'tag',
    32         'rewrite' => false,
     35        'rewrite' => array(
     36                    'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag' ,
     37                    'with_front' => false),
    3338        'public' => true,
    3439        'show_ui' => true,
     
    314319
    315320        if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] )
    316             $tag = '(.*?)';
     321            $tag = '(.+?)';
    317322        else
    318323            $tag = '([^/]+)';
     
    350355
    351356    // 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');
    353358}
    354359
     
    25822587 * @since 2.5.0
    25832588 *
     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 *
    25842593 * @param object|int|string $term
    25852594 * @param string $taxonomy (optional if $term is object)
     
    26042613
    26052614    $taxonomy = $term->taxonomy;
    2606 
    2607     // use legacy functions for core taxonomies until they are fully plugged in
    2608     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);
    26122615
    26132616    $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
     
    26382641        $termlink = home_url( user_trailingslashit($termlink, 'category') );
    26392642    }
     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
    26402649    return apply_filters('term_link', $termlink, $term, $taxonomy);
    26412650}
Note: See TracChangeset for help on using the changeset viewer.