Advertisement
geminilabs

[site-reviews] replace avatar with page featured image

Mar 20th, 2019 (edited)
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. // This will only work for Site Reviews v5
  2.  
  3. /**
  4.  * Add a new WordPress image size for Site Reviews avatars
  5.  * Paste this in your active theme's functions.php file.
  6.  * This will only work for Site Reviews v5
  7.  * @return void
  8.  */
  9. add_action('after_setup_theme', function () {
  10.     $fallback = 40; // fallback width/height in pixels
  11.     $size = apply_filters('glsr_get_option', $fallback, 'reviews.avatars_size', $fallback);
  12.     add_image_size('site-reviews-avatar', $size, $size, true);
  13. });
  14.  
  15. /**
  16.  * Replaces the review avatar with the featured image thumbnail of the assigned page
  17.  * Paste this in your active theme's functions.php file.
  18.  * @param string $value
  19.  * @param \GeminiLabs\SiteReviews\Modules\Html\Tags\ReviewAvatarTag $tag
  20.  * @return string
  21.  */
  22. add_filter('site-reviews/review/value/avatar', function ($value, $tag) {
  23.     $firstAssignedPostId = array_shift($tag->review->assigned_posts);
  24.     if (empty($firstAssignedPostId)) {
  25.         return $value;
  26.     }
  27.     $thumbnail = get_the_post_thumbnail($firstAssignedPostId, 'site-reviews-avatar');
  28.     if (empty($thumbnail)) {
  29.         return $value;
  30.     }
  31.     return $thumbnail;
  32. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement