Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Forked from Pebblo/example-multiple-caps.php
Last active August 3, 2018 22:52
Show Gist options
  • Save joshfeck/ad9d682bf56880eeb7d489ed9c16c93f to your computer and use it in GitHub Desktop.
Save joshfeck/ad9d682bf56880eeb7d489ed9c16c93f to your computer and use it in GitHub Desktop.
Example of how to dynamically remove the current registrations ticket capability (if set) from the current user.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_action(
'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
'my_remove_one_time_invitation_from_user',
10,
2
);
function my_remove_one_time_invitation_from_user(
$registration,
$additional_details
) {
// Pull the registrations ticket object.
$ticket = $registration->ticket();
// Check we actually have an EE_Ticket object.
if($ticket instanceof EE_Ticket) {
// Pull the capability set on the ticket.
$cap_required = $ticket->get_extra_meta('ee_ticket_cap_required', true);
// If we have a capbility that begins with 'has_unique_invitation_code' set on the ticket and the current user has that cap, remove it from the user.
if( !empty($cap_required)
&& current_user_can($cap_required)
&& strpos($cap_required, 'has_unique_invitation_code' ) !== false
){
$user = new WP_User(get_current_user_id());
$user->remove_cap($cap_required);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment