WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/03/2010 10:13:17 AM (11 years ago)
Author:
nacin
Message:

Post format indexes. First pass. see #15378.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r16698 r16705  
    50685068}
    50695069
     5070function get_post_format_slugs() {
     5071    $slugs = array(
     5072        'default' => _x( 'default', 'Post format slug' ),
     5073        'aside'   => _x( 'aside',   'Post format slug' ),
     5074        'chat'    => _x( 'chat',    'Post format slug' ),
     5075        'gallery' => _x( 'gallery', 'Post format slug' ),
     5076        'link'    => _x( 'link',    'Post format slug' ),
     5077        'image'   => _x( 'image',   'Post format slug' ),
     5078        'quote'   => _x( 'quote',   'Post format slug' ),
     5079        'status'  => _x( 'status',  'Post format slug' ),
     5080        'video'   => _x( 'video',   'Post format slug' ),
     5081        'audio'   => _x( 'audio',   'Post format slug' ),
     5082    );
     5083    $slugs = array_map( 'sanitize_title_with_dashes', $slugs );
     5084    return $slugs;
     5085}
     5086
    50705087/**
    50715088 * Returns a pretty, translated version of a post format slug
     
    51065123}
    51075124
     5125/**
     5126 * Returns a link to a post format index.
     5127 *
     5128 * @since 3.1.0
     5129 *
     5130 * @param $format string Post format
     5131 * @return string Link
     5132 */
     5133function get_post_format_link( $format ) {
     5134    $term = get_term_by('slug', 'post-format-' . $format, 'post_format' );
     5135    if ( ! $term || is_wp_error( $term ) )
     5136        return false;
     5137    return get_term_link( $term );
     5138}
     5139
     5140/**
     5141 * Filters the request to allow for the format prefix.
     5142 *
     5143 * @access private
     5144 * @since 3.1.0
     5145 */
     5146function _post_format_request( $qvs ) {
     5147    if ( ! isset( $qvs['post_format'] ) )
     5148        return $qvs;
     5149    $slugs = array_flip( get_post_format_slugs() );
     5150    if ( isset( $slugs[ $qvs['post_format'] ] ) )
     5151        $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ];
     5152    return $qvs;
     5153}
     5154add_filter( 'request', '_post_format_request' );
     5155
     5156/**
     5157 * Filters the post format term link to remove the format prefix.
     5158 *
     5159 * @access private
     5160 * @since 3.1.0
     5161 */
     5162function _post_format_link( $link, $term, $taxonomy ) {
     5163    global $wp_rewrite;
     5164    if ( 'post_format' != $taxonomy )
     5165        return $link;
     5166    $slugs = get_post_format_slugs();
     5167    if ( $wp_rewrite->get_extra_permastruct( $taxonomy ) ) {
     5168        return str_replace( "/{$term->slug}", '/' . $slugs[ str_replace( 'post-format-', '', $term->slug ) ], $link );
     5169    } else {
     5170        $link = remove_query_arg( 'format', $link );
     5171        return add_query_arg( 'format', str_replace( 'post-format-', $term->slug ), $link );
     5172    }
     5173}
     5174add_filter( 'term_link', '_post_format_link', 10, 3 );
     5175
    51085176?>
Note: See TracChangeset for help on using the changeset viewer.