Make WordPress Core

Ticket #15378: 15378.2.diff

File 15378.2.diff, 4.9 KB (added by nacin, 14 years ago)

Patch doesn't handle flushing rewrite rules on theme switch (#14849). Uses a filter for the base, instead of a UI option. Also, the array_flip and such makes for dense logic. But it does handle i18n slug situations both generating and handling links.

  • wp-includes/taxonomy.php

     
    1919                'hierarchical' => true,
    2020                'update_count_callback' => '_update_post_term_count',
    2121                'query_var' => 'category_name',
    22                 'rewrite' => array(
     22                'rewrite' => did_action( 'init' ) ? array(
    2323                                        'hierarchical' => true,
    2424                                        'slug' => get_option('category_base') ? get_option('category_base') : 'category',
    25                                         'with_front' => false),
     25                                        'with_front' => false) : false,
    2626                'public' => true,
    2727                'show_ui' => true,
    2828                '_builtin' => true,
     
    3232                'hierarchical' => false,
    3333                'update_count_callback' => '_update_post_term_count',
    3434                'query_var' => 'tag',
    35                 'rewrite' => array(
    36                                         'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag' ,
    37                                         'with_front' => false),
     35                'rewrite' => did_action( 'init' ) ? array(
     36                                        'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
     37                                        'with_front' => false) : false,
    3838                'public' => true,
    3939                'show_ui' => true,
    4040                '_builtin' => true,
     
    5252                'show_ui' => false,
    5353                '_builtin' => true,
    5454                'show_in_nav_menus' => false,
    55         ) ) ;
     55        ) );
    5656
    5757        register_taxonomy( 'link_category', 'link', array(
    5858                'hierarchical' => false,
     
    7575                'public' => false,
    7676                'show_ui' => false,
    7777                '_builtin' => true,
    78         ) ) ;
     78        ) );
    7979
     80        $rewrite = false;
     81        if ( did_action( 'init' ) && current_theme_supports( 'post-formats' ) ) {
     82                $rewrite = apply_filters( 'post_format_rewrite_base', 'type' );
     83                $rewrite = $rewrite ? array( 'slug' => $rewrite ) : false;
     84        }
     85
    8086        register_taxonomy( 'post_format', 'post', array(
    81                 'public' => false,
     87                'public' => true,
    8288                'hierarchical' => false,
    8389                'labels' => array(
    8490                        'name' => '',
    8591                        'singular_name' => '',
    8692                ),
    87                 'query_var' => false,
    88                 'rewrite' => false,
     93                'query_var' => 'post_format',
     94                'rewrite' => $rewrite,
    8995                'show_ui' => false,
    9096                '_builtin' => true,
    9197                'show_in_nav_menus' => false,
    92         ) ) ;
     98        ) );
    9399}
    94100add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
    95101
     
    310316                $wp->add_query_var($args['query_var']);
    311317        }
    312318
    313         if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') && !empty($wp_rewrite) ) {
     319        if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') ) {
    314320                $args['rewrite'] = wp_parse_args($args['rewrite'], array(
    315321                        'slug' => sanitize_title_with_dashes($taxonomy),
    316322                        'with_front' => true,
  • wp-includes/post.php

     
    50585058        return $strings;
    50595059}
    50605060
     5061function get_post_format_slugs() {
     5062        $slugs = array(
     5063                'default' => _x( 'default', 'Post format slug' ),
     5064                'aside'   => _x( 'aside',   'Post format slug' ),
     5065                'chat'    => _x( 'chat',    'Post format slug' ),
     5066                'gallery' => _x( 'gallery', 'Post format slug' ),
     5067                'link'    => _x( 'link',    'Post format slug' ),
     5068                'image'   => _x( 'image',   'Post format slug' ),
     5069                'quote'   => _x( 'quote',   'Post format slug' ),
     5070                'status'  => _x( 'status',  'Post format slug' ),
     5071                'video'   => _x( 'video',   'Post format slug' ),
     5072                'audio'   => _x( 'audio',   'Post format slug' ),
     5073        );
     5074        $slugs = array_map( 'sanitize_title_with_dashes', $slugs );
     5075        return $slugs;
     5076}
     5077
    50615078/**
    50625079 * Returns a pretty, translated version of a post format slug
    50635080 *
     
    50965113        return false;
    50975114}
    50985115
     5116/**
     5117 * Returns a link to a post format index.
     5118 *
     5119 * @since 3.1.0
     5120 *
     5121 * @param $format string Post format
     5122 * @return string Link
     5123 */
     5124function get_post_format_link( $format ) {
     5125        $term = get_term_by('slug', 'post-format-' . $format, 'post_format' );
     5126        if ( ! $term || is_wp_error( $term ) )
     5127                return false;
     5128        return get_term_link( $term );
     5129}
     5130
     5131/**
     5132 * Filters the request to allow for the format prefix.
     5133 *
     5134 * @access private
     5135 * @since 3.1.0
     5136 */
     5137function _post_format_request( $qvs ) {
     5138        if ( ! isset( $qvs['post_format'] ) )
     5139                return $qvs;
     5140        $slugs = array_flip( get_post_format_slugs() );
     5141        if ( isset( $slugs[ $qvs['post_format'] ] ) )
     5142                $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ];
     5143        return $qvs;
     5144}
     5145add_filter( 'request', '_post_format_request' );
     5146
     5147/**
     5148 * Filters the post format term link to remove the format prefix.
     5149 *
     5150 * @access private
     5151 * @since 3.1.0
     5152 */
     5153function _post_format_link( $link, $term, $taxonomy ) {
     5154        global $wp_rewrite;
     5155        if ( 'post_format' != $taxonomy )
     5156                return $link;
     5157        $slugs = get_post_format_slugs();
     5158        if ( $wp_rewrite->get_extra_permastruct( $taxonomy ) ) {
     5159                return str_replace( "/{$term->slug}", '/' . $slugs[ str_replace( 'post-format-', '', $term->slug ) ], $link );
     5160        } else {
     5161                $link = remove_query_arg( 'format', $link );
     5162                return add_query_arg( 'format', str_replace( 'post-format-', $term->slug ), $link );
     5163        }
     5164}
     5165add_filter( 'term_link', '_post_format_link', 10, 3 );
     5166
    50995167?>