Forked from kimwhite/set-user-to-active-whenever-imported.php
Last active
July 2, 2024 12:46
-
-
Save dwanjuki/8751513bc590065f047ff4cb0e7e34c2 to your computer and use it in GitHub Desktop.
Approve members imported from CSV
This file contains hidden or 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 | |
/** | |
* Make sure approved users are active whenever you run an import using the Import Members From CSV Add On. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function set_imported_user_to_approved( $user_id ) { | |
if ( ! class_exists( 'PMPro_Approvals' ) ) { | |
return; | |
} | |
$users_level = pmpro_getMembershipLevelForUser( $user_id ); | |
// If their level doesn't require approval, just bail. | |
if ( ! empty( $users_level ) && ! PMPro_Approvals::requiresApproval( $users_level->id ) ) { | |
return; | |
} | |
// Set them to approved. | |
PMPro_Approvals::ApproveMember( $user_id, $users_level->id ); | |
} | |
add_action( 'pmproiucsv_post_user_import', 'set_imported_user_to_approved', 50, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment