Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jtsternberg
Last active November 19, 2020 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtsternberg/ed8ac54a36ab12d543c99db7486516e6 to your computer and use it in GitHub Desktop.
Save jtsternberg/ed8ac54a36ab12d543c99db7486516e6 to your computer and use it in GitHub Desktop.
Define a list of allowed users which can access the OptinMonster admin pages.
<?php
// Comma-separated list of WordPress user ids allowed access to the OptinMonster pages.
define( 'ALLOWED_OM_USERS', '1,2,5' );
// The new capability defined for viewing OM pages.
// function for_om_get_allowed_cap() {
// return 'optinmonster_allowed';
// }
// add_filter( 'optin_monster_api_menu_cap', 'for_om_get_allowed_cap' );
// // Checking given user against the list of allowed users.
// function for_om_is_user_in_allowed_list( $user_id ) {
// if ( ! defined( 'ALLOWED_OM_USERS' ) ) {
// return $user_id;
// }
// $allowed = array_map( 'absint', explode( ',', ALLOWED_OM_USERS ) );
// return in_array( absint( $user_id ), $allowed, true );
// }
// // Determines if given user has the new OM allowed capability.
// function om_check_if_user_allowed_access( $caps, $cap, $user_id ) {
// if ( for_om_get_allowed_cap() === $cap && ! for_om_is_user_in_allowed_list( $user_id ) ) {
// // Search for and remove the optinmonster_allowed capability.
// $key = array_search( for_om_get_allowed_cap(), $caps );
// if ( false !== $key ) {
// unset( $caps[ $key ] );
// }
// // Handles for multisite super admins, which have all caps by definition,
// // unless specifically denied.
// $caps[] = 'do_not_allow';
// }
// return $caps;
// }
// add_filter( 'map_meta_cap', 'om_check_if_user_allowed_access', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment