WordPress.org

Make WordPress Core

Changeset 19741


Ignore:
Timestamp:
01/23/2012 07:58:26 PM (6 years ago)
Author:
nacin
Message:

Clean up and better document create_initial_taxonomies(). see #19275.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r19738 r19741  
    1313
    1414/**
    15  * Creates the initial taxonomies when 'init' action is fired.
     15 * Creates the initial taxonomies.
     16 *
     17 * This function fires twice: in wp-settings.php before plugins are loaded (for
     18 * backwards compatibility reasons), and again on the 'init' action. We must avoid
     19 * registering rewrite rules before the 'init' action.
    1620 */
    1721function create_initial_taxonomies() {
    1822    global $wp_rewrite;
     23
     24    if ( ! did_action( 'init' ) ) {
     25        $rewrite = array( 'category' => false, 'post_tag' => false, 'post_format' => false );
     26    } else {
     27        $post_format_base = apply_filters( 'post_format_rewrite_base', 'type' );
     28        $rewrite = array(
     29            'category' => array(
     30                'hierarchical' => true,
     31                'slug' => get_option('category_base') ? get_option('category_base') : 'category',
     32                'with_front' => get_option('category_base') || $wp_rewrite->using_index_permalinks(),
     33                'ep_mask' => EP_CATEGORIES,
     34            ),
     35            'post_tag' => array(
     36                'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
     37                'with_front' => get_option('tag_base') || $wp_rewrite->using_index_permalinks(),
     38                'ep_mask' => EP_TAGS,
     39            ),
     40            'post_format' => $post_format_base ? array( 'slug' => $post_format_base ) : false,
     41        );
     42    }
    1943
    2044    register_taxonomy( 'category', 'post', array(
    2145        'hierarchical' => true,
    2246        'query_var' => 'category_name',
    23         'rewrite' => did_action( 'init' ) ? array(
    24                     'hierarchical' => true,
    25                     'slug' => get_option('category_base') ? get_option('category_base') : 'category',
    26                     'with_front' => ( get_option('category_base') && ! $wp_rewrite->using_index_permalinks() ) ? false : true,
    27                     'ep_mask' => EP_CATEGORIES,
    28                 ) : false,
     47        'rewrite' => $rewrite['category'],
    2948        'public' => true,
    3049        'show_ui' => true,
     
    3554        'hierarchical' => false,
    3655        'query_var' => 'tag',
    37         'rewrite' => did_action( 'init' ) ? array(
    38                     'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
    39                     'with_front' => ( get_option('tag_base') && ! $wp_rewrite->using_index_permalinks() ) ? false : true,
    40                     'ep_mask' => EP_TAGS,
    41                 ) : false,
     56        'rewrite' => $rewrite['post_tag'],
    4257        'public' => true,
    4358        'show_ui' => true,
     
    8297    ) );
    8398
    84     $rewrite = false;
    85     if ( did_action( 'init' ) ) {
    86         $rewrite = apply_filters( 'post_format_rewrite_base', 'type' );
    87         $rewrite = $rewrite ? array( 'slug' => $rewrite ) : false;
    88     }
    89 
    9099    register_taxonomy( 'post_format', 'post', array(
    91100        'public' => true,
     
    96105        ),
    97106        'query_var' => true,
    98         'rewrite' => $rewrite,
     107        'rewrite' => $rewrite['post_format'],
    99108        'show_ui' => false,
    100109        '_builtin' => true,
Note: See TracChangeset for help on using the changeset viewer.