From 967e1e499c5ce9e4baa78aba4273238d4e662ed0 Mon Sep 17 00:00:00 2001 From: Kim White Date: Fri, 15 Nov 2024 15:21:06 -0500 Subject: [PATCH] login-login new folder, for login logout recipes. Added 2 recipes from this post: https://www.paidmembershipspro.com/restrict-user-login-for-members-only/ --- .../redirect-member-on-login.php | 0 .../redirect-member-on-logout.php | 0 ...quire-confirmed-email-address-to-login.php | 29 +++++++++++++ .../restrict-user-login-to-active-members.php | 42 +++++++++++++++++++ 4 files changed, 71 insertions(+) rename {misc => login-logout}/redirect-member-on-login.php (100%) rename {misc => login-logout}/redirect-member-on-logout.php (100%) create mode 100644 login-logout/require-confirmed-email-address-to-login.php create mode 100644 login-logout/restrict-user-login-to-active-members.php diff --git a/misc/redirect-member-on-login.php b/login-logout/redirect-member-on-login.php similarity index 100% rename from misc/redirect-member-on-login.php rename to login-logout/redirect-member-on-login.php diff --git a/misc/redirect-member-on-logout.php b/login-logout/redirect-member-on-logout.php similarity index 100% rename from misc/redirect-member-on-logout.php rename to login-logout/redirect-member-on-logout.php diff --git a/login-logout/require-confirmed-email-address-to-login.php b/login-logout/require-confirmed-email-address-to-login.php new file mode 100644 index 0000000..b553bd9 --- /dev/null +++ b/login-logout/require-confirmed-email-address-to-login.php @@ -0,0 +1,29 @@ +ID, "pmpro_email_confirmation_key", true ); + + if( $validated != 'validated' && !empty( $validated ) ) { + return new WP_Error( 'user_not_verified', 'User has not validated their email' ); + } + + return $user; +} + +add_filter( 'wp_authenticate_user', 'my_pmpro_check_login', 10, 2 ); \ No newline at end of file diff --git a/login-logout/restrict-user-login-to-active-members.php b/login-logout/restrict-user-login-to-active-members.php new file mode 100644 index 0000000..e9dd8ad --- /dev/null +++ b/login-logout/restrict-user-login-to-active-members.php @@ -0,0 +1,42 @@ +roles ) ){ + return $user; + } + + $membership_levels = pmpro_getMembershipLevelsForUser( $user->ID ); + + if( empty( $membership_levels ) ){ //No membership level assigned - no login allowed + return; + } + + return $user; + +} +add_filter( 'authenticate', 'mypmpro_validate_membership_login', 99, 3 ); \ No newline at end of file