Skip to content

Instantly share code, notes, and snippets.

@selul
Last active July 21, 2021 06:52
Show Gist options
  • Save selul/2f5f76d423f9d44f7b5a927e17001c28 to your computer and use it in GitHub Desktop.
Save selul/2f5f76d423f9d44f7b5a927e17001c28 to your computer and use it in GitHub Desktop.
Remove login on wordpress site
<?php
/*
Plugin Name: Remove login.
Description: Plugin that removes login WordPress, useful on testing environments. Should never be used on production.
Author: Marius Cristea
Version: 0.0.1
*/
add_action( 'after_setup_theme', function () {
if ( ! is_user_logged_in() ) {
$autologin_user = wp_signon(
[
'user_login' => 'admin',
'user_password' => 'admin',
'remember' => true
],
false
);
if ( ! is_wp_error( $autologin_user ) ) {
header( 'Location: wp-admin' );
}
}
} );
add_filter( 'rest_authentication_errors', function () {
wp_set_current_user( 1 );
}, 101 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment