返回介绍

wp_set_password()

发布于 2017-09-11 12:52:36 字数 2634 浏览 1171 评论 0 收藏 0

wp_set_password( string $password,  int $user_id )

Updates the user’s password with a new encrypted one.


description

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.


参数

$password

(string) (Required) The plaintext new user password

$user_id

(int) (Required) User ID


源代码

File: wp-includes/pluggable.php

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');
}

更新日志

Versiondescription
2.5.0Introduced.

相关函数

Uses

  • wp-includes/cache.php: wp_cache_delete()
  • wp-includes/pluggable.php: wp_hash_password()
  • wp-includes/wp-db.php: wpdb::update()

Used By

  • wp-includes/pluggable.php: wp_check_password()
  • wp-includes/user.php: reset_password()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Below is an example showing how to update a user’s password

    
    <?php
    $user_id = 1;
    $password = 'HelloWorld';
    wp_set_password( $password, $user_id );
    ?>
    

    Please note: This code should be deleted after ONE page load, otherwise the password will be reset on every subsequent load, sending the user back to the login screen each time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文