Advertisement
geminilabs

[site-reviews] replace avatar with page featured image

Mar 20th, 2019 (edited)
308
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 get_the_post_thumbnail($firstAssignedPostId, 'site-reviews-avatar');
  26.     }
  27.     return $value; // You can also return a fallback <img> tag here
  28. }, 10, 2);
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement