• wordpress themes developer

    (@wordpress-themes-developer)


    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 source-code (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 code-base 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,

    IF ($THIS->OPTIONS[‘GOTO_SHOW_BUTTON’] == 1) {

    JUST BEFORE THIS LINE, WRITE THIS CONDITIONAL STATEMENT,

    IF (IS_USER_LOGGED_IN()) {

    THEN GO TO LINE 1087 AND AFTER THIS LINE,

    $OUT4 .= ‘<DIV CLASS=”WPCR_CLEAR WPCR_PB5″></DIV>’; ADD THIS ELSE STATEMENT AND FINALLY CLOSE THE CONDITIONAL IF STATEMENT.

    } ELSE {

    $OUT .= ‘<H2 STYLE=”COLOR: #C77405″>PLEASE LOGIN TO POST A REVIEW</H2>’;

    };

    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 theis_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 check box 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.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘MODIFYING WP CUSTOMER REVIEWS PLUGIN’ is closed to new replies.