Skip to content

Instantly share code, notes, and snippets.

@joshfeck

joshfeck/add_user_cap.php

Last active Oct 7, 2019
Embed
What would you like to do?
Add a new capability to WP User account after they complete a registration for a specific event. Event Espresso 4
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_action(
'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
'my_add_user_cap_for_event',
10,
2
);
function my_add_user_cap_for_event(
$transaction,
$update_params
) {
if($transaction->status_ID() != 'TCM') {
return;
}
$registrations = $transaction->registrations();
foreach($registrations as $registration) {
if($registration instanceof EE_Registration) {
if($registration->get('EVT_ID') == 190) { // swap in your event ID here
$user = new WP_User(get_current_user_id());
if( $user instanceof WP_User ) {
$user->add_cap('a_new_wp_capability'); // swap in your capability here
}
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.