Membership2 PRO - how to tell if a category is protected

We are using Membership2 Pro and our client now wants us to edit our search to allow the user to choose via checkboxes what they would like to search. For example they could check "FAQ" or "Blog" or "Protected Categories". My question is how do we check if a category is protected?

Thanks!

  • mccawphoto
    • The Incredible Code Injector

    Thanks for the quick reply! I realize it is a custom job and my developer has been looking into the api for Membership 2 Pro but has been unable to find anything useful to help check if a category is protected. We want to index the protected categories only for those logged in to the level that is allowed to see that category. How do we check to see if the category is protected?

    Thanks!

  • Luís
    • Support

    Hi @mccawphoto,

    I hope had been good today!

    Firstly, sorry my late reply and all the problems it may have caused.

    Try this function to check if is a protected category:

    add_action( 'ms_init', 'my_api_hook' );
    function my_api_hook( $api ) {
        $cat_id = 71;
        $protect = false;
    
        $base = MS_Model_Membership::get_base();
        $rule = $base->get_rule( MS_Rule_Category::RULE_ID );
        if( $rule->rule_value[$cat_id] ) {
            $protect = true;
        }
    
        return $protect;
    
    }

    Cheers, Luís

  • mccawphoto
    • The Incredible Code Injector

    Hi @Luis,

    Since I started this thread the project has changed. What I am trying to accomplish is this:

    We are using wp_list_categories to create a list of categories for a navigation in our FAQ section. Some of the categories are protected by Membership 2 Pro. My client wants the categories that are protected to be the color Red a user is logged into the appropriate membership level that allows them to view the protected category.

    Can you help me understand how I can use the above code or some other code to accomplish this? I want to make this dynamic so I don't have to manually write new code each time my client protects another category.

    Thanks!

  • Luís
    • Support

    Hi @mccawphoto,

    I hope had been good today!

    I flagged the SLS team (our code experts :slight_smile: ) to investigate further and get their valuable feedback.

    Since this team deals with more advanced threads it may take them longer to reply.

    Cheers, Luís

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.