Last active
August 8, 2018 09:09
-
-
Save Pebblo/25cab2c24fe28b0c65285b15f0e25104 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.
This file contains 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 | |
//* 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 | |
) { | |
//No need to check if $registration is an instance of an EE_Registration as its done in before the action is called. | |
$registrations = $registration->transaction()->registrations(); | |
foreach($registrations as $registration) { | |
if($registration instanceof EE_Registration) { | |
// 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); | |
} | |
} | |
} | |
} | |
} |
This file contains 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 | |
//* 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, 1); | |
function my_remove_one_time_invitation_from_user($registration) { | |
// 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