Skip to content

Instantly share code, notes, and snippets.

@mattneal-stafflink
Created June 2, 2021 23:36
Show Gist options
  • Save mattneal-stafflink/f8f915174086bb826541c12069bc9754 to your computer and use it in GitHub Desktop.
Save mattneal-stafflink/f8f915174086bb826541c12069bc9754 to your computer and use it in GitHub Desktop.
Allow /register to be accessed when using forcelogin plugin.
<?php
/**
* Bypass Force Login to allow for exceptions. Used to push everyone to the login page, except if they are registering.
* As it stands, this code allows the forcelogin plugin to ignores /register.
*
* @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( '/register/' )
);
if ( ! $bypass ) {
$bypass = in_array( $visited_url, $allowed );
}
return $bypass;
}
add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment