Skip to content

Instantly share code, notes, and snippets.

@ryanshoover
Last active June 23, 2016 16:15
Show Gist options
  • Select an option

  • Save ryanshoover/3cb1c4d57b4859e5fe1b137578556393 to your computer and use it in GitHub Desktop.

Select an option

Save ryanshoover/3cb1c4d57b4859e5fe1b137578556393 to your computer and use it in GitHub Desktop.
WP Plugin for dev sites. You'll always log in if you submit the login form. NOT FOR PRODUCTION SITES
<?php
/*
Plugin Name: Always log in
Version: 0.1
Description: If authentication fails, just log in as user #1. ONLY FOR DEV SITES
Author: ryanshoover
*/
/**
* Always log in if you submit the login form
* @param {WP_User/WP_Error} $user Either the WP_User object or a WP_Error object
* @return {WP_User} The WP_User object from before OR of User #1
*/
function always_log_in( $user ) {
if ( 'developer' == WPE_ENVIRONMENT && is_wp_error( $user ) && ! ( isset( $_GET[ 'loggedout'] ) && true == $_GET[ 'loggedout' ] ) ) {
$user = get_user_by( 'ID', 1 );
}
return $user;
}
add_filter( 'authenticate', 'always_log_in', 999 );
/**
* Memcached hack
* Sometimes, memcached won't clear the cache if you run wp-cli from outside the vagrant
* This fixes that problem
*/
if ( function_exists( 'wp_cache_flush' ) ) {
$flush_actions = ['activate_plugin', 'deactivate_plugin', 'switch_theme', 'generate_rewrite_rules'];
foreach ( $flush_actions as $action ) {
add_action( $action, 'wp_cache_flush' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment