Making WordPress.org

Changeset 9016


Ignore:
Timestamp:
07/02/2019 05:49:32 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Reviews: Don't attempt to translate review titles/content, and switch to the Support Forums blog to ensure that template functions work as expected for Reviews.

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

    r8946 r9016  
    969969            return $content;
    970970        }
    971         return Plugin_I18n::instance()->translate( $section, $content, [ 'post_id' => $post_id ] );
     971
     972        $post = get_post( $post_id );
     973
     974        // Only translate Plugin post objects
     975        if ( $post && 'plugin' === $post->post_type ) {
     976            return Plugin_I18n::instance()->translate( $section, $content, [ 'post_id' => $post_id ] );
     977        }
     978
     979        return $content;
    972980    }
    973981
     
    982990        $post = get_post( $post_id );
    983991
    984         // The $post_id passed may be a Support Forum post ID, which thankfully is much higher than plugins ID's for now.
    985         if ( $post instanceof \WP_Post ) {
    986             $title = Plugin_I18n::instance()->translate( 'title', $title, [ 'post_id' => $post ] );
     992        // Only translate Post type items.
     993        if ( $post && $post->post_type === 'plugin' ) {
     994            return Plugin_I18n::instance()->translate( 'title', $title, [ 'post_id' => $post ] );
    987995        }
    988996
     
    9981006     */
    9991007    public function translate_post_excerpt( $excerpt, $post ) {
    1000         return Plugin_I18n::instance()->translate( 'excerpt', $excerpt, [ 'post_id' => $post ] );
     1008        $post = get_post( $post );
     1009
     1010        // Only translate Post type items.
     1011        if ( $post && $post->post_type === 'plugin' ) {
     1012            return Plugin_I18n::instance()->translate( 'excerpt', $excerpt, [ 'post_id' => $post ] );
     1013        }
     1014
     1015        return $excerpt;
    10011016    }
    10021017
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-reviews.php

    r8917 r9016  
    2929        <div class="plugin-reviews">
    3030            <?php
    31             foreach ( $reviews as $review ) :
     31            // Switch to the Support Forum so that Template functions that call get_post() work as intended.
     32            if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     33                switch_to_blog( WPORG_SUPPORT_FORUMS_BLOGID );
     34            }
     35
     36            foreach ( $reviews as $review ) {
     37                $GLOBALS['post'] = $review; // Override the_post();
    3238                setup_postdata( $review );
    3339                ?>
     
    4450                    </div>
    4551                </article>
    46             <?php endforeach; ?>
     52            <?php
     53            }
     54
     55            // Reset back to the plugin post.
     56            wp_reset_postdata();
     57            if ( defined( 'WPORG_SUPPORT_FORUMS_BLOGID' ) ) {
     58                restore_current_blog();
     59            }
     60        ?>
    4761        </div>
    48         <?php wp_reset_postdata(); ?>
    4962
    5063        <a class="reviews-link" href="<?php echo esc_url( 'https://wordpress.org/support/plugin/' . get_post()->post_name . '/reviews/' ); ?>">
Note: See TracChangeset for help on using the changeset viewer.