Reviews version 2.0 – important changes and backwards compatibility

Reviews version 2.0 is close to being ready. It’s a major update to the way Reviews will function and we just want to go over the changes that will be coming to this release.

Database upgrades

If you have upgraded from a previous version of Reviews, you will see a notice in your WordPress Dashboard that the database needs upgrading. This upgrade goes through all the reviews stored in the database and changes the comment type and adds the metadata required for the new version to function correctly.

The changes to the database are:

  • Comment type is changed to edd_review
  • Add two new comment meta keys: edd_review_approved and edd_review_replyedd_review_approved just copies the value of the comment_approved field from the wp_comments table and edd_review_reply is only added for replies which were made to reviews. The plugin makes use of edd_review_approved for the comment status instead of the WordPress comment_approved field due to the way WordPress counts comments; it would cause the comment unread count to be incorrect.

When first updating to Reviews 2.0, the following admin notice will be displayed:

Screen Shot 2016-07-08 at 20.58.55

Following the link will begin the database upgrade and the upgrade routines described above wit

Moving away from the WordPress Comment Form

There are a huge number of improvements in 2.0 in the way reviews are handled. Up until now, we have been extending the WordPress comment_form by enabling support for comments on all downloads. In 2.0, we hook on to the the_content filter and display a custom form to submit reviews along with a custom Walker to display all the reviews.

The form displayed in Reviews 1.3.10 looks like this:

Screen Shot 2016-07-08 at 21.04.09

The new form coming to Reviews 2.0, looks like this:

Screen Shot 2016-07-08 at 21.04.26

As you can see, the standard WordPress comment form is displayed beneath the review submission form.  It should be noted that the comment form is only displayed if comments have been enabled on the Downloads post type.

There is very minimal styling applied to the form, in fact, only one CSS rule is applied which is:

.edd-reviews-form label {
display: inline-block;
width: 150px;

This rule just ensures that the labels and inputs line up.  Besides that, any global styling applied to input fields will be inherited from your theme.

In terms of the markup changes for the reviews form, this is an example of the markup for the review form:

This change not only makes the submission form more reliable, it also means that download products can now have reviews and comments enabled at the same time.

Please note: the markup has changed significantly from Reviews 1.x so themes that had specific styling for Reviews should be tested

All reviews now have a comment type of edd_review and are still stored in the wp_comments table.  They are filtered out from the WP_Comment_Query and other queries. If you currently query for reviews using get_comments, you need to remove the actions and filters which stop reviews and replies to reviews being queried. An example of querying reviews can be done as follows:

If you are doing custom querying of reviews, you must ensure to add the actions and filters after the get_comments call to ensure reviews are not tied in with comments.

Replies made to reviews have also been adjusted, they also follow the comment type of edd_review but have a meta key attached to them entitled edd_review_reply and it has a value of 1.

All reviews are displayed using a new Walker created: Walker_EDD_Review. The reviews are still displayed by making a call to wp_list_comments, the only thing different is the Walker which traverses over the reviews.

In the WordPress Dashboard, all reviews are now displayed on a new page which is located at Downloads > Reviews. No reviews will be displayed on the Comments admin page. The output of the review is controlled by the EDD_Reviews_List_Table class.

Improved API Output Data

Changes have been made to the data that is output when querying the reviews endpoint on the EDD API.

New keys that have been added:

  • parent: displays the ID of the parent review (only valid for replies)
  • type: displays the type of the review: whether it’s a review or a reply

The output has changed so that null is displayed if a review doesn’t have a title or a rating rather than just displaying a blank string. The same applies for votes: if no votes have been cast for a review, the votes key is simply set to null with no ‘yes’ and ‘no’ sub-keys.

Here is an example of the data output by the API in Reviews 2.0:

Screen Shot 2016-07-08 at 21.07.45

The first JSON element is of a reply to a review as can be distinguished by it having a value of reply for the type key. You can also see that the votes key has a value of null as replies do not have the voting feature.  The second JSON element has a type of review as well as a title key which has a value as well as having sub-keys for the votes key.

Integration with Frontend Submissions

Reviews now work alongside Frontend Submissions by allowing a much requested feature: Vendor Feedback.  All the code to integrates FES is stored under includes/class-edd-reviews-fes-integration.php.

A link is added to the Purchase History table to allow vendor feedback to be supplied. The labels can be changed using the templates and the Reviews settings under Downloads > Settings > Extensions > Reviews.

Screen Shot 2016-07-08 at 21.15.32

Upon installing Reviews, a new page is created called Vendor Feedback, this page has a shortcode which renders the feedback submission form.  The form looks like this:

Screen Shot 2016-07-08 at 21.16.45

All Vendor Feedback can be viewed from the FES Vendor Dashboard:

Screen Shot 2016-07-08 at 21.23.36

Administrators can view all Vendor Feedback by going to EDD FES > Vendor Feedback within the WordPress Admin interface.  It’s all displayed in a list table, as such:

Screen Shot 2016-07-08 at 21.14.58

Vendor Feedback is stored with an edd_vendor_feedback comment type in the comments table and, similar to reviews, is hidden from the WordPress Comments Query.  When querying vendor feedback, use a similar approach to above and just change the callback to array( edd_reviews()->fes, 'hide_feedback' ).

New Templating

Similar to Easy Digital Downloads, we have introduced a template system to allow easy modifications to certain elements of the plugins. These files are located in the templates folder of the plugin directory.

Template files bundled with the plugin are:

  • reviews-fes-vendor-feedback.php: This template is used to render all the Vendor Feedback submitted.  The output generated by this template is on the Vendor Feedback page of the FES Vendor Dashboard.
  • reviews-reply.php: This template builds the reply form which is displayed when replying to a review
  • reviews.php: This template is used for displaying the reviews and the review submission form
  • shortcode-vendor-feedback.php: This template handles the output of the [edd_vendor_feedback] shortcode and displays the form used to submit vendor feedback

All the templates bundled with the plugin can be edited by creating a file of the same name under the edd_templates folder of your active theme.  The file inside the edd_templates folder will override the file bundled in the plugin.

Updated Widgets and Shortcodes

The markup for the widgets and shortcodes has been altered to follow the same markup as a review displayed under downloads.

Featured Review Widget

The updated widget will be displayed like this:

Screen Shot 2016-07-08 at 21.12.07

Per Product Reviews Widget

The updated widget will be displayed like this:

Screen Shot 2016-07-08 at 21.13.06

Recent Reviews

The updated widget will be displayed exactly like the Per Product Review widget.

Review Shortcode

Note: previous custom styling for the review shortcode has been removed and has been replaced with a very simple CSS rule to add a border around the review with some padding and a margin.

As you can see from the above snippets, the markup is now consistent across all widgets and shortcodes but this all means that custom styling previous applied to the widgets and shortcode will break and again, as aforementioned, themes will need to be tested.

Other Notable Fixes/Changes

  • TinyMCE widget to embed reviews into posts has been rewritten and redesigned to work better with the WordPress Editor
  • HTML 5 microdata has been fixed and validated
  • Markup to display the star rating for each rating has been changed from using images to using WordPress Dashicons.
2 responses... add one

Leave a Reply

Your email address will not be published. Required fields are marked *