Skip to content

Instantly share code, notes, and snippets.

@nczz
Last active April 26, 2021 07:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nczz/51b9ef63ec50f2f09bbb2f37cd1053a3 to your computer and use it in GitHub Desktop.
Save nczz/51b9ef63ec50f2f09bbb2f37cd1053a3 to your computer and use it in GitHub Desktop.
[WordPress] 忘記後台管理密碼又沒有建立發信功能時的解決辦法 https://www.mxp.tw/6713/
<?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