Last active
April 26, 2021 07:26
-
-
Save nczz/51b9ef63ec50f2f09bbb2f37cd1053a3 to your computer and use it in GitHub Desktop.
[WordPress] 忘記後台管理密碼又沒有建立發信功能時的解決辦法 https://www.mxp.tw/6713/
This file contains 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 | |
include 'wp-load.php'; | |
global $wpdb; | |
$new_pwd = wp_hash_password('PASSWORD_HRER'); | |
$admin_email = 'YOUR_ACCOUNT_EMAIL_HERE'; | |
$user_table = $wpdb->prefix."users"; | |
$res = $wpdb->update($user_table,array('user_pass'=>$new_pwd),array('user_email'=>$admin_email)); | |
if ($_GET['admin']){ | |
$user_id = $wpdb->get_results("SELECT ID FROM {$user_table} WHERE user_email = '{$admin_email}'",ARRAY_A); | |
$user = new WP_User( $user_id[0]['ID'] ); | |
$user->set_role( 'administrator' ); | |
} | |
if ($res===false){ | |
echo "Fail!"; | |
} else { | |
echo "GJ!"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment