Post format indexes. First pass. see #15378.

git-svn-id: http://svn.automattic.com/wordpress/trunk@16705 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-12-03 10:13:17 +00:00
parent e69d948ca4
commit 47cfe8dd05
3 changed files with 92 additions and 14 deletions

View File

@ -35,6 +35,10 @@ $parent_file = 'themes.php';
if ( current_user_can( 'switch_themes' ) ) : if ( current_user_can( 'switch_themes' ) ) :
// Flush rewrite rules on activation once new theme is in place.
if ( isset( $_GET['activated'] ) && $_GET['activated'] == 'true' )
flush_rewrite_rules();
$help = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>'; $help = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>';
$help .= '<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Preview link. To change themes, click the Activate link.') . '</p>'; $help .= '<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Preview link. To change themes, click the Activate link.') . '</p>';
if ( current_user_can('install_themes') ) if ( current_user_can('install_themes') )

View File

@ -5067,6 +5067,23 @@ function get_post_format_strings() {
return $strings; return $strings;
} }
function get_post_format_slugs() {
$slugs = array(
'default' => _x( 'default', 'Post format slug' ),
'aside' => _x( 'aside', 'Post format slug' ),
'chat' => _x( 'chat', 'Post format slug' ),
'gallery' => _x( 'gallery', 'Post format slug' ),
'link' => _x( 'link', 'Post format slug' ),
'image' => _x( 'image', 'Post format slug' ),
'quote' => _x( 'quote', 'Post format slug' ),
'status' => _x( 'status', 'Post format slug' ),
'video' => _x( 'video', 'Post format slug' ),
'audio' => _x( 'audio', 'Post format slug' ),
);
$slugs = array_map( 'sanitize_title_with_dashes', $slugs );
return $slugs;
}
/** /**
* Returns a pretty, translated version of a post format slug * Returns a pretty, translated version of a post format slug
* *
@ -5105,4 +5122,55 @@ function set_post_thumbnail( $post, $thumbnail_id ) {
return false; return false;
} }
/**
* Returns a link to a post format index.
*
* @since 3.1.0
*
* @param $format string Post format
* @return string Link
*/
function get_post_format_link( $format ) {
$term = get_term_by('slug', 'post-format-' . $format, 'post_format' );
if ( ! $term || is_wp_error( $term ) )
return false;
return get_term_link( $term );
}
/**
* Filters the request to allow for the format prefix.
*
* @access private
* @since 3.1.0
*/
function _post_format_request( $qvs ) {
if ( ! isset( $qvs['post_format'] ) )
return $qvs;
$slugs = array_flip( get_post_format_slugs() );
if ( isset( $slugs[ $qvs['post_format'] ] ) )
$qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ];
return $qvs;
}
add_filter( 'request', '_post_format_request' );
/**
* Filters the post format term link to remove the format prefix.
*
* @access private
* @since 3.1.0
*/
function _post_format_link( $link, $term, $taxonomy ) {
global $wp_rewrite;
if ( 'post_format' != $taxonomy )
return $link;
$slugs = get_post_format_slugs();
if ( $wp_rewrite->get_extra_permastruct( $taxonomy ) ) {
return str_replace( "/{$term->slug}", '/' . $slugs[ str_replace( 'post-format-', '', $term->slug ) ], $link );
} else {
$link = remove_query_arg( 'format', $link );
return add_query_arg( 'format', str_replace( 'post-format-', $term->slug ), $link );
}
}
add_filter( 'term_link', '_post_format_link', 10, 3 );
?> ?>

View File

@ -19,10 +19,10 @@ function create_initial_taxonomies() {
'hierarchical' => true, 'hierarchical' => true,
'update_count_callback' => '_update_post_term_count', 'update_count_callback' => '_update_post_term_count',
'query_var' => 'category_name', 'query_var' => 'category_name',
'rewrite' => array( 'rewrite' => did_action( 'init' ) ? array(
'hierarchical' => true, 'hierarchical' => true,
'slug' => get_option('category_base') ? get_option('category_base') : 'category', 'slug' => get_option('category_base') ? get_option('category_base') : 'category',
'with_front' => false), 'with_front' => false) : false,
'public' => true, 'public' => true,
'show_ui' => true, 'show_ui' => true,
'_builtin' => true, '_builtin' => true,
@ -32,9 +32,9 @@ function create_initial_taxonomies() {
'hierarchical' => false, 'hierarchical' => false,
'update_count_callback' => '_update_post_term_count', 'update_count_callback' => '_update_post_term_count',
'query_var' => 'tag', 'query_var' => 'tag',
'rewrite' => array( 'rewrite' => did_action( 'init' ) ? array(
'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag', 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
'with_front' => false), 'with_front' => false) : false,
'public' => true, 'public' => true,
'show_ui' => true, 'show_ui' => true,
'_builtin' => true, '_builtin' => true,
@ -77,15 +77,21 @@ function create_initial_taxonomies() {
'_builtin' => true, '_builtin' => true,
) ); ) );
$rewrite = false;
if ( did_action( 'init' ) && current_theme_supports( 'post-formats' ) ) {
$rewrite = apply_filters( 'post_format_rewrite_base', 'type' );
$rewrite = $rewrite ? array( 'slug' => $rewrite ) : false;
}
register_taxonomy( 'post_format', 'post', array( register_taxonomy( 'post_format', 'post', array(
'public' => false, 'public' => true,
'hierarchical' => false, 'hierarchical' => false,
'labels' => array( 'labels' => array(
'name' => '', 'name' => '',
'singular_name' => '', 'singular_name' => '',
), ),
'query_var' => false, 'query_var' => 'post_format',
'rewrite' => false, 'rewrite' => $rewrite,
'show_ui' => false, 'show_ui' => false,
'_builtin' => true, '_builtin' => true,
'show_in_nav_menus' => false, 'show_in_nav_menus' => false,
@ -310,7 +316,7 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
$wp->add_query_var($args['query_var']); $wp->add_query_var($args['query_var']);
} }
if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') && !empty($wp_rewrite) ) { if ( false !== $args['rewrite'] && '' != get_option('permalink_structure') ) {
$args['rewrite'] = wp_parse_args($args['rewrite'], array( $args['rewrite'] = wp_parse_args($args['rewrite'], array(
'slug' => sanitize_title_with_dashes($taxonomy), 'slug' => sanitize_title_with_dashes($taxonomy),
'with_front' => true, 'with_front' => true,