Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active August 3, 2017 16:07
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 joshfeck/51c2ef122616b48cc4846b1f44384859 to your computer and use it in GitHub Desktop.
Save joshfeck/51c2ef122616b48cc4846b1f44384859 to your computer and use it in GitHub Desktop.
Remove a WP user capability from a user **after** the user registers for an Event Espresso event.
<?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');
function my_remove_one_time_invitation_from_user() {
if (current_user_can( 'has_unique_invitation_code' )){
$user = new WP_User( get_current_user_id() );
$user->remove_cap( 'has_unique_invitation_code' );
}
}

Usage Notes

  1. Use a script, see below, or a plugin like the User Role Editor plugin to create a new capability and grant that capability to user accounts. In this example the capability is has_unique_invitation_code.
  2. Use the WP User Integration add-on’s feature to set the ticket requirement capability: Ticket Capability Requirement
  3. Add the above code to automatically remove that capability after they register for the event: You can add the above to a functions plugin.
<?php
/*
Plugin Name: Add User Capability on Activation
Description: Adds a capability to an array of user accounts specified by email address. Deactivate and delete this plugin after activation.
Version: 1.0
*/
function add_user_caps_on_activate() {
$selectedUserEmails =
array(
'example1@example.com',
'example2@example.com',
'example3@example.com',
// and more added here
);
foreach ( $selectedUserEmails as $userEmail ) {
if ( filter_var( $userEmail, FILTER_VALIDATE_EMAIL ) ) {
$user = get_user_by( 'email', $userEmail );
if ( ! empty( $user ) ) {
$user->add_cap( 'has_unique_invitation_code' );
}
}
}
}
register_activation_hook( __FILE__, 'add_user_caps_on_activate' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment