Skip to content

Instantly share code, notes, and snippets.

@kevinvess
Last active March 30, 2018 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinvess/8f831b8ad29bef4b544d078b4bb55e6b to your computer and use it in GitHub Desktop.
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
<?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' );
@kevinvess
Copy link
Author

kevinvess commented Mar 30, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment