Advertisement
geminilabs

[site-reviews] auto-create user categories

Nov 6th, 2019
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. /**
  2.  * Automatically create a category for each user that submits a review
  3.  * This category can then be used to target the user reviews
  4.  * i.e. [site_reviews category=u_13] - u_13 is the category slug for the author with an user ID of 13
  5.  * @param \GeminiLabs\SiteReviews\Review $review
  6.  * @return void
  7.  */
  8. add_action('site-reviews/review/created', function ($review) {
  9.     if ($user = get_userdata($review->user_id)) {
  10.         $term = 'u_'.$user->ID;
  11.         $taxonomy = glsr()->taxonomy;
  12.         if (!term_exists($term, $taxonomy)) {
  13.             wp_insert_term($user->display_name, $taxonomy, ['slug' => $term]);
  14.         }
  15.         wp_set_object_terms($review->ID, $term, $taxonomy);
  16.     }
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement