Skip to content

Instantly share code, notes, and snippets.

@dalethedeveloper
Last active December 17, 2015 11:49
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 dalethedeveloper/5605660 to your computer and use it in GitHub Desktop.
Save dalethedeveloper/5605660 to your computer and use it in GitHub Desktop.
I FORGOT MY WORDPRESS PASSWORD (But I still have write access to the theme files)
<?php
/*
If you don't know a user_id of an admin, find one with $wpdb->query():
SELECT user_id,meta_value FROM {$wpdb->prefix}usermeta WHERE meta_key = 'nickname'
AND user_id IN
(SELECT user_id FROM {$wpdb->prefix}usermeta WHERE meta_value LIKE '%administrator%');
+---------+------------+
| user_id | meta_value |
+---------+------------+
| 1 | admin |
| 87 | guido |
| 810 | mattf |
+---------+------------+
Drop any of these in the nearest executable php on load, like functions.php in current theme
*/
$user_id = 1;
$newpass = wp_hash_password('PASSWORD');
// Method 1: http://stackoverflow.com/questions/6083618/wordpress-update-users-password-with-php
update_user_meta($user_id, 'user_pass', $newpass);
// Method 2: http://stackoverflow.com/questions/6083618/wordpress-update-users-password-with-php
wp_update_user( array ('ID' => $user_id, 'user_pass' => $newpass) ) ;
// Method 3, old school
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->prefix}users SET user_pass = %s WHERE ID = %d",
$newpass,
$user_id
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment