Last active
September 23, 2025 02:42
-
-
Save xnau/d2f23e7650bbe3c7ad7b67ebb75862ec to your computer and use it in GitHub Desktop.
Demonstrates a simple plugin to prevent a Participants Database user with an editor role from deleting records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: PDB Prevent Editor Delete Records | |
| * Description: prevent users with an editor role from deleting records | |
| * Version: 1.0 | |
| * | |
| * @see https://xnau.com/user-access-control/ | |
| */ | |
| add_filter( 'pdb-access_capability', 'xnau_editor_delete_cap', 10, 2 ); | |
| /** | |
| * alters access privileges | |
| * | |
| * @see https://codex.wordpress.org/Roles_and_Capabilities | |
| * | |
| * @param string $cap current WP capability for the privilege | |
| * @param string $context the privilege requested | |
| * @return string the WP capability to use for the privilege | |
| */ | |
| function xnau_editor_delete_cap( $cap, $context ) | |
| { | |
| switch ( $context ) { | |
| case 'delete participants'; // this is the particular privilege we want to change | |
| /* | |
| * this is the WP capability the the user must have, "manage_options" is a | |
| * capability only an admin will have | |
| */ | |
| $cap = 'manage_options'; | |
| break; | |
| } | |
| return $cap; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment