Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kimcoleman/fa679a2fb991df42d320db15cb0a68fd to your computer and use it in GitHub Desktop.
Save kimcoleman/fa679a2fb991df42d320db15cb0a68fd to your computer and use it in GitHub Desktop.
Do not return the post thumbnail (featured image) on restricted content when viewed by a non-member.
<?php
/**
* Do not return the post thumbnail (featured image) on restricted content when viewed by a non-member.
*
*/
function hide_post_thumbnail_on_restricted_content( $html, $post_id, $post_image_id ) {
if ( function_exists( 'pmpro_has_membership_access' ) ) {
// Check if the user has access to the post.
$hasaccess = pmpro_has_membership_access( $post_id );
if ( empty( $hasaccess ) ) {
$html = '';
}
}
return $html;
}
add_filter( 'post_thumbnail_html', 'hide_post_thumbnail_on_restricted_content', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment