Advertisement
geminilabs

[site-reviews] Prevent author of assigned page from submitting a review

Aug 13th, 2022 (edited)
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. /**
  2.  * Prevent authors from submitting reviews for their own post
  3.  * @param bool $isValid
  4.  * @param \GeminiLabs\SiteReviews\Request $request
  5.  * @return bool|string
  6.  */
  7. add_filter('site-reviews/validate/custom', function ($isValid, $request) {
  8.     $postIds = explode(',', $request->assigned_posts);
  9.     foreach ($postIds as $postId) {
  10.         $post = get_post($postId);
  11.         if ($post && intval($post->post_author) === get_current_user_id()) {
  12.             return __('You cannot review your own product.');
  13.         }
  14.     }
  15.     return $isValid;
  16. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement