Making WordPress.org

Changeset 9857


Ignore:
Timestamp:
05/13/2020 03:31:34 AM (4 years ago)
Author:
dd32
Message:

Support Forums: Reviews: Include the rating in plugin/theme review feeds.

See #1611.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc
Files:
3 edited

Legend:

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

    r9041 r9857  
    7474     */
    7575    public function parse_query() {
     76        global $wp;
     77
    7678        $slug = get_query_var( 'wporg_plugin' );
    7779        if ( ! $slug ) {
    78             return;
     80            // bbPress feeds are bad and don't actually fill in globals.
     81            if ( isset( $wp->query_vars['feed'] ) && ! empty( $wp->query_vars['wporg_plugin'] ) ) {
     82                $slug = $wp->query_vars['wporg_plugin'];
     83            } else {
     84                return;
     85            }
    7986        }
    8087
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-ratings-compat.php

    r9600 r9857  
    7373        add_action( 'bbp_new_topic_post_extras', array( $this, 'topic_post_extras' ) );
    7474        add_action( 'bbp_edit_topic_post_extras', array( $this, 'topic_post_extras' ) );
     75
     76        // Add the rating to the Feed body/title
     77        if ( did_action( 'bbp_feed' ) ) {
     78            add_filter( 'bbp_get_topic_content', array( $this, 'feed_prepend_rating' ), 10, 2 );
     79            add_filter( 'bbp_get_topic_title', array( $this, 'feed_append_rating' ), 10, 2 );
     80        }
    7581    }
    7682
     
    440446        return false;
    441447    }
     448
     449    /**
     450     * Prepend the Rating to the feed content.
     451     */
     452    public function feed_prepend_rating( $content, $topic_id ) {
     453        if ( Plugin::REVIEWS_FORUM_ID == bbp_get_topic_forum_id( $topic_id ) ) {
     454            $user_id = bbp_get_topic_author_id( $topic_id );
     455            $rating = \WPORG_Ratings::get_user_rating( $this->compat, $this->slug, $user_id );
     456
     457            if ( $rating ) {
     458                $content = sprintf(
     459                    "<p>%s</p>\n%s",
     460                    sprintf(
     461                        __( 'Rating: %s', 'wporg-forums' ),
     462                        sprintf(
     463                            _n( '%s star', '%s stars', $rating, 'wporg-forums' ),
     464                            $rating
     465                        )
     466                    ),
     467                    $content
     468                );
     469            }
     470        }
     471
     472        return $content;
     473    }
     474
     475    /**
     476     * Append the Rating to the feed title.
     477     */
     478    public function feed_append_rating( $title, $topic_id ) {
     479        if ( Plugin::REVIEWS_FORUM_ID == bbp_get_topic_forum_id( $topic_id ) ) {
     480            $user_id = bbp_get_topic_author_id( $topic_id );
     481            $rating = \WPORG_Ratings::get_user_rating( $this->compat, $this->slug, $user_id );
     482
     483            if ( $rating ) {
     484                $title = sprintf(
     485                    "%s (%s)",
     486                    $title,
     487                    sprintf(
     488                        _n( '%s star', '%s stars', $rating, 'wporg-forums' ),
     489                        $rating
     490                    )
     491                );
     492            }
     493        }
     494
     495        return $title;
     496    }
    442497}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-theme-directory-compat.php

    r9041 r9857  
    7474     */
    7575    public function parse_query() {
     76        global $wp;
     77
    7678        $slug = get_query_var( 'wporg_theme' );
    7779        if ( ! $slug ) {
    78             return;
     80            // bbPress feeds are bad and don't actually fill in globals.
     81            if ( isset( $wp->query_vars['feed'] ) && ! empty( $wp->query_vars['wporg_theme'] ) ) {
     82                $slug = $wp->query_vars['wporg_theme'];
     83            } else {
     84                return;
     85            }
    7986        }
    8087
     
    8895            status_header( 404 );
    8996            return;
    90         } else {
    91             $this->slug         = $slug;
    92             $this->theme        = $theme;
    93             $this->authors      = $this->get_authors( $slug );
    94             $this->contributors = $this->get_contributors( $slug );
    95             $this->support_reps = $this->get_support_reps( $slug );
    9697        }
     98
     99        $this->slug         = $slug;
     100        $this->theme        = $theme;
     101        $this->authors      = $this->get_authors( $slug );
     102        $this->contributors = $this->get_contributors( $slug );
     103        $this->support_reps = $this->get_support_reps( $slug );
    97104    }
    98105
Note: See TracChangeset for help on using the changeset viewer.