Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/8751513bc590065f047ff4cb0e7e34c2 to your computer and use it in GitHub Desktop.
Save dwanjuki/8751513bc590065f047ff4cb0e7e34c2 to your computer and use it in GitHub Desktop.
Approve members imported from CSV
<?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