From 5053c62d6400fba3145cd9f2cc4a45104f08e90e Mon Sep 17 00:00:00 2001 From: markjaquith Date: Mon, 20 Dec 2010 21:59:16 +0000 Subject: [PATCH] Translate post format term names on the fly. props mfields. fixes #15899 git-svn-id: http://svn.automattic.com/wordpress/trunk@17092 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 60 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 15f5c44181..3f04d65d9b 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -476,7 +476,7 @@ function get_post_mime_type($ID = '') { } /** - * Retrieve the format for a post + * Retrieve the format slug for a post * * @since 3.1.0 * @@ -494,7 +494,7 @@ function get_post_format( $post = null ) { $format = array_shift( $_format ); - return ( str_replace('post-format-', '', $format->name ) ); + return ( str_replace('post-format-', '', $format->slug ) ); } /** @@ -5175,4 +5175,58 @@ function _post_format_link( $link, $term, $taxonomy ) { } add_filter( 'term_link', '_post_format_link', 10, 3 ); -?> +/** + * Remove the post format prefix from the name property of the term object created by get_term(). + * + * @access private + * @since 3.1.0 + */ +function _post_format_get_term( $term ) { + if ( isset( $term->slug ) ) { + $term->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); + } + return $term; +} +add_filter( 'get_post_format', '_post_format_get_term' ); + +/** + * Remove the post format prefix from the name property of the term objects created by get_terms(). + * + * @access private + * @since 3.1.0 + */ +function _post_format_get_terms( $terms, $taxonomies, $args ) { + if ( in_array( 'post_format', (array) $taxonomies ) ) { + if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) { + foreach( $terms as $order => $name ) { + $terms[$order] = get_post_format_string( str_replace( 'post-format-', '', $name ) ); + } + } else { + foreach ( (array) $terms as $order => $term ) { + if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { + $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); + } + } + } + } + return $terms; +} +add_filter( 'get_terms', '_post_format_get_terms', 10, 3 ); + +/** + * Remove the post format prefix from the name property of the term objects created by wp_get_object_terms(). + * + * @access private + * @since 3.1.0 + */ +function _post_format_wp_get_object_terms( $terms ) { + foreach ( (array) $terms as $order => $term ) { + if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { + $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); + } + } + return $terms; +} +add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' ); + +?> \ No newline at end of file