WordPress.org

Making WordPress.org

Changeset 9984


Ignore:
Timestamp:
06/26/2020 05:13:22 PM (6 weeks ago)
Author:
Otto42
Message:

Support Forum: Simplify ratings saving, eliminate the case where users submit a review without a rating. Fixes #5291

File:
1 edited

Legend:

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

    r9857 r9984  
    309309     */
    310310    public function topic_post_extras( $topic_id ) {
    311         if ( isset( $_POST['rating'] ) && in_array( (int) $_POST['rating'], array( 1, 2, 3, 4, 5 ) ) ) {
    312             if (
    313                 Plugin::REVIEWS_FORUM_ID == bbp_get_topic_forum_id( $topic_id )
    314             &&
    315                 bbp_get_topic_author_id( $topic_id ) == get_current_user_id()
    316             ) {
    317                 \WPORG_Ratings::set_rating( $topic_id, $this->compat, $this->slug, bbp_get_topic_author_id( $topic_id ), absint( $_POST['rating'] ) );
    318             }
     311
     312        // if this is in the reviews forum, and the user is editing their own post
     313        if ( Plugin::REVIEWS_FORUM_ID == bbp_get_topic_forum_id( $topic_id )
     314            && bbp_get_topic_author_id( $topic_id ) == get_current_user_id() ) {
     315
     316            // if the rating is set, get it
     317            if ( isset( $_POST['rating'] ) ) {
     318                $rating = absint( $_POST[ 'rating' ] );
     319            }
     320
     321            // if the rating isn't 1-5, then set it to a default value (prevent zero star ratings and the like)
     322            if ( ! in_array( $rating, array( 1, 2, 3, 4, 5 ) ) ) {
     323                    $rating = 5; // default is 5
     324            }
     325
     326            // set the rating
     327            \WPORG_Ratings::set_rating(
     328                $topic_id,
     329                $this->compat,
     330                $this->slug,
     331                bbp_get_topic_author_id( $topic_id ),
     332                $rating
     333            );
    319334        }
    320335    }
Note: See TracChangeset for help on using the changeset viewer.