Last active
August 29, 2015 14:02
-
-
Save WillBrubaker/9f71397059ccfec11cc5 to your computer and use it in GitHub Desktop.
An authentication filter for your WordPress development environment
This file contains hidden or 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 | |
/** | |
* 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