Hi @frostmob
Thank you for reaching out to Paid Memberships Pro.
You could use the following CSS to blur featured image if the person doesn’t have access (however, if people are smart enough they may remove the CSS effect):
.pmpro-no-access .post-thumbnail {
filter:blur(10px);
}
Another solution would be to use the pmpro_hasMembershipLevel function to remove the thumbnail entirely or swap out the featured image for a placeholder image – https://www.paidmembershipspro.com/documentation/content-controls/require-membership-function/
This might be a better solution for those that may be able to work around the CSS styling. You may also be able to hook in on the ‘post_thumbnail_html’ possibly – https://developer.wordpress.org/reference/hooks/post_thumbnail_html/
We are looking into ways to improve upon this for sites that may want to blur/adjust the featured image based on membership level.
One more option you may explore is to filter the archives and search pages to only show items the user has access to. This may be adjusted inside the Advanced Settings area of Paid Memberships Pro under “Filter Searches and Archives” option.
Thanks Andrew for the prompt reply and guidance!
I’ve tried hooking with ‘post_thumbnail_html’ and custom image fields with little success unfortunately. The theme and plugins I used don’t seem to use ‘post_thumbnail_html’ but ‘get_post_thumbnail_id’ instead. I’m not very tech-savvy so I have no idea how to hook to this. Any pointers would be greatly appreciated.
It’s good to hear you’re already working on featured images. I look forward to the improvements to this aspect in the future and the plugin becoming a solid alternative to patreon for creatives!
After some fiddling and searching I found out I can hook to wp_get_attachment_image_src instead. There’s still problems though, the site logo gets replaced with the custom thumbnail of the first post in archives, and next/prev post thumbnails get overrode on single posts or show the original thumbnails on unprotected posts.
function custom_preview_thumb($image, $attachment_id, $size, $icon)
{
if ( function_exists( 'pmpro_has_membership_access' ) ) {
// Check if the user has access to the post.
$hasaccess = pmpro_has_membership_access();
// No access
if ( empty( $hasaccess ) ) {
// Show preview image
$preview = get_field('preview_image');
// if no preview img, return default thumbnail
if ( empty( $preview ) ) {
return $image;
}
// else, return custom PV image
else {
$image[0] = $preview;
return $image;
}
}
return $image;
}
}
add_filter('wp_get_attachment_image_src', 'custom_preview_thumb', 10, 4);
Here is our article around this solution – https://www.paidmembershipspro.com/locked-post-message-image-overlay/
This solution uses the ‘post_thumbnail_html’. I recommend reaching out to a local WordPress developer to assist you with your custom code for your needs.
Hey Andrew, I can’t access the post because I’m not a plus member, but since it uses ‘post_thumbnail_html’ I’m not sure if it’ll work for my site since they use ‘get_post_thumbnail_id’. I’ve successfully hooked it with themes that use it such as Kadence though. I’ll try fiddling with it and maybe learning about theme customization. I hope you guys find a neat solution to this problem in the future.
This sounds like your theme isn’t following the standards that most themes use and it would need to be tweaked in order to fit your requirements. A local developer should be able to assist you further with this customization request.
I tried the snippet for the article you mentioned and can confirm it doesn’t work for my theme. It works on most others such as Kadence, Generatepress and Twenty twenty-one but a few themes don’t support it.
It took a few days but I managed to find a solution to make sure ‘wp_get_attachment_image_src’ does not replace non-thumbnails. I also switched the condition to whether they have memberships, to avoid issues with plugins not supporting custom fields and leaking the image. It’s a bit of extra work, manually creating the preview image but it works for me.