Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewlimaza/06b95254f23ffbe0d78606248c6fed6a to your computer and use it in GitHub Desktop.
Save andrewlimaza/06b95254f23ffbe0d78606248c6fed6a to your computer and use it in GitHub Desktop.
Reset user to pending when importing from CSV.
<?php
/**
* Set the user to "pending" whenever you run an import using the Import Users From CSV Integration for Paid Memberships Pro.
*
* 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_pending( $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 pending.
PMPro_Approvals::resetMember( $user_id, $users_level->id );
}
add_action( 'is_iu_post_user_import', 'set_imported_user_to_pending', 50, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment