- 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
. - Use the WP User Integration add-on’s feature to set the ticket requirement capability:
- Add the above code to automatically remove that capability after they register for the event: You can add the above to a functions plugin.
Last active
August 3, 2017 16:07
-
-
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.
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'); | |
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' ); | |
} | |
} |
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 | |
/* | |
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