Created
April 26, 2019 07:28
-
-
Save wpmudev-sls/e84c0ae6049359ac3124ae5e696b7757 to your computer and use it in GitHub Desktop.
M2P Show Protected Posts in Archive Custom Post Type
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 Custom Post Type | |
* Description: M2P Show Protected Posts in Archive Custom Post Type | |
* 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_cpt_func', 100 ); | |
function wpmudev_ms_show_protected_post_in_archive_cpt_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_cpt' ); | |
function wpmudev_remove_protection_from_archive_cpt( $obj ){ | |
// 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