Created
December 13, 2021 17:26
-
-
Save dcavins/704a3b9dafe81992265b6bfc5ea1c1b0 to your computer and use it in GitHub Desktop.
Automatically approve membership requests that satisfy some criteria.
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 | |
/** | |
* If a user submits a site membership request, but has a | |
* 'my-school.edu' email address, bypass the manual approval of the request. | |
* | |
* @param bool $send Whether or not this membership request should be approved | |
* immediately and the activation email sent. | |
* Default is `false` meaning that the request should be | |
* manually approved by a site admin. | |
* @param array $details The details of the request. | |
*/ | |
function bpcodex_auto_approve_some_requests( $send, $details ) { | |
// We'll need the prospective user's email address. | |
if ( empty( $details['user_email'] ) ) { | |
return $send; | |
} | |
$email_parts = explode( '@', $details['user_email'] ); | |
// If the email address is one of ours, approve the request. | |
if ( ! empty( $email_parts[1] ) && 'my-school.edu' === $email_parts[1] ) { | |
$send = true; | |
} | |
return $send; | |
} | |
add_filter( 'bp_members_membership_requests_bypass_manual_approval', 'bpcodex_auto_approve_some_requests', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment