The whitelist filter expects exact URLs to be passed to it, that is why whitelisting just the parent directory of /activate/ won’t work.
However, try adding this (untested) code to your functions.php file instead:
/**
* Filter Force Login to allow exceptions for specific URLs.
*
* @return array An array of URLs. Must be absolute.
**/
function my_forcelogin_whitelist($whitelist) {
// list of single page URLs
$whitelist[] = site_url( '/xmlrpc.php' );
);
// whitelist buddypress login URLs
if( function_exists('bp_is_register_page') ) {
if( bp_is_register_page() && bp_is_activation_page() )
$whitelist[] = site_url($_SERVER['REQUEST_URI']);
}
return $whitelist;
}
add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
Unfortunately, it didn’t work .. all the pages went blank
ahh .. I think I got it! I believe it should be an OR instead of an AND.
I also modified it a bit using some BuddyPress code and didn’t do the bp_is_register_page() check.
I’m a WordPress newbie, so please let me know if there’s something risky/incorrect in my approach. Thank you so much!
function my_forcelogin_whitelist($whitelist) {
// If user is not logged in and
if (!is_user_logged_in() &&
(
// The current page is not register or activation
bp_is_register_page() ||
bp_is_activation_page()
)
)
// list of single page URLs
$whitelist[] = site_url($_SERVER[‘REQUEST_URI’]);
return $whitelist;
}
add_filter(‘v_forcelogin_whitelist’, ‘my_forcelogin_whitelist’, 10, 1);
Ah, ok – thanks for posting your solution!
However, there is one thing about your code that I don’t think needs to be there, you shouldn’t need to check “if the user is not logged-in,” the plugin already does that.
I would try this code instead then:
/**
* Filter Force Login to allow exceptions for specific URLs.
*
* @return array An array of URLs. Must be absolute.
**/
function my_forcelogin_whitelist($whitelist) {
// list of single page URLs
$whitelist[] = site_url( '/xmlrpc.php' );
);
// whitelist buddypress login URLs
if( function_exists('bp_is_register_page') ) {
if( bp_is_register_page() || bp_is_activation_page() ) {
$whitelist[] = site_url($_SERVER['REQUEST_URI']);
}
}
return $whitelist;
}
add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);
Also, if you turn on the WP_DEBUG mode in your wp-config.php file, that might help you figure out what went wrong when “the pages went blank.”
https://codex.ww.wp.xz.cn/Debugging_in_WordPress
Correction to code above:
/**
* Filter Force Login to allow exceptions for specific URLs.
*
* @return array An array of URLs. Must be absolute.
**/
function my_forcelogin_whitelist($whitelist) {
// list of single page URLs
$whitelist[] = site_url( '/xmlrpc.php' );
// whitelist buddypress login URLs
if( function_exists('bp_is_register_page') ) {
if( bp_is_register_page() || bp_is_activation_page() ) {
$whitelist[] = site_url($_SERVER['REQUEST_URI']);
}
}
return $whitelist;
}
add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);