Created
August 2, 2017 15:00
-
-
Save panoslyrakis/b7be383042207d2bda17ce9b5bf68b5b to your computer and use it in GitHub Desktop.
Hide the excerpt in the archive list
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 | |
add_filter( 'the_excerpt', '_wpmudev_ms_custom_content_protection', 20, 1 ); | |
add_filter( 'the_content', '_wpmudev_ms_custom_content_protection', 20, 1 ); | |
function _wpmudev_ms_custom_content_protection( $content ){ | |
global $post; | |
if( ! $post instanceof WP_Post || ! is_archive() ){ | |
return $content; | |
} | |
if( is_user_logged_in() ){ | |
$member = MS_Model_Member::get_current_member(); | |
//Get active subscriptions | |
$active_status = array( | |
MS_Model_Relationship::STATUS_ACTIVE, | |
MS_Model_Relationship::STATUS_TRIAL, | |
MS_Model_Relationship::STATUS_CANCELED, | |
); | |
foreach ( $member->subscriptions as $sub ) { | |
if ( $sub->is_base() ) { continue; } | |
if ( ! in_array( $sub->status, $active_status ) ) { continue; } | |
$membership = $sub->get_membership(); | |
$rule = $membership->get_rule( MS_Rule_Category::RULE_ID ); | |
if( $rule->has_access( $post->ID ) ){ | |
$user_has_access = true; | |
break; | |
} | |
} | |
} | |
else{ | |
//For logged out visitors | |
$base = MS_Model_Membership::get_base(); | |
$cat_rule = $base->get_rule( MS_Rule_Category::RULE_ID ); | |
if( $cat_rule->has_access( $post->ID ) ){ | |
$user_has_access = true; | |
} | |
} | |
if( ! $user_has_access ){ | |
$content = 'Sorry, no access buddy! The content you are trying to access is only available to members.'; | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment