Advertisement
geminilabs

[site-reviews] set post_author of review to first assigned user

Nov 20th, 2020 (edited)
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. /**
  2.  * This will change the post_author of a review to the first assigned user.
  3.  * This hook is triggered immediately after the review is created but before the reviews details are saved.
  4.  * Note: This will also trigger a post revision.
  5.  * @param int $postId
  6.  * @param \GeminiLabs\SiteReviews\Commands\CreateReview $command
  7.  * @return void
  8.  */
  9. add_action('site-reviews/review/create', function ($postId, $command) {
  10.     $userId = glsr_get($command->assigned_users, 0); // get the first user ID from the assigned_users array
  11.     if (get_user_by('id', $userId)) { // make sure the user exists
  12.         wp_update_post([
  13.             'ID' => $postId,
  14.             'post_author' => $userId,
  15.         ]);
  16.     }
  17. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement