Protected Categories in Membership 2 Pro

Is there a way to check if a category is protected when using the Membership 2 Pro plugin?

My client has some very specific requests and I am trying to figure out how to accomplish them.

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.

Could anyone help me figure out how I can do this?


  • Kasia Swiderska
    • Support nomad

    Hello mccawphoto,

    I'm not sure how familiar with PHP you are, but there is API documentation for the Membership 2 Pro in Membership 2 -> Help -> API Docs.
    I think you should take a look on the MS_Rule_Category - if this is not something you are comfortable I will ping plugin developer to share some thoughts.

    kind regards,

  • Rupok
    • Support Ninja

    Hi mccawphoto

    I hope you had a wonderful day.

    I've just looked into the API docs but I'm afraid, there is not easy way you can check if a category is protected. However, I've found a code that might give you idea about how you can check if any category has protection rule applied on it or not:

    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;

    Change 71 to your desired category ID in this line: $cat_id = 71;

    Please note, this is not a direct solution to your query but it should help you get the idea of checking rule assigned on any category.

    Have a nice day. Cheers!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.