Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/e84c0ae6049359ac3124ae5e696b7757 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/e84c0ae6049359ac3124ae5e696b7757 to your computer and use it in GitHub Desktop.
M2P Show Protected Posts in Archive Custom Post Type
<?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