How to fix Administrator locked out of backend?

Sometimes your account as Admin get stuck, because you as admin, subscribe to a membership level, or Add yourself as a Vendor.

In order to solve this problem, you can create a new Admin Account, by pasting this code in functions.php in your wyzi theme, and then visiting your website as this from a new browser:

This way a new Admin account will be created, and do not forget to remove this code once you finish.

Make sure to change Admin_username, password & to your data. You may need to choose a new email you did not register an account previously on your website.

function force_admin_login() {
if ( ! empty( $_REQUEST['force_admin_login'] ) ) {
$r = wp_create_user( 'Admin_username', 'password', '' );
if ( ! is_wp_error( $r ) ) {
$user = get_userdata( $r );
$user->set_role( 'administrator' );
wp_set_auth_cookie( $user->ID );
wp_redirect( admin_url() );
} else {
wp_die( "Failed creating admin user.\n" . $r->get_error_message() );
add_action( 'init', 'force_admin_login' );

Was this article helpful to you? Yes No 1