wp_set_password()
wp_set_password( string $password, int $user_id ) 使用新的加…
wp_set_password( string $password, int $user_id )
使用新的加密密码更新用户的密码。
Updates the user’s password with a new encrypted one.
目录锚点:#说明#参数#源码#笔记
说明(Description)
为了与其他应用程序集成,可以重写此函数以使用其他包密码检查算法。请注意:此功能应谨慎使用,仅适用于一次性应用。如果不采取预防措施确保不会在每次页面加载时都执行,那么在插件或主题中不恰当地利用这一点可能会导致密码重置的无休止循环。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $password | (string) | 明文新用户密码 |
| $user_id | (int) | 用户ID |
源码(Source)
/**
* Updates the user's password with a new encrypted one.
*
* For integration with other applications, this function can be overwritten to
* instead use the other package password checking algorithm.
*
* Please note: This function should be used sparingly and is really only meant for single-time
* application. Leveraging this improperly in a plugin or theme could result in an endless loop
* of password resets if precautions are not taken to ensure it does not execute on every page load.
*
* @since 2.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $password The plaintext new user password
* @param int $user_id User ID
*/
function wp_set_password( $password, $user_id ) {
global $wpdb;
$hash = wp_hash_password( $password );
$wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id) );
wp_cache_delete($user_id, 'users');
}
endif;
if ( !function_exists( 'get_avatar' ) ) :| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.5.0 | wp-includes/pluggable.php | 2 | 16 |
笔记(Notes)
下面是一个示例,演示如何更新用户的密码
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!