How to Allow Different WordPress User Roles Access to the OptinMonster Plugin

If you’re using the OptinMonster plugin for WordPress you can grant access to non-Admin users.

In this article, you’ll learn how to give access to the OptinMonster plugin to other user-roles.

Before You Start

Here are some things to know before you begin:

  • By default, only Administrators (and Super-Administrators for multi-site installs) are allowed to access the OptinMonster plugin.
  • Before adding any code provided in this guide to your site, you should perform a complete site backup.
  • The example code provided in this guide requires that your site is using PHP 5.3 or higher. WordPress strongly recommends using PHP 7+. You can check and upgrade the version of PHP running your site through your hosting account.
  • Adding PHP Code to your site does pose some risks if the code is not added correctly. It could even potentially break your site and your access to the administrative area.
    We recommend using the Code Snippets plugin or adding the code via FTP to your site’s functions.php file.

Grant Access

To provide access to lower user-roles, follow these steps:

  1. Determine the user-role you would like to grand access to. In this example, we provide access to Editor user-role.
  2. Add the following code to your site:
    add_filter( 'optin_monster_api_menu_cap', function( $cap ) { return 'edit_pages'; } );



What are the Code Snippets for each user role?

Allow Editors and Above:

add_filter( 'optin_monster_api_menu_cap', function( $cap ) { return 'edit_pages'; } );

Allow Authors and Above:

add_filter( 'optin_monster_api_menu_cap', function( $cap ) { return 'publish_posts'; } );

Allow Contributors and Above:

add_filter( 'optin_monster_api_menu_cap', function( $cap ) { return 'edit_posts'; } );
After I added my code, my website is no longer working, what happened!?

Check the console for any errors in the code you’ve added.

WPBeginner offers a debugging guide for WordPress here.

Also, make sure that you’ve added your code between the PHP tags. Some developers add a closing PHP tag, and if you add the code snippet after the closing PHP tag then it can break your site.

Most likely something was copied incorrectly or pasted in the wrong location. You can either (1) restore the backup you made in Step 1 or (2) you can use FTP to manually remove that code you just added.

After I updated my theme, the lower user role no longer has access to OptinMonster. Why?

This is most likely because you manually added the code to your functions.php file and it probably got overwritten with the theme’s update. You can re-add the code again to the current active theme or you can use the Code Snippets plugin.