How to restrict access to all custom posts in a specific category

Hi,

I am using events+ along with Membership 2 pro.

I want to find a way to restrict access to certain events easily via the Add new/Edit event screens.

1. It would be great if there was a protected content widget on the edit/add new screen to allow event by event setting the access of permissions.

Is there an option to enable this for custom posts edit screen? (events in this case)

(i know it is possible to control this via the protection rules screen after enabling the relevant add on for single custom posts)

2. Is it possible to restrict access to all content placed in a certain category. With events+ it is using a custom taxonomy - so is there a way to set access permissions for the entire custom post category?

Many thanks
chris

  • Michael Bissett

    Hey @chris, hope you're doing well this evening! :slight_smile:

    1. It would be great if there was a protected content widget on the edit/add new screen to allow event by event setting the access of permissions.

    Is there an option to enable this for custom posts edit screen? (events in this case)

    We can do this with a bit of code here, please try inserting the following into your site as a mu-plugin (more on the creation of one here):

    add_filter( 'ms_controller_membership_metabox_add_meta_boxes_post_types', 'rit_protect_cpt', 10, 1 );
    
    function rit_protect_cpt( $post_types ) {
    	$post_types[] = 'incsub_event';
    
    	return array_unique( $post_types );
    }

    2. Is it possible to restrict access to all content placed in a certain category. With events+ it is using a custom taxonomy - so is there a way to set access permissions for the entire custom post category?

    This would be something that would require custom development presently, and would require more coding than what I could cook up here in a support thread.

    Currently, you could custom code it within your posts loop to protect the taxonomy based on what membership they level, though this would require quite a bit of custom coding.

    I've put this in as a feature request though, as I can see where having this functionality would be quite useful. :slight_smile:

    Kind Regards,
    Michael

  • chris

    Thanks Michael,

    #1 works like a charm!

    [UPDATE] It actually caused some other issue preventing access to other pages with already protected access. (i may have messed the code up but i dont think so.) I will experiment more with more time.

    Is there any configuration setting to add a catch all protection rule to an entire content type.

    In this example I would like to restrict access to all Events posts and only allow one membership class to access any Events.

    Is this possible?

    Thanks
    Chris

  • Michael Bissett

    Hey @chris,

    Is there any configuration setting to add a catch all protection rule to an entire content type.

    In this example I would like to restrict access to all Events posts and only allow one membership class to access any Events.

    Is this possible?

    Yep, that'd be something we could accomplish by enabling the "URL Protection" add-on, and then going to:

    Membership 2 -> Protection Rules -> URL Restrictions

    And then entering the URL for your events page, like this:

    mysite.com/events/

    That'll also protect any subpages, so all of the events inside will be protected. :slight_smile:

    Hope this helps!

    Kind Regards,
    Michael

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.