Last active
September 26, 2017 09:07
-
-
Save cdillon/a086d568c618d17185b7a0cdb0da3cb1 to your computer and use it in GitHub Desktop.
In Strong Testimonials, redirect bad reviews to a different page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Strong Testimonials | Bad review redirect. | |
* | |
* IMPORTANT! If adding this to your theme's functions.php, remove line 1: <?php | |
* | |
* For help, contact [email protected] | |
* | |
* @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