Modifying WP Customer Reviews plugin

  • Home / Modifying WP Customer Reviews plugin

Modifying WP Customer Reviews plugin

Wp Customer Reviews is an excellent plugin that allows visitors to write review and rate any particular product/blog/article in any WordPress powered site. The plugin supports writing reviews on pages, posts and even custom posts. The plugin is completely free and you can get most of its features out of the box. Recently I had used this excellent plugin in one of my project but suddenly my whole excitement demise when I received a wired requirement from the client. The client wanted to allow writing reviews for registered users only while the plugin supports writing review for anyone!

When you work for a client, you must need to set your mind for the ethics that “The client is always right”. With a retired mind and broken heart I finally went to review the 1344 lines of sourcecode (that’s a piece only) of the plugin. I started hard and paid a significant amount of time to understand the code and finally all my investments pays. I was able to modify the plugin to allow review from the authenticated users only. The codebase is fairly easy to understand if you have a basic understanding of object oriented programming and some advanced WordPress’s action hook. So let’s not waste any time, modify the plugin to meet our need.

In the wp-customer-reviews.php file, go to line number 1045. You’ll find,

Just before this line, write this conditional statement,

Then go to line 1087 and after this line,

add this else statement and finally close the conditional if statement.

Explanation: Well the code itself is very much self-explanatory. If you already know what the “is_user_logged_in()” function do in WordPress then you probably understand what modification is done. The is_user_logged_in() function checks if the current visitor is logged in or not and it returns a Boolean value. I wrapped the Review button with the is_user_logged_in() function to make sure that only logged in users will able to view the button and review and the else statement simply prints a message that users must be logged in to write a review. Simple as it should be. The solution is very simple but it was difficult to find the problem. This is the core part. If you are interested to play with it and want to implement a feature in the review plugin like there will be a checkbox in the plugin settings and check marking the box will allow logged in users to post review and unchecking the box allow anyone to review. More user friendly way actually. Thank you for reading. If you find it interesting, just drop us your thoughts in the comment section. Happy coding.

Note: You can visit our main site for Outsource your WordPress Development Projects.

Leave Comments

Contact Us