php [Membership 2 Pro]隐藏存档列表中的摘录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [Membership 2 Pro]隐藏存档列表中的摘录相关的知识,希望对你有一定的参考价值。

<?php
//Membership 2 Pro
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;

}

以上是关于php [Membership 2 Pro]隐藏存档列表中的摘录的主要内容,如果未能解决你的问题,请参考以下文章

php [Membership 2 Pro] - 通知预览

php [Membership 2 Pro] - 向尚未支付订阅费用的会员添加付款通知

php [Membership 2 Pro] - 强制管理员对新订阅的待处理状态

php Cron的工作是将wordpress用户添加到特定的Membership 2 Pro会员/订阅中

php integracióndewoocommerce con pay membership pro #wordpress #woocommerce

php 修复Membership2与Impreza主题的冲突