Making WordPress.org

Changeset 4920


Ignore:
Timestamp:
02/18/2017 05:05:55 AM (8 years ago)
Author:
SergeyBiryukov
Message:

Support Forums: Add a notice with an edit link for current user's existing reviews.

Fixes #2199.

File:
1 edited

Legend:

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

    r4919 r4920  
    4646        // Set up the single topic.
    4747        add_action( 'bbp_template_before_lead_topic', array( $this, 'add_topic_stars' ) );
     48
     49        // Add a notice with an edit link for an individual review topic.
     50        add_action( 'bbp_theme_before_topic_content', array( $this, 'add_edit_review_notice' ) );
    4851
    4952        // Set up ratings view.
     
    9598                echo \WPORG_Ratings::get_dashicons_stars( $rating );
    9699            }
     100        }
     101    }
     102
     103    /**
     104     * Add a notice with an edit link for an individual review topic.
     105     */
     106    public function add_edit_review_notice() {
     107        if ( bbp_is_single_topic() && Plugin::REVIEWS_FORUM_ID == bbp_get_topic_forum_id() ) {
     108            if ( bbp_get_topic_author_id() != get_current_user_id() ) {
     109                return;
     110            }
     111
     112            $notice = $object_link = $edit_link = '';
     113            switch( $this->compat ) {
     114                case 'plugin' :
     115                    /* translators: 1: link to the plugin, 2: review edit URL */
     116                    $notice = _x( 'This is your review of %1$s, you can <a href="%2$s">edit your review</a> at any time.', 'plugin', 'wporg-forums' );
     117                    $object_link = sprintf( '<a href="//wordpress.org/plugins/%s/">%s</a>', esc_attr( $this->slug ), esc_html( $this->object->post_title ) );
     118                    $edit_url = sprintf( '//wordpress.org/support/plugin/%s/reviews/#new-post', esc_attr( $this->slug ) );
     119                    break;
     120                case 'theme' :
     121                    /* translators: 1: link to the theme, 2: review edit URL */
     122                    $notice = _x( 'This is your review of %1$s, you can <a href="%2$s">edit your review</a> at any time.', 'theme', 'wporg-forums' );
     123                    $object_link = sprintf( '<a href="//wordpress.org/themes/%s/">%s</a>', esc_attr( $this->slug ), esc_html( $this->object->post_title ) );
     124                    $edit_url = sprintf( '//wordpress.org/support/theme/%s/reviews/#new-post', esc_attr( $this->slug ) );
     125                    break;
     126            }
     127
     128            printf(
     129                '<div class="bbp-template-notice info"><p>%s</p></div>',
     130                sprintf( $notice, $object_link, $edit_url )
     131            );
    97132        }
    98133    }
     
    258293
    259294    /**
    260      * Check if the current user already has a review for the plugin being viewed.
     295     * Check if the current user already has a review for the plugin or theme being viewed.
    261296     *
    262297     * @return bool True if review already exists, false otherwise.
Note: See TracChangeset for help on using the changeset viewer.