Last active
April 26, 2019 07:17
-
-
Save wpmudev-sls/8b7881f0c17f9b481c74462cc05c217a to your computer and use it in GitHub Desktop.
[Membership 2] - Show Protected Post in Archive
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 | |
/** | |
* Plugin Name: M2P Show Protected Posts in Archive | |
* Description: M2P Show Protected Posts in Archive | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/profile/tho2757 | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
add_action( 'plugins_loaded', 'wpmudev_ms_show_protected_post_in_archive_func', 100 ); | |
function wpmudev_ms_show_protected_post_in_archive_func(){ | |
if( defined('MS_IS_PRO') && MS_IS_PRO && class_exists('MS_Model_Addon') ){ | |
add_action( 'ms_model_membership_protect_content_after', 'wpmudev_remove_protection_from_archive_individual_post' ); | |
function wpmudev_remove_protection_from_archive_individual_post( $obj ){ | |
// disable Individual Posts | |
if( MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_POST_BY_POST ) ) { | |
$rule = $obj->get_rule(MS_Rule_Post::RULE_ID); | |
remove_filter( 'pre_get_posts', array( $rule, 'protect_posts' ), 100 ); | |
} | |
// disable Category Posts | |
if( class_exists('MS_Rule_Category_Model') && MS_Rule_Category_Model::is_active() ) { | |
$rule = $obj->get_rule( MS_Rule_Category::RULE_ID ); | |
remove_filter( 'pre_get_posts', array( $rule, 'protect_posts' ), 98 ); | |
} | |
// disable custom post type Groups from archive | |
if( ! MS_Model_Addon::is_enabled( MS_Model_Addon::ADDON_CPT_POST_BY_POST ) ) { | |
$rule = $obj->get_rule(MS_Rule_CptGroup::RULE_ID); | |
remove_action( 'parse_query', array( $rule, 'protect_posts' ), 98 ); | |
}else{ | |
// disable individual Custom Posts from archive | |
$rule = $obj->get_rule(MS_Rule_CptItem::RULE_ID); | |
remove_action( 'parse_query', array( $rule, 'protect_posts' ), 98 ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment