WP Manifestindependent plugin directory
manifest / social / be-comment-rating

BE Comment Rating

A lean and AMP-compatible star rating field for WordPress comments

★ 9stars

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/billerickson/be-comment-rating/archive/refs/heads/master.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

This WordPress plugin adds a star rating field for comments that's lean, uses no JavaScript, and is AMP-compatible. This 100% CSS approach was inspired by the AMP documentation.

You can also use this plugin to add AMP compatibility to an existing rating plugin that uses JavaScript. See the WP Recipe Maker section below.

screenshot

Filters

be_comment_rating_post_types
(array) Which post types the comment rating field appears on. Default value is [ 'post' ].

be_comment_rating_display
(bool) You can disable the comment rating from appearing inside each comment with apply_filters( 'be_comment_rating_display', '__return_false' );

be_comment_rating_star
(string) The star used in the comment rating (but not the comment form). Default is ★.

be_comment_rating_location
(string) Whether the star rating should appear before the comment text (default) or after.

be_comment_rating_include_css
(bool) You can prevent BE Comment Rating from enqueuing its stylesheet using apply_filters( 'be_comment_rating_include_css', '__return_false' ). If you do this, I recommend you copy the CSS to your theme because the functionality of this plugin depends upon its very unique usage of CSS.

be_comment_rating_field_display
(bool) Whether or not the comment field should appear in the comment form. Default is true.

be_comment_rating_field_label
(string) Label for the comment rating field. Default: Rating

be_comment_rating_save_data
(bool) Whether or not BE Comment Rating should save the rating data. Default is true. This is useful for integrating with other plugins.

be_comment_rating_meta_key
(string) Used to change the comment meta key, useful for integrating with other plugins. The default is be_comment_rating. Note: don't change this after you have begun collecting comment ratings, as all previous comment ratings will disappear.

WP Recipe Maker

WP Recipe Maker includes its own comment rating field, but it depends upon JavaScript so is not AMP compatible.

You can use BE Comment Rating to enable WPRM star ratings on AMP endpoints. Add the following to your theme's functions.php file:

/**
 * When to use BE Comment Rating
 * Only use it for AMP endpoints, and when the current post has a recipe
 */
function ea_use_be_comment_rating() {
    $is_amp = function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
    $has_recipe = class_exists( 'WPRM_Template_Shortcodes' ) && WPRM_Template_Shortcodes::get_current_recipe_id();
    return $is_amp && $has_recipe;
}

// WPRM AMP Compatibility

// -- Don't display rating in comment, WPRM does this
add_filter( 'be_comment_rating_display', '__return_false' );

// -- Only show comment rating field for AMP endpoints
add_filter( 'be_comment_rating_field_display', 'ea_use_be_comment_rating' );

// -- Don't save data, WPRM does this
add_filter( 'be_comment_rating_save_data', '__return_false' );

// -- Change meta key to match WPRM
add_filter( 'be_comment_rating_meta_key', function( $meta_key ) {
    return 'wprm-comment-rating';
});

// -- Disable WPRM comment rating form field
add_filter( 'wprm_template_comment_rating_form', function( $file ) {
    if( ea_use_be_comment_rating() )
        $file = WP_CONTENT_DIR . '/index.php';
    return $file;
} );