Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active March 2, 2018 07:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xnau/c014e27d036773269d32686c4de8b06a to your computer and use it in GitHub Desktop.
Save xnau/c014e27d036773269d32686c4de8b06a to your computer and use it in GitHub Desktop.
Shows how to set up the use of custom admin capabilities for Participants Database
<?php
/*
Plugin Name: PDb Custom Admin Capabilities
Description: Sets up the use of custom admin capabilities for Participants Database
*/
add_filter( 'pdb-access_capability', 'xnau_setup_admin_capabilities', 10, 2 );
/**
* sets the custom capabilities for use with the plugin
*
* @param string $capability the default capability for the role
* @param string $context the specific context of the request (ignored)
*
* @return string the capability to test for
*/
function xnau_setup_admin_capabilities( $capability, $context )
{
// translate the incoming standard cap to our custom cap
switch ( $capability ) {
case 'edit_others_posts': // this is for an editor role
$capability = 'edit_pdb_records'; // this is the custom cap for editors
break;
case 'manage_options': // admin role
$capability = 'configure_pdb'; // custom cap for admins
break;
}
return $capability; // return the capability to test for
}
@xnau
Copy link
Author

xnau commented Mar 2, 2018

This gist was created for a tutorial:

Setting Up Custom Access Roles in Participants Database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment