Forked from kimcoleman/hide_post_thumbnail_on_restricted_content.php
Last active
April 7, 2021 03:33
-
-
Save travislima/63061be20f114ff8d038d542499037ed 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Do not return the post thumbnail (featured image) on restricted content when viewed by a non-member. | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
* | |
*/ | |
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
This recipe is included in the blog post on "Hide a Post’s Featured Image From Non-Members" at Paid Memberships Pro here: https://www.paidmembershipspro.com/hide-a-blog-posts-featured-image-from-non-members/