A Cozmoslabs Product
Documentation / Developer Knowledge Base / Allow other user roles to access plugin functions

Allow other user roles to access plugin functions

This is useful when you might want to give access to specific PMS pages to other users from your website, but you don’t want them to access your whole Dashboard.

In order to achieve this, 2 things are necessary:
* add this custom capability to their user role: pms_edit_capability
* add the same custom capability to your Administrator account

An easy way to assign this capability would be to use the Profile Builder Roles Editor functionality.  You can download the Free version of Profile Builder from here.

Payments and Members

To give access to the Payments and Members pages you need to use the following code:

1
2
3
4
5
6
7
add_filter( 'pms_submenu_page_capability', 'pmsc_allow_editors_to_view_pages', 20, 2 );
function pmsc_allow_editors_to_view_pages( $capability, $menu_slug ){          
    if( in_array( $menu_slug, array( 'paid-member-subscriptions', 'pms-payments-page', 'pms-members-page' ) ) )        
        return 'pms_edit_capability';
 
    return $capability;
}

Other pages

The above code can be modified in order to target other plugin pages as well:

In the code, replace the existing entries or add another comma-separated entry in quotes, e.g.:  array( ‘pms-payments-page’, ‘pms-members-page’, ‘pms-reports-page’ )

Subscription Plans and Discount Codes

To give access to the Subscription Plans and Discount Codes pages, use the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
add_filter( 'pms_custom_post_type_capability', 'pmsc_allow_editors_to_view_cpts', 20, 2 );
function pmsc_allow_editors_to_view_cpts( $capability, $menu_slug ){
 
    $target_pages = array(
        'pms-subscription', // subscription plans
        'pms-discount-codes', // discount codes
    );
 
    if( in_array( $menu_slug, $target_pages ) )
        return 'pms_edit_capability';
 
    return $capability;
 
}

Export Functionality

If you’ve given access to a user role to view the Reports -> Export page, then in order for the “Generate CSV” functionality to actually work you will also need to add the following code:

1
2
3
4
add_filter( 'pms_export_capability', 'pmsc_change_export_capability' );
function pmsc_change_export_capability(){
    return 'pms_edit_capability';
}

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket