Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created December 13, 2016 12:05
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 Pebblo/f0c2ab5e0295f7eca8e463f087ccf9e8 to your computer and use it in GitHub Desktop.
Save Pebblo/f0c2ab5e0295f7eca8e463f087ccf9e8 to your computer and use it in GitHub Desktop.
Example of how to use the context filters with capabilities, this removes the 'Registration Form Answers' metabox from the EE Registration admin page for user that can edit EE registrations but are not admins.
<?php //Please do not include the opening PHP tag if you already have one.
function tw_ee_test_cap_current_user_can_context_filters( $cap, $id ) {
//Check we are checking for the correct capability (anoter plugin/add-on may add additional caps)
//Also check is we are not an Administrator (based on the manage_options cap)
if ( $cap == 'ee_edit_registration' && !current_user_can( 'manage_options' ) ) {
//If not return a capability that we do not have which will be pass to current_user_can()
return 'you_no_access';
}
//Return $cap for standard usage.
return $cap;
}
add_filter( 'FHEE__EE_Capabilities__current_user_can__cap__edit-reg-questions-mbox', 'tw_ee_test_cap_current_user_can_context_filters', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment