Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict all content of a Custom Post Type (CPT) to members only. #119

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

JarrydLong
Copy link
Contributor

No description provided.

Comment on lines +64 to +74
function disable_pmpro_cpt_redirect() {
$my_cpt = 'recipe'; // Set your custom post type name here

// check if post belongs to the CPT
if ( is_singular() && get_post_type() === $my_cpt ) {
if ( has_action( 'template_redirect', 'pmprocpt_template_redirect' ) ) {
remove_action( 'template_redirect', 'pmprocpt_template_redirect' );
}
}
}
add_action( 'wp', 'disable_pmpro_cpt_redirect' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want to disable redirects when using this code recipe? Redirects are important for the CPT Add On since our standard restriction code doesn't work for CPTs that aren't filtered by the_content. If we disable redirects for these CPTs, then they will always be visible, even to non-members

Comment on lines +22 to +26
if ( current_user_can( 'manage_options' ) ) {
return true;
} else {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want to give admins access as a part of this code recipe? Or should sites use the separate "always give admins access" code recipe if they want that functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants