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:
parent
e69d948ca4
commit
47cfe8dd05
|
@ -12,13 +12,13 @@ require_once('./admin.php');
|
|||
$wp_list_table = get_list_table('WP_Themes_List_Table');
|
||||
$wp_list_table->check_permissions();
|
||||
|
||||
if ( current_user_can('switch_themes') && isset($_GET['action']) ) {
|
||||
if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
|
||||
if ( 'activate' == $_GET['action'] ) {
|
||||
check_admin_referer('switch-theme_' . $_GET['template']);
|
||||
switch_theme($_GET['template'], $_GET['stylesheet']);
|
||||
wp_redirect( admin_url('themes.php?activated=true') );
|
||||
exit;
|
||||
} else if ( 'delete' == $_GET['action'] ) {
|
||||
} elseif ( 'delete' == $_GET['action'] ) {
|
||||
check_admin_referer('delete-theme_' . $_GET['template']);
|
||||
if ( !current_user_can('delete_themes') )
|
||||
wp_die( __( 'Cheatin’ uh?' ) );
|
||||
|
@ -35,6 +35,10 @@ $parent_file = 'themes.php';
|
|||
|
||||
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>' . __('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') )
|
||||
|
|
|
@ -5067,6 +5067,23 @@ function get_post_format_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
|
||||
*
|
||||
|
@ -5105,4 +5122,55 @@ function set_post_thumbnail( $post, $thumbnail_id ) {
|
|||
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 );
|
||||
|
||||
?>
|
||||
|
|
|
@ -19,10 +19,10 @@ function create_initial_taxonomies() {
|
|||
'hierarchical' => true,
|
||||
'update_count_callback' => '_update_post_term_count',
|
||||
'query_var' => 'category_name',
|
||||
'rewrite' => array(
|
||||
'rewrite' => did_action( 'init' ) ? array(
|
||||
'hierarchical' => true,
|
||||
'slug' => get_option('category_base') ? get_option('category_base') : 'category',
|
||||
'with_front' => false),
|
||||
'with_front' => false) : false,
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
'_builtin' => true,
|
||||
|
@ -32,9 +32,9 @@ function create_initial_taxonomies() {
|
|||
'hierarchical' => false,
|
||||
'update_count_callback' => '_update_post_term_count',
|
||||
'query_var' => 'tag',
|
||||
'rewrite' => array(
|
||||
'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag' ,
|
||||
'with_front' => false),
|
||||
'rewrite' => did_action( 'init' ) ? array(
|
||||
'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
|
||||
'with_front' => false) : false,
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
'_builtin' => true,
|
||||
|
@ -52,7 +52,7 @@ function create_initial_taxonomies() {
|
|||
'show_ui' => false,
|
||||
'_builtin' => true,
|
||||
'show_in_nav_menus' => false,
|
||||
) ) ;
|
||||
) );
|
||||
|
||||
register_taxonomy( 'link_category', 'link', array(
|
||||
'hierarchical' => false,
|
||||
|
@ -75,21 +75,27 @@ function create_initial_taxonomies() {
|
|||
'public' => false,
|
||||
'show_ui' => false,
|
||||
'_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(
|
||||
'public' => false,
|
||||
'public' => true,
|
||||
'hierarchical' => false,
|
||||
'labels' => array(
|
||||
'name' => '',
|
||||
'singular_name' => '',
|
||||
),
|
||||
'query_var' => false,
|
||||
'rewrite' => false,
|
||||
'query_var' => 'post_format',
|
||||
'rewrite' => $rewrite,
|
||||
'show_ui' => false,
|
||||
'_builtin' => true,
|
||||
'show_in_nav_menus' => false,
|
||||
) ) ;
|
||||
) );
|
||||
}
|
||||
add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
|
||||
|
||||
|
@ -310,7 +316,7 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
|
|||
$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(
|
||||
'slug' => sanitize_title_with_dashes($taxonomy),
|
||||
'with_front' => true,
|
||||
|
|
Loading…
Reference in New Issue