Making WordPress.org

Changeset 3468


Ignore:
Timestamp:
06/19/2016 12:15:28 PM (9 years ago)
Author:
ocean90
Message:

Plugin Directory: Pass the post object to Plugin_I18n::translate().

Fixes missing translations for excerpts on the front page.

See #1691.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3465 r3468  
    235235            add_filter( 'the_content', array( $this, 'translate_post_content' ), 1, 2 );
    236236            add_filter( 'the_title', array( $this, 'translate_post_title' ), 1, 2 );
    237             add_filter( 'get_the_excerpt', array( $this, 'translate_post_excerpt' ), 1 );
     237            add_filter( 'get_the_excerpt', array( $this, 'translate_post_excerpt' ), 1, 2 );
    238238        }
    239239
     
    508508     * @return string
    509509     */
    510     public function translate_post_title( $title, $post_id ) {
     510    public function translate_post_title( $title, $post_id = null ) {
    511511        $post = get_post();
    512512
    513513        if ( $post instanceof \WP_Post && $post_id === $post->ID ) {
    514             $title = Plugin_I18n::instance()->translate( 'title', $title );
     514            $title = Plugin_I18n::instance()->translate( 'title', $title, [ 'post_id' => $post ] );
    515515        }
    516516
     
    522522     *
    523523     * @param string $excerpt
     524     * @param \WP_Post $post
    524525     * @return string
    525526     */
    526     public function translate_post_excerpt( $excerpt ) {
    527         return Plugin_I18n::instance()->translate( 'excerpt', $excerpt );
     527    public function translate_post_excerpt( $excerpt, $post ) {
     528        return Plugin_I18n::instance()->translate( 'excerpt', $excerpt, [ 'post_id' => $post ] );
    528529    }
    529530
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r3391 r3468  
    268268        }
    269269
    270         if ( !empty( $args['post_id'] ) && is_numeric( $args['post_id'] ) ) {
    271             $topic = get_post( $args['post_id'] );
    272         } else {
    273             global $post;
    274         }
    275 
    276         if ( empty( $post ) ) {
    277             return $content;
    278         }
    279 
    280         if ( !empty( $args['locale'] ) ) {
     270        $args = wp_parse_args( $args, [
     271            'post_id' => null,
     272            'locale'  => '',
     273        ] );
     274
     275        $post = get_post( $args['post_id'] );
     276
     277        if ( ! $post ) {
     278            return $content;
     279        }
     280
     281        if ( ! empty( $args['locale'] ) ) {
    281282            $wp_locale = $args['locale'];
    282283        } else {
Note: See TracChangeset for help on using the changeset viewer.