wp_set_password() WordPress Function

The wp_set_password() function allows you to set the password for a user account. This function can be used by administrators to reset a user's password, or by users who have forgotten their password.

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.


Top ↑

Parameters

$password

(string)(Required)The plaintext new user password

$user_id

(int)(Required)User ID


Top ↑

Source

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

		clean_user_cache( $user_id );
	}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More