Hi, thanks for using Force Login!
You only have an issue with your custom registration URL – which would have been an issue for you using any version of Force Login.
Force Login is a simple plugin, designed to work with the default WordPress login, lost-password, and register screens.
Since you’re using a custom registration URL/process, you’ll need to use the v_forcelogin_bypass
filter to allow Force Login to bypass your custom URLs.
Please check out the FAQs for examples of how to add an exception for pages.
You may also reference this Github issue about this topic:
https://github.com/kevinvess/wp-force-login/issues/33
Thanks!
Hi!
So I have to use both filters or only the v_forcelogin_bypass?
And if I have to use both filters, is the order of the filters important?
// Custom Registration URL
function my_registration_page( $register_url ) {
return site_url( '/logreg/', 'login' );
}
add_filter( 'register_url', 'my_registration_page', 10, 1 );
// Custom Login URL
function my_login_page( $login_url, $redirect ) {
return site_url( '/logreg/?redirect_to=' . $redirect );
}
add_filter( 'login_url', 'my_login_page', 10, 2 );
/**
* Bypass Force Login to allow for exceptions.
*
* @param bool $bypass Whether to disable Force Login. Default false.
* @param string $visited_url The visited URL.
* @return bool
*/
function my_forcelogin_bypass( $bypass, $visited_url ) {
// Allow all single posts
if ( is_single() ) {
$bypass = true;
}
// Allow these absolute URLs
$allowed = array(
home_url( '/logreg/' ),
);
if ( ! $bypass ) {
$bypass = in_array( $visited_url, $allowed );
}
return $bypass;
}
add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
Contract
Kind regards,
Klaus
Hello!
Ok, I made two plugins.
Plugin ONE with this code:
/**
* Bypass Force Login to allow for exceptions.
*
* @param bool $bypass Whether to disable Force Login. Default false.
* @param string $visited_url The visited URL.
* @return bool
*/
function my_forcelogin_bypass( $bypass, $visited_url ) {
// Allow all single posts
if ( is_single() ) {
$bypass = true;
}
// Allow these absolute URLs
$allowed = array(
home_url( '/logreg/' ),
);
if ( ! $bypass ) {
$bypass = in_array( $visited_url, $allowed );
}
return $bypass;
}
add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
Plugin TWO with this code:
// Custom Registration URL
function my_registration_page( $register_url ) {
return site_url( '/logreg/', 'login' );
}
add_filter( 'register_url', 'my_registration_page', 10, 1 );
// Custom Login URL
function my_login_page( $login_url, $redirect ) {
return site_url( '/logreg/?redirect_to=' . $redirect );
}
add_filter( 'login_url', 'my_login_page', 10, 2 );
Both activated, but I still have the same problem…
Kind regards,
Klaus
Seems to be same problem continuing. I’m closing this thread. Please continue in the original thread.