WordPress.org

Make WordPress Core

Changeset 17092


Ignore:
Timestamp:
12/20/2010 09:59:16 PM (7 years ago)
Author:
markjaquith
Message:

Translate post format term names on the fly. props mfields. fixes #15899

File:
1 edited

Legend:

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

    r17073 r17092  
    477477
    478478/**
    479  * Retrieve the format for a post
     479 * Retrieve the format slug for a post
    480480 *
    481481 * @since 3.1.0
     
    495495    $format = array_shift( $_format );
    496496
    497     return ( str_replace('post-format-', '', $format->name ) );
     497    return ( str_replace('post-format-', '', $format->slug ) );
    498498}
    499499
     
    51765176add_filter( 'term_link', '_post_format_link', 10, 3 );
    51775177
     5178/**
     5179 * Remove the post format prefix from the name property of the term object created by get_term().
     5180 *
     5181 * @access private
     5182 * @since 3.1.0
     5183 */
     5184function _post_format_get_term( $term ) {
     5185    if ( isset( $term->slug ) ) {
     5186        $term->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
     5187    }
     5188    return $term;
     5189}
     5190add_filter( 'get_post_format', '_post_format_get_term' );
     5191
     5192/**
     5193 * Remove the post format prefix from the name property of the term objects created by get_terms().
     5194 *
     5195 * @access private
     5196 * @since 3.1.0
     5197 */
     5198function _post_format_get_terms( $terms, $taxonomies, $args ) {
     5199    if ( in_array( 'post_format', (array) $taxonomies ) ) {
     5200        if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) {
     5201            foreach( $terms as $order => $name ) {
     5202                $terms[$order] = get_post_format_string( str_replace( 'post-format-', '', $name ) );
     5203            }
     5204        } else {
     5205            foreach ( (array) $terms as $order => $term ) {
     5206                if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) {
     5207                    $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
     5208                }
     5209            }
     5210        }
     5211    }
     5212    return $terms;
     5213}
     5214add_filter( 'get_terms', '_post_format_get_terms', 10, 3 );
     5215
     5216/**
     5217 * Remove the post format prefix from the name property of the term objects created by wp_get_object_terms().
     5218 *
     5219 * @access private
     5220 * @since 3.1.0
     5221 */
     5222function _post_format_wp_get_object_terms( $terms ) {
     5223    foreach ( (array) $terms as $order => $term ) {
     5224        if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) {
     5225            $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) );
     5226        }
     5227    }
     5228    return $terms;
     5229}
     5230add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
     5231
    51785232?>
Note: See TracChangeset for help on using the changeset viewer.