Skip to content

Instantly share code, notes, and snippets.

Kevin Vess kevinvess

Block or report user

Report or block kevinvess

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kevinvess
kevinvess / wp-force-login-buddypress.php
Created Mar 1, 2017
Sample code showing how to bypass the Force Login plugin for BuddyPress registration
View wp-force-login-buddypress.php
<?php
/**
* Bypass Force Login to allow for exceptions.
*
* @return bool Whether to disable Force Login. Default false.
*/
function my_forcelogin_bypass( $bypass ) {
// add exception for buddypress login URLs
if ( function_exists('bp_is_register_page') ) {
if ( bp_is_register_page() || bp_is_activation_page() ) {
@kevinvess
kevinvess / wp-force-login-bypass-facebook.php
Last active Mar 30, 2018
Sample code showing how to allow the Facebook Crawler to bypass the Force Login plugin
View wp-force-login-bypass-facebook.php
<?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 ) {
@kevinvess
kevinvess / wp-force-login-bypass.php
Last active Apr 4, 2017
Sample code showing how to bypass the Force Login plugin for certain pages or posts
View wp-force-login-bypass.php
<?php
/**
* Bypass Force Login to allow for exceptions.
*
* @return bool Whether to disable Force Login. Default false.
*/
function my_forcelogin_bypass( $bypass ) {
if ( is_home() ) {
$bypass = true;
}
@kevinvess
kevinvess / wp-force-login-whitelist-dir.php
Last active Mar 1, 2017
Sample code showing how to add exceptions for any URL within a specified directory for the Force Login plugin
View wp-force-login-whitelist-dir.php
<?php
/**
* Filter Force Login to allow exceptions for specific URLs.
*
* @return array An array of URLs. Must be absolute.
*/
function my_forcelogin_whitelist( $whitelist ) {
// Get visited URL without query string
$url_path = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
@kevinvess
kevinvess / wp-force-login-whitelist.php
Last active Sep 15, 2016
Sample code showing how to add exceptions for specific URLs in the Force Login plugin
View wp-force-login-whitelist.php
<?php
/**
* 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( '/mypage/' );
$whitelist[] = site_url( '/2015/03/post-title/' );
@kevinvess
kevinvess / wp-force-login-redirect.php
Created Mar 27, 2015
Sample code showing how to set a custom redirect in the Force Login plugin
View wp-force-login-redirect.php
<?php
/**
* Set the URL to redirect to on login.
*
* @return string URL to redirect to on login. Must be absolute.
**/
function my_forcelogin_redirect() {
return site_url( '/mypage/' );
}
add_filter('v_forcelogin_redirect', 'my_forcelogin_redirect', 10, 1);
@kevinvess
kevinvess / wp-force-login-cli.php
Created Mar 18, 2015
Added an exception to allow command line prompt while my Force Login plugin is activated.
View wp-force-login-cli.php
<?php
function v_is_cli() {
if(php_sapi_name() == 'cli' && empty($_SERVER['REMOTE_ADDR'])) {
return true;
} else {
return false;
}
}
function v_forcelogin() {
@kevinvess
kevinvess / wp-force-login-xmlrpc.php
Created Dec 8, 2014
Added an exception to allow WordPress XML-RPC remote publishing while my Force Login plugin is activated.
View wp-force-login-xmlrpc.php
<?php
function v_forcelogin() {
$url = v_getUrl();
if( !is_user_logged_in() && preg_replace('/\?.*/', '', $url) != preg_replace('/\?.*/', '', wp_login_url()) ) {
if( substr(preg_replace('/\?.*/', '', $url), -10) != 'xmlrpc.php' ) {
wp_safe_redirect( wp_login_url( $url ), 302 ); exit();
}
}
}
@kevinvess
kevinvess / wp-force-login-alt.php
Last active Jun 30, 2016
Added an exception to allow localhost access while my Force Login plugin is activated.
View wp-force-login-alt.php
<?php
function v_forcelogin() {
$url = v_getUrl();
if( !is_user_logged_in() && preg_replace('/\?.*/', '', $url) != preg_replace('/\?.*/', '', wp_login_url()) ) {
if( $_SERVER['REMOTE_ADDR'] != '127.0.0.1' ) {
wp_safe_redirect( wp_login_url( $url ), 302 ); exit();
}
}
}
@kevinvess
kevinvess / wordpress-replace-siteurl.sql
Last active Jun 22, 2018
This SQL statement will replace any instance of the site's current url with a new url in all the common locations of a WordPress database.
View wordpress-replace-siteurl.sql
UPDATE wp_options SET option_value = replace(option_value, 'http://current-url.com', 'http://new-url.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://current-url.com', 'http://new-url.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://current-url.com', 'http://new-url.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://current-url.com', 'http://new-url.com');
You can’t perform that action at this time.