Skip to content

Instantly share code, notes, and snippets.

@cdillon
Last active September 26, 2017 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdillon/a086d568c618d17185b7a0cdb0da3cb1 to your computer and use it in GitHub Desktop.
Save cdillon/a086d568c618d17185b7a0cdb0da3cb1 to your computer and use it in GitHub Desktop.
In Strong Testimonials, redirect bad reviews to a different page.
<?php
/**
* Strong Testimonials | Bad review redirect.
*
* IMPORTANT! If adding this to your theme's functions.php, remove line 1: <?php
*
* For help, contact chris@strongplugins.com
*
* @param $location
* @param $status
*
* @return string
*/
function my_review_redirect( $location, $status ) {
/*
* -----------------
* How to customize:
* -----------------
* Change these 3 settings that start with $my_ to match your situation.
* Make sure words are in single quotes like 'this'.
* Make sure each of those lines ends in a semicolon.
*/
// Change 'rating' to the name of your star rating field.
$my_rating_field = 'rating';
// Change 5 to the rating value that defines a good review.
// Values less than that number will redirect to a different page.
$my_good_rating = 5;
// Change 'feedback' to the slug of the page to redirect bad reviews to.
$my_bad_review_page = 'feedback';
if ( isset( $_POST['wpmtst_form_nonce'] ) && wp_verify_nonce( $_POST['wpmtst_form_nonce'], 'wpmtst_form_action' ) ) {
if ( isset( $_POST[ $my_rating_field ] ) && $_POST[ $my_rating_field ] < $my_good_rating ) {
return get_permalink( get_page_by_path( $my_bad_review_page ) );
}
}
return $location;
}
add_filter( 'wp_redirect', 'my_review_redirect', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment