我创建了一个函数,该函数使用 生成一个 21 位随机字符串,使用wp_generate_password()对其进行哈希处理wp_hash(),将生成的字符串保存到数据库,然后return将哈希字符串保存到数据库中。它工作得很好。但是,我想做另一种方式,而不是将生成的随机字符串保存到数据库中,我想保存散列字符串和return随机字符串。
但它不起作用。当我尝试将散列字符串保存在数据库中时,它根本不会创建任何条目。如果我想保存随机字符串,效果很好。
我已经尝试清理散列字符串, applied strval(), applied $wpdb->insertwithformat我将其声明为字符串的地方。什么都不管用!我什至尝试将服务器资源增加到 4GB 内存、2Vcore 处理器。将每个 php.ini 资源限制增加到 3GB。什么都不管用。
这是完美运行的功能。但是,在这个函数中,我想用替换'verification_code'=>$email_verification,'verification_code'=>$email_verification_hashed它不起作用。我想让它工作,以便散列字符串进入数据库并返回随机字符串。
function generate_verification($user_id) {
$user_info = get_userdata($user_id);
$email_verification = wp_generate_password( 21, true, true );
$email_verification_hashed = wp_hash( $email_verification );
if (isset($user_info)) {
global $wpdb;
$table_name = $wpdb->base_prefix.'custom_table'; //already exist
$user_email = $user_info->user_email;
$data = array('email'=>$user_email, 'verification_code'=>$email_verification, 'user_id'=>$user_id);
$where = array('user_id'=>$user_id);
$existing_data = "SELECT * FROM {$wpdb->prefix}custom_table WHERE user_id = {$user_id}";
$existing_data_results = $wpdb->get_results($query);
if($existing_data_results > 0) {
$wpdb->update( $table_name, $data, $where);
return $email_verification_hashed;
} else {
$wpdb->insert( $table_name, $data);
return $email_verification_hashed;
}
} else {
return 'Failed';
}
}
呼如林
繁星点点滴滴
随时随地看视频慕课网APP