wp_set_password

函式
wp_set_password ( $password, $user_id )
引數
  • (string) $password The plaintext new user password.
    Required:
  • (int) $user_id User ID.
    Required:
定義位置
相關方法
wp_hash_passwordreset_passwordwp_check_passwordwp_get_password_hintwp_generate_password
引入
2.5.0
棄用
-

wp_set_password: 這個函式為一個使用者設定一個新的密碼。它接受使用者的ID和新密碼,並在資料庫中更新使用者的密碼。

用新的加密密碼更新使用者的密碼。

對於與其他應用程式的整合,這個函式可以被覆蓋,以取代使用其他軟體包的密碼檢查演算法。

請注意: 這個函式應該儘量少用,實際上只適用於單次應用。如果不採取預防措施,確保它不會在每次頁面載入時執行,那麼在外掛或主題中不適當地利用它可能會導致無休止的密碼重設迴圈。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
endif;
if ( ! function_exists( 'get_avatar' ) ) :
/**
* Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post.
*
* @since 2.5.0
* @since 4.2.0 Optional `$args` parameter added.
*
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
* @param int $size Optional. Height and width of the avatar image file in pixels. Default 96.
* @param string $default Optional. URL for the default image or a default type. Accepts '404'
* (return a 404 instead of a default image), 'retro' (8bit), 'monsterid'
* (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"),
* 'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF),
* or 'gravatar_default' (the Gravatar logo). Default is the value of the
* 'avatar_default' option, with a fallback of 'mystery'.
* @param string $alt Optional. Alternative text to use in img tag. Default empty.
* @param array $args {
* Optional. Extra arguments to retrieve the avatar.
*
* @type int $height Display height of the avatar in pixels. Defaults to $size.
* @type int $width Display width of the avatar in pixels. Defaults to $size.
* @type bool $force_default Whether to always show the default image, never the Gravatar. Default false.
* @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
* judged in that order. Default is the value of the 'avatar_rating' option.
* @type string $scheme URL scheme to use. See set_url_scheme() for accepted values.
* Default null.
* @type array|string $class Array or string of additional classes to add to the img element.
* Default null.
* @type bool $force_display Whether to always show the avatar - ignores the show_avatars option.
* Default false.
* @type string $loading Value for the `loading` attribute.
* Default null.
* @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
* }
* @return string|false `<img>` tag for the user's avatar. False on failure.
*/
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 ); } endif; if ( ! function_exists( 'get_avatar' ) ) : /** * Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post. * * @since 2.5.0 * @since 4.2.0 Optional `$args` parameter added. * * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash, * user email, WP_User object, WP_Post object, or WP_Comment object. * @param int $size Optional. Height and width of the avatar image file in pixels. Default 96. * @param string $default Optional. URL for the default image or a default type. Accepts '404' * (return a 404 instead of a default image), 'retro' (8bit), 'monsterid' * (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"), * 'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), * or 'gravatar_default' (the Gravatar logo). Default is the value of the * 'avatar_default' option, with a fallback of 'mystery'. * @param string $alt Optional. Alternative text to use in img tag. Default empty. * @param array $args { * Optional. Extra arguments to retrieve the avatar. * * @type int $height Display height of the avatar in pixels. Defaults to $size. * @type int $width Display width of the avatar in pixels. Defaults to $size. * @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. * @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are * judged in that order. Default is the value of the 'avatar_rating' option. * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. * Default null. * @type array|string $class Array or string of additional classes to add to the img element. * Default null. * @type bool $force_display Whether to always show the avatar - ignores the show_avatars option. * Default false. * @type string $loading Value for the `loading` attribute. * Default null. * @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty. * } * @return string|false `<img>` tag for the user's avatar. False on failure. */
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 );
	}
endif;

if ( ! function_exists( 'get_avatar' ) ) :
	/**
	 * Retrieves the avatar `<img>` tag for a user, email address, MD5 hash, comment, or post.
	 *
	 * @since 2.5.0
	 * @since 4.2.0 Optional `$args` parameter added.
	 *
	 * @param mixed  $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
	 *                            user email, WP_User object, WP_Post object, or WP_Comment object.
	 * @param int    $size        Optional. Height and width of the avatar image file in pixels. Default 96.
	 * @param string $default     Optional. URL for the default image or a default type. Accepts '404'
	 *                            (return a 404 instead of a default image), 'retro' (8bit), 'monsterid'
	 *                            (monster), 'wavatar' (cartoon face), 'indenticon' (the "quilt"),
	 *                            'mystery', 'mm', or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF),
	 *                            or 'gravatar_default' (the Gravatar logo). Default is the value of the
	 *                            'avatar_default' option, with a fallback of 'mystery'.
	 * @param string $alt         Optional. Alternative text to use in img tag. Default empty.
	 * @param array  $args {
	 *     Optional. Extra arguments to retrieve the avatar.
	 *
	 *     @type int          $height        Display height of the avatar in pixels. Defaults to $size.
	 *     @type int          $width         Display width of the avatar in pixels. Defaults to $size.
	 *     @type bool         $force_default Whether to always show the default image, never the Gravatar. Default false.
	 *     @type string       $rating        What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are
	 *                                       judged in that order. Default is the value of the 'avatar_rating' option.
	 *     @type string       $scheme        URL scheme to use. See set_url_scheme() for accepted values.
	 *                                       Default null.
	 *     @type array|string $class         Array or string of additional classes to add to the img element.
	 *                                       Default null.
	 *     @type bool         $force_display Whether to always show the avatar - ignores the show_avatars option.
	 *                                       Default false.
	 *     @type string       $loading       Value for the `loading` attribute.
	 *                                       Default null.
	 *     @type string       $extra_attr    HTML attributes to insert in the IMG element. Is not sanitized. Default empty.
	 * }
	 * @return string|false `<img>` tag for the user's avatar. False on failure.
	 */

常見問題

FAQs
檢視更多 >