Last active
December 17, 2015 11:49
-
-
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)
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 | |
/* | |
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