Last active
March 30, 2018 19:21
-
-
Save kevinvess/8f831b8ad29bef4b544d078b4bb55e6b to your computer and use it in GitHub Desktop.
Sample code showing how to allow the Facebook Crawler to bypass the Force Login plugin
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 | |
/** | |
* Bypass Force Login to allow for exceptions. | |
* | |
* @param bool $bypass True to disable Force Login. Default False. | |
* @return boolean | |
*/ | |
function my_forcelogin_bypass( $bypass ) { | |
// Allow the Facebook Crawler to access the site | |
if ( strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/") !== false || strpos($_SERVER["HTTP_USER_AGENT"], "Facebot") !== false ) { | |
$bypass = true; | |
} | |
return $bypass; | |
} | |
add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case you need to allow other social networks to bypass Force Login, here are some other crawler user agents to reference:
https://gist.github.com/Paratron/8676518