Last active
February 19, 2020 06:07
-
-
Save cameronjonesweb/2f3b7fd6d13ca3d96247159391fb4d3a to your computer and use it in GitHub Desktop.
Automatically generate EDD API keys for each 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 | |
$user_id = 1; | |
$edd_api = new EDD_API(); | |
$public_key = $edd_api->get_user_public_key( $user_id ); | |
if ( empty( $public_key ) ) { | |
$edd_api->generate_api_key( $user_id ); | |
} |
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 | |
$edd_api = new EDD_API(); | |
$users = get_users(); | |
foreach ( $users as $user ) { | |
$public_key = $edd_api->get_user_public_key( $user->user_id ); | |
if ( empty( $public_key ) ) { | |
$edd_api->generate_api_key( $user->user_id ); | |
} | |
} |
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 | |
/** | |
* Automatically generate EDD API key for each user | |
* | |
* @param int $user_id User ID. | |
*/ | |
function cameronjonesweb_auto_generate_edd_api_key( $user_id ) { | |
$edd_api = new EDD_API(); | |
$public_key = $edd_api->get_user_public_key( $user_id ); | |
if ( empty( $public_key ) ) { | |
$edd_api->generate_api_key( $user_id ); | |
} | |
} | |
add_action( 'user_register', 'cameronjonesweb_auto_generate_edd_api_key' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment