Created
July 15, 2020 23:12
-
-
Save thomasplevy/8b8fff0d37b7b2af936923c22bd324d9 to your computer and use it in GitHub Desktop.
Make the BuddyPress/BuddyBoss "Private Network" available only to "active" LifterLMS User Accounts
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 // don't copy this to a functions.php file! | |
/** | |
* Make the BuddyPress/BuddyBoss "Private Network" available only to "active" LifterLMS User Accounts | |
* | |
* An "active" account is any logged in user with active enrollment into at least one course or membership. | |
* | |
* @return void | |
*/ | |
function bp_llms_private_network_redirect() { | |
// Short circuit if LifterLMS or BuddyPress are disabled. | |
if ( ! function_exists( 'llms_get_student' ) || ! function_exists( 'bp_enable_private_network' ) ) { | |
return; | |
} | |
$student = llms_get_student(); | |
// Logged in student, BP Private Network is Enabled and the student is inactive. | |
if ( $student && bp_enable_private_network() && ! $student->is_active() ) { | |
$redirect_url = is_ssl() ? 'https://' : 'http://'; | |
$redirect_url .= isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : ''; | |
$redirect_url .= isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : ''; | |
$defaults = array( | |
'mode' => 2, | |
'redirect' => $redirect_url, | |
'root' => bp_get_root_domain(), | |
'message' => __( 'Please login to access this website.', 'buddyboss' ), | |
); | |
bp_core_no_access( $defaults ); | |
} | |
} | |
add_action( 'bp_template_redirect', 'bp_llms_private_network_redirect', 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment