WordPress.org

Making WordPress.org

Changeset 3498


Ignore:
Timestamp:
06/20/16 11:00:11 (18 months ago)
Author:
tellyworth
Message:

Fix some issues with the pseudo-meta translated content for JP sync.

See #1691, #1692

File:
1 edited

Legend:

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

    r3476 r3498  
    498498     * @return string 
    499499     */ 
    500     public function translate_post_content( $content, $section = null ) { 
     500    public function translate_post_content( $content, $section = null, $post_id = null ) { 
    501501        if ( is_null( $section ) ) { 
    502502            return $content; 
    503503        } 
    504         return Plugin_I18n::instance()->translate( $section, $content ); 
     504        return Plugin_I18n::instance()->translate( $section, $content, [ 'post_id' => $post_id ] ); 
    505505    } 
    506506 
     
    538538     */ 
    539539    public function append_meta_for_jetpack() { 
    540         // TEMP: only do this for low numbered plugin IDs, till we're sure it works. 
    541         $post = get_post(); 
    542         if ( $post instanceof \WP_Post && $post->ID > 200 ) 
    543             return; 
    544  
    545540        // Guess if a Jetpack sync is scheduled to run. It runs during shutdown at a lower priority than this action, so we can get in first. 
    546541        // Fetching the extra meta to inject is expensive, so we only want to do this if a sync is likely. 
    547         if ( class_exists( 'Jetpack' ) && !empty(\Jetpack::init()->sync->sync) ) { 
     542        if ( class_exists( 'Jetpack' ) && !empty(\Jetpack::$instance->sync->sync) ) { 
    548543            add_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ), 10, 2 ); 
    549544        } 
     
    562557        remove_filter( 'wporg_plugins_custom_meta_fields', array( $this, 'filter_post_meta_i18n' ) ); 
    563558 
    564         if ( get_post()->ID == $post_id ) { 
    565             $locales_to_sync = array( 'fr_fr', 'es_es' ); // This should probably be a list of available translations for the plugin readme. 
     559        if ( $post_id <= 200 ) { 
     560            $locales_to_sync = array( 'fr_FR', 'es_ES' ); // This should probably be a list of available translations for the plugin readme. 
    566561 
    567562            global $locale; 
    568563            $_locale = $locale; 
    569564            foreach ( $locales_to_sync as $locale ) { 
    570                 $this->i18n_meta[$post_id]['title_'.$locale] = $this->translate_post_title( get_the_title(), $post_id ); 
    571                 $this->i18n_meta[$post_id]['excerpt_'.$locale] = $this->translate_post_excerpt( get_the_excerpt() ); 
     565                $this->i18n_meta[$post_id]['title_'.$locale] = $this->translate_post_title( get_the_title( $post_id ), $post_id ); 
     566                $this->i18n_meta[$post_id]['excerpt_'.$locale] = $this->translate_post_excerpt( get_the_excerpt( $post_id ), $post_id ); 
    572567 
    573568                // Split up the content to translate it in sections 
    574569                $content = ''; 
    575                 $sections = $this->split_post_content_into_pages( get_the_content() ); 
    576                 foreach ( $sections as $section => $section_content ) 
    577                     $content .= $this->translate_post_content( $section_content, $section ); 
     570                $sections = $this->split_post_content_into_pages( get_the_content( $post_id ) ); 
     571                foreach ( $sections as $section => $section_content ) { 
     572                    $content .= $this->translate_post_content( $section_content, $section, $post_id ); 
     573                } 
    578574                $this->i18n_meta[$post_id]['content_'.$locale] = $content; 
    579575 
     
    784780                break; 
    785781            default: 
    786                 if ( isset( $this->i18n_meta[ $object_id ][ $meta_key ] ) ) 
     782                if ( isset( $this->i18n_meta[ $object_id ][ $meta_key ] ) ) { 
    787783                    return array( $this->i18n_meta[ $object_id ][ $meta_key ] ); 
     784                } 
    788785                break; 
    789786        } 
Note: See TracChangeset for help on using the changeset viewer.