A WordPress-centric search engine for devs and theme authors

wp_set_password ›

wp_set_password ( $password, $user_id )
Parameters: (2)
  • (string) $password The plaintext new user password
    Required: Yes
  • (int) $user_id User ID
    Required: Yes
Defined at:

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.


function wp_set_password( $password, $user_id ) {
		global $wpdb;

		$hash = wp_hash_password( $password );
			$wpdb->users, array(
				'user_pass'           => $hash,
				'user_activation_key' => '',
			), array( 'ID' => $user_id )

		wp_cache_delete( $user_id, 'users' );

if ( ! function_exists( 'get_avatar' ) ) :