Change the Review Text with a Custom Filter

Starting with version 11.5.8 you can now use a custom filter to modify the review text. For example, let's say that I wanted to change the word "good" in the reviews to "great". I would add the following to my function.php file...

add_filter( 'wprevpro_modify_reviewtext' , 'modify_review_text', 10, 4 );
function modify_review_text($reviewtext, $review, $currentform, $length_type) {
     $reviewtextnew = str_replace ( "good" , "great" , $reviewtext );
     return $reviewtextnew;
}

Another example might be if I want to render shortcodes inside the review text. Of course you would need to add the shortcode to the review text first by modifying it. But then you could do something like this...

add_filter( 'wprevpro_modify_reviewtext' , 'modify_review_text', 10, 4 );
function modify_review_text($reviewtext, $review, $currentform, $length_type) {
     $reviewtextnew = do_shortcode($reviewtext);
     return $reviewtextnew;
}

Another example would be if you wanted to add other variables that are saved with the review. For example if I wanted to add the source page name after the review text I could do something like so...

add_filter( 'wprevpro_modify_reviewtext' , 'modify_review_text', 10, 4 );
function modify_review_text($reviewtext, $review, $currentform, $length_type) {
$title = strip_tags($review->pagename);
$reviewtextnew = $reviewtext."-".$title;
return $reviewtextnew;
}
 

Here's an example if you want to make the first sentence an HTML header.

add_filter( 'wprevpro_modify_reviewtext' , 'modify_review_text', 10, 4 );
function modify_review_text($reviewtext, $review, $currentform, $length_type) {
$resultarray = preg_split('/(?<=[.?!;:])\s+/', $reviewtext, -1, PREG_SPLIT_NO_EMPTY);
$title = "<h3>".$resultarray[0]."</h3>";
unset($resultarray[0]);
$reviewtextnew = $title." ".implode(" ", $resultarray);
return $reviewtextnew;
}

For a list of variables check the bottom of this page.

Is this article helpful for you?