Created
March 18, 2024 22:29
-
-
Save rafaehlers/445a9d18647ee80b155a1fb942d1daa8 to your computer and use it in GitHub Desktop.
Allow multiple reviews but only the first has ratings
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 // DO NOT COPY THIS LINE | |
add_filter( 'gv_ratings_reviews_ratings_allowed', function ( $is_allowed, $_, $__, $view ) { | |
if ( ! $is_allowed || ! $view instanceof GravityView_View ) { | |
return $is_allowed; | |
} | |
global $gv_ratings_reviews; | |
$post_bridge_comp = $gv_ratings_reviews->component_instances['post-bridge']; | |
$post_id = $post_bridge_comp->create_bridge($view->getCurrentEntry()); | |
if ($post_id instanceof WP_Error) { | |
return $is_allowed; | |
} | |
$user = wp_get_current_user(); | |
$reviewdata['comment_post_ID'] = $post_id; | |
$reviewdata['comment_author'] = $user->user_login; | |
$reviewdata['comment_author_email'] = $user->user_email; | |
$left_review = GravityView_Ratings_Reviews_Helper::is_user_has_left_review_before( $reviewdata ); | |
// If the user left a review, they are NOT allowed. | |
return ! $left_review; | |
}, 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment