Advertisement
geminilabs

[site-reviews] prevent users from reviewing their own posts

Mar 30th, 2024 (edited)
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. /**
  2.  * @param bool|string $isValid
  3.  * @param \GeminiLabs\SiteReviews\Request $request
  4.  * @return bool|string
  5.  */
  6. add_filter('site-reviews/validate/custom', function ($isValid, $request) {
  7.     if (!is_user_logged_in()) {
  8.         return $isValid;
  9.     }
  10.     $postIds = $request->sanitize('assigned_posts', 'array-int');
  11.     $userId = get_current_user_id();
  12.     foreach ($postIds as $postId) {
  13.         $postAuthorId = (int) (get_post($postId)->post_author ?? 0);
  14.         if ($userId === $postAuthorId) {
  15.             return 'You are not allowed to review your own post.';
  16.         }
  17.     }
  18.     return $isValid;
  19. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement