Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Last active August 29, 2015 14:02
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 WillBrubaker/9f71397059ccfec11cc5 to your computer and use it in GitHub Desktop.
Save WillBrubaker/9f71397059ccfec11cc5 to your computer and use it in GitHub Desktop.
An authentication filter for your WordPress development environment
<?php
/**
* Filters 'authenticate'
* to keep user with id 1
* logged in without needing
* to enter l/p
*/
add_filter( 'authenticate', 'wwm_authenticate_filter', 10, 1 );
/**
* The filtering function. If needed, the hook
* passes a total of 3 paramaters, but in this case
* only one is needed.
* @param $user null|WP_User|WP_Error
* @see wp-includes/pluggable.php wp_authenticate_user
*
*/
function wwwm_authenticate_filter( $user ) {
/**
* Because somebody is just going to copy & paste
* this and use it - conditionally check and ONLY
* auto login user 1 if this is running on 'localhost'
*/
if ( 127.0.0.1 == $_SERVER['REMOTE_ADDR'] ) {
$user = new WP_User( 1 );
}
return $user;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment