Make WordPress Core

Ticket #15378: 15378.3.diff

File 15378.3.diff, 6.8 KB (added by nacin, 14 years ago)

Includes rudimentary UI support.

  • 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 = array( 'slug' => get_option( 'format_base' ) ? get_option( 'format_base' ) : 'type' );
     83
    8084        register_taxonomy( 'post_format', 'post', array(
    81                 'public' => false,
     85                'public' => true,
    8286                'hierarchical' => false,
    8387                'labels' => array(
    8488                        'name' => '',
    8589                        'singular_name' => '',
    8690                ),
    87                 'query_var' => false,
    88                 'rewrite' => false,
     91                'query_var' => 'post_format',
     92                'rewrite' => $rewrite,
    8993                'show_ui' => false,
    9094                '_builtin' => true,
    9195                'show_in_nav_menus' => false,
    92         ) ) ;
     96        ) );
    9397}
    9498add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
    9599
     
    310314                $wp->add_query_var($args['query_var']);
    311315        }
    312316
    313         if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') && !empty($wp_rewrite) ) {
     317        if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') ) {
    314318                $args['rewrite'] = wp_parse_args($args['rewrite'], array(
    315319                        'slug' => sanitize_title_with_dashes($taxonomy),
    316320                        '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?>
  • wp-admin/options-permalink.php

     
    9797                        $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
    9898                $wp_rewrite->set_tag_base( $tag_base );
    9999        }
     100
     101        if ( isset( $_POST['format_base'] ) ) {
     102                $format_base = $_POST['format_base'];
     103                if ( ! empty( $format_base ) )
     104                        $format_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $format_base ) );
     105                update_option( 'format_base', $format_base );
     106                $wp_rewrite->init();
     107        }
    100108}
    101109
    102110$permalink_structure = get_option('permalink_structure');
    103111$category_base = get_option('category_base');
    104112$tag_base = get_option( 'tag_base' );
     113$format_base = get_option( 'format_base' );
    105114
    106115if ( $iis7_permalinks ) {
    107116        if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
     
    160169        $permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
    161170        $category_base = preg_replace( '|^/?blog|', '', $category_base );
    162171        $tag_base = preg_replace( '|^/?blog|', '', $tag_base );
     172        $format_base = preg_replace( '|^/?blog|', '', $format_base );
    163173}
    164174
    165175$structures = array(
     
    216226                <th><label for="tag_base"><?php _e('Tag base'); ?></label></th>
    217227                <td><?php echo $blog_prefix; ?> <input name="tag_base" id="tag_base" type="text" value="<?php echo esc_attr($tag_base); ?>" class="regular-text code" /></td>
    218228        </tr>
     229<?php if ( current_theme_supports( 'post-formats' ) ) : ?>
     230        <tr>
     231                <th><label for="format_base"><?php _e('Format base'); ?></label></th>
     232                <td><?php echo $blog_prefix; ?> <input name="format_base" id="format_base" type="text" value="<?php echo esc_attr($format_base); ?>" class="regular-text code" /></td>
     233        </tr>
     234<?php endif; ?>
    219235        <?php do_settings_fields('permalink', 'optional'); ?>
    220236</table>
    221237