<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[16705] trunk: Post format indexes.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16705">16705</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-12-03 10:13:17 +0000 (Fri, 03 Dec 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Post format indexes. First pass. see <a href="http://trac.wordpress.org/ticket/15378">#15378</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminthemesphp">trunk/wp-admin/themes.php</a></li>
<li><a href="#trunkwpincludespostphp">trunk/wp-includes/post.php</a></li>
<li><a href="#trunkwpincludestaxonomyphp">trunk/wp-includes/taxonomy.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminthemesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/themes.php (16704 => 16705)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/themes.php        2010-12-03 09:44:17 UTC (rev 16704)
+++ trunk/wp-admin/themes.php        2010-12-03 10:13:17 UTC (rev 16705)
</span><span class="lines">@@ -12,13 +12,13 @@
</span><span class="cx"> $wp_list_table = get_list_table('WP_Themes_List_Table');
</span><span class="cx"> $wp_list_table-&gt;check_permissions();
</span><span class="cx"> 
</span><del>-if ( current_user_can('switch_themes') &amp;&amp; isset($_GET['action']) ) {
</del><ins>+if ( current_user_can( 'switch_themes' ) &amp;&amp; isset($_GET['action'] ) ) {
</ins><span class="cx">         if ( 'activate' == $_GET['action'] ) {
</span><span class="cx">                 check_admin_referer('switch-theme_' . $_GET['template']);
</span><span class="cx">                 switch_theme($_GET['template'], $_GET['stylesheet']);
</span><span class="cx">                 wp_redirect( admin_url('themes.php?activated=true') );
</span><span class="cx">                 exit;
</span><del>-        } else if ( 'delete' == $_GET['action'] ) {
</del><ins>+        } elseif ( 'delete' == $_GET['action'] ) {
</ins><span class="cx">                 check_admin_referer('delete-theme_' . $_GET['template']);
</span><span class="cx">                 if ( !current_user_can('delete_themes') )
</span><span class="cx">                         wp_die( __( 'Cheatin&amp;#8217; uh?' ) );
</span><span class="lines">@@ -35,6 +35,10 @@
</span><span class="cx"> 
</span><span class="cx"> if ( current_user_can( 'switch_themes' ) ) :
</span><span class="cx"> 
</span><ins>+// Flush rewrite rules on activation once new theme is in place.
+if ( isset( $_GET['activated'] ) &amp;&amp; $_GET['activated'] == 'true' )
+        flush_rewrite_rules();
+
</ins><span class="cx"> $help = '&lt;p&gt;' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '&lt;/p&gt;';
</span><span class="cx"> $help .= '&lt;p&gt;' . __('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.') . '&lt;/p&gt;';
</span><span class="cx"> if ( current_user_can('install_themes') )
</span></span></pre></div>
<a id="trunkwpincludespostphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post.php (16704 => 16705)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post.php        2010-12-03 09:44:17 UTC (rev 16704)
+++ trunk/wp-includes/post.php        2010-12-03 10:13:17 UTC (rev 16705)
</span><span class="lines">@@ -5067,6 +5067,23 @@
</span><span class="cx">         return $strings;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function get_post_format_slugs() {
+        $slugs = array(
+                'default' =&gt; _x( 'default', 'Post format slug' ),
+                'aside'   =&gt; _x( 'aside',   'Post format slug' ),
+                'chat'    =&gt; _x( 'chat',    'Post format slug' ),
+                'gallery' =&gt; _x( 'gallery', 'Post format slug' ),
+                'link'    =&gt; _x( 'link',    'Post format slug' ),
+                'image'   =&gt; _x( 'image',   'Post format slug' ),
+                'quote'   =&gt; _x( 'quote',   'Post format slug' ),
+                'status'  =&gt; _x( 'status',  'Post format slug' ),
+                'video'   =&gt; _x( 'video',   'Post format slug' ),
+                'audio'   =&gt; _x( 'audio',   'Post format slug' ),
+        );
+        $slugs = array_map( 'sanitize_title_with_dashes', $slugs );
+        return $slugs;
+}
+
</ins><span class="cx"> /**
</span><span class="cx">  * Returns a pretty, translated version of a post format slug
</span><span class="cx">  *
</span><span class="lines">@@ -5105,4 +5122,55 @@
</span><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * 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-&gt;get_extra_permastruct( $taxonomy ) ) {
+                return str_replace( &quot;/{$term-&gt;slug}&quot;, '/' . $slugs[ str_replace( 'post-format-', '', $term-&gt;slug ) ], $link );
+        } else {
+                $link = remove_query_arg( 'format', $link );
+                return add_query_arg( 'format', str_replace( 'post-format-', $term-&gt;slug ), $link );
+        }
+}
+add_filter( 'term_link', '_post_format_link', 10, 3 );
+
</ins><span class="cx"> ?&gt;
</span></span></pre></div>
<a id="trunkwpincludestaxonomyphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/taxonomy.php (16704 => 16705)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/taxonomy.php        2010-12-03 09:44:17 UTC (rev 16704)
+++ trunk/wp-includes/taxonomy.php        2010-12-03 10:13:17 UTC (rev 16705)
</span><span class="lines">@@ -19,10 +19,10 @@
</span><span class="cx">                 'hierarchical' =&gt; true,
</span><span class="cx">                  'update_count_callback' =&gt; '_update_post_term_count',
</span><span class="cx">                 'query_var' =&gt; 'category_name',
</span><del>-                'rewrite' =&gt; array(
</del><ins>+                'rewrite' =&gt; did_action( 'init' ) ? array(
</ins><span class="cx">                                         'hierarchical' =&gt; true,
</span><span class="cx">                                         'slug' =&gt; get_option('category_base') ? get_option('category_base') : 'category',
</span><del>-                                        'with_front' =&gt; false),
</del><ins>+                                        'with_front' =&gt; false) : false,
</ins><span class="cx">                 'public' =&gt; true,
</span><span class="cx">                 'show_ui' =&gt; true,
</span><span class="cx">                 '_builtin' =&gt; true,
</span><span class="lines">@@ -32,9 +32,9 @@
</span><span class="cx">                  'hierarchical' =&gt; false,
</span><span class="cx">                 'update_count_callback' =&gt; '_update_post_term_count',
</span><span class="cx">                 'query_var' =&gt; 'tag',
</span><del>-                'rewrite' =&gt; array(
-                                        'slug' =&gt; get_option('tag_base') ? get_option('tag_base') : 'tag' ,
-                                        'with_front' =&gt; false),
</del><ins>+                'rewrite' =&gt; did_action( 'init' ) ? array(
+                                        'slug' =&gt; get_option('tag_base') ? get_option('tag_base') : 'tag',
+                                        'with_front' =&gt; false) : false,
</ins><span class="cx">                 'public' =&gt; true,
</span><span class="cx">                 'show_ui' =&gt; true,
</span><span class="cx">                 '_builtin' =&gt; true,
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">                 'show_ui' =&gt; false,
</span><span class="cx">                 '_builtin' =&gt; true,
</span><span class="cx">                 'show_in_nav_menus' =&gt; false,
</span><del>-        ) ) ;
</del><ins>+        ) );
</ins><span class="cx"> 
</span><span class="cx">         register_taxonomy( 'link_category', 'link', array(
</span><span class="cx">                 'hierarchical' =&gt; false,
</span><span class="lines">@@ -75,21 +75,27 @@
</span><span class="cx">                 'public' =&gt; false,
</span><span class="cx">                 'show_ui' =&gt; false,
</span><span class="cx">                 '_builtin' =&gt; true,
</span><del>-        ) ) ;
</del><ins>+        ) );
</ins><span class="cx"> 
</span><ins>+        $rewrite = false;
+        if ( did_action( 'init' ) &amp;&amp; current_theme_supports( 'post-formats' ) ) {
+                $rewrite = apply_filters( 'post_format_rewrite_base', 'type' );
+                $rewrite = $rewrite ? array( 'slug' =&gt; $rewrite ) : false;
+        }
+
</ins><span class="cx">         register_taxonomy( 'post_format', 'post', array(
</span><del>-                'public' =&gt; false,
</del><ins>+                'public' =&gt; true,
</ins><span class="cx">                 'hierarchical' =&gt; false,
</span><span class="cx">                 'labels' =&gt; array(
</span><span class="cx">                         'name' =&gt; '',
</span><span class="cx">                         'singular_name' =&gt; '',
</span><span class="cx">                 ),
</span><del>-                'query_var' =&gt; false,
-                'rewrite' =&gt; false,
</del><ins>+                'query_var' =&gt; 'post_format',
+                'rewrite' =&gt; $rewrite,
</ins><span class="cx">                 'show_ui' =&gt; false,
</span><span class="cx">                 '_builtin' =&gt; true,
</span><span class="cx">                 'show_in_nav_menus' =&gt; false,
</span><del>-        ) ) ;
</del><ins>+        ) );
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
</span><span class="cx"> 
</span><span class="lines">@@ -310,7 +316,7 @@
</span><span class="cx">                 $wp-&gt;add_query_var($args['query_var']);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if ( false !== $args['rewrite'] &amp;&amp; '' != get_option('permalink_structure') &amp;&amp; !empty($wp_rewrite) ) {
</del><ins>+        if ( false !== $args['rewrite'] &amp;&amp; '' != get_option('permalink_structure') ) {
</ins><span class="cx">                 $args['rewrite'] = wp_parse_args($args['rewrite'], array(
</span><span class="cx">                         'slug' =&gt; sanitize_title_with_dashes($taxonomy),
</span><span class="cx">                         'with_front' =&gt; true,
</span></span></pre>
</div>
</div>

</body>
</html>