- 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細)
「関数リファレンス/wp update user」の版間の差分
細 (→関連情報) |
細 |
||
(3人の利用者による、間の8版が非表示) | |||
1行目: | 1行目: | ||
− | + | == 説明<span id="Description"></span> == | |
− | < | + | |
− | + | ||
− | </ | + | |
− | + | ||
− | + | この関数はデータベース内の1件のユーザー情報を更新します。更新情報には配列としてユーザーメタ情報の複数の項目を含めることができますが、カスタムユーザーメタフィールドは更新しません。この関数が更新できるメタ情報は [[関数リファレンス/wp_insert_user|wp_insert_user()]] /[[:en:Function_Reference/wp_insert_user|en]] と同じです。 | |
− | + | ユーザーメタ情報の項目1つを更新するには、[[関数リファレンス/update_user_meta|update_user_meta()]] /[[:en:Function_Reference/update_user_meta|en]] を代わりに使ってください。 | |
− | + | ''新規''ユーザーを作成したり、パスワード変更メールを送らずに更新したりするには、[[関数リファレンス/wp_insert_user|wp_insert_user()]] /[[:en:Function_Reference/wp_insert_user|en]] を代わりに使ってください。 | |
+ | '''参考:''' 現在ログインしているユーザーのパスワードが更新されると、Cookie はクリアされます! | ||
− | + | === 特記事項<span id="Special Note"></span> === | |
− | + | <del>(バージョン3.6より前は) <tt>$userdata</tt> がキー 'ID' を含まなければ、新規ユーザーが作られてそのユーザー ID が返されます。</del> バージョン3.6以降、このようなことはありませんが、この動作は将来復活するかもしれません。[https://core.trac.wordpress.org/ticket/16731 チケット #16731] を見てください。 | |
− | < | + | == 使い方<span id="Usage"></span> == |
+ | <?php wp_update_user( $userdata ) ?> | ||
− | < | + | == パラメータ<span id="Parameters"></span> == |
− | + | {{Parameter|$userdata|mixed|ユーザー情報の配列、stdClass、[[クラスリファレンス/WP_User|WP_User]] オブジェクトのいずれか。}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | < | + | == 戻り値<span id="Return Values"></span> == |
− | + | ||
− | </ | + | |
− | + | ||
− | < | + | ; <tt>(mixed)</tt> : 成功するとユーザー ID を、それ以外の場合は [[クラスリファレンス/WP_Error|WP_Error]] オブジェクトを返します。 |
− | == | + | == 用例<span id="Examples"></span> == |
− | + | ||
− | + | 以下の例はユーザープロフィールの項目「ウェブサイト」を更新する方法を示します: | |
− | < | + | |
− | |||
− | |||
− | |||
− | |||
<pre> | <pre> | ||
<?php | <?php | ||
− | |||
$user_id = 1; | $user_id = 1; | ||
$website = 'http://wordpress.org'; | $website = 'http://wordpress.org'; | ||
52行目: | 37行目: | ||
if ( is_wp_error( $user_id ) ) { | if ( is_wp_error( $user_id ) ) { | ||
− | // | + | // エラー発生、おそらくユーザーが存在しなかった。 |
} else { | } else { | ||
− | // | + | // 成功! |
} | } | ||
</pre> | </pre> | ||
+ | == 参考<span id="Notes"></span> == | ||
− | + | === 内部で使用する関数 === | |
− | + | * [[関数リファレンス/get_userdata|<tt>get_userdata()</tt>]] - 渡された ID からユーザーに紐づく情報のオブジェクトを返します。 | |
− | </ | + | * [[関数リファレンス/wp_hash_password|<tt>wp_hash_password()</tt>]] /[[:en:Function_Reference/wp_hash_password|<tt>en</tt>]] |
− | + | * [[関数リファレンス/wp_insert_user|<tt>wp_insert_user()</tt>]] /[[:en:Function_Reference/wp_insert_user|<tt>en</tt>]] - ユーザーを更新したり、存在しない場合に作成するために使われます。 | |
+ | * [[関数リファレンス/wp_get_current_user|<tt>wp_get_current_user()</tt>]] /[[:en:Function_Reference/wp_get_current_user|<tt>en</tt>]] | ||
+ | * [[関数リファレンス/wp_clear_auth_cookie|<tt>wp_clear_auth_cookie()</tt>]] /[[:en:Function_Reference/wp_clear_auth_cookie|<tt>en</tt>]] | ||
+ | * [[関数リファレンス/wp_set_auth_cookie|<tt>wp_set_auth_cookie()</tt>]] /[[:en:Function_Reference/wp_set_auth_cookie|<tt>en</tt>]] | ||
− | + | === 引数の詳細 === | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | 配列 <tt>$userdata</tt> には次の項目を含めることができます。 | ||
{| border="0" cellspacing="5" summary="User data array fields." | {| border="0" cellspacing="5" summary="User data array fields." | ||
− | |||
|- | |- | ||
− | ! style="font-weight:bold" | | + | ! style="font-weight:bold" | 項目名 |
− | ! | + | ! 項目内容 |
− | ! [[ | + | ! [[プラグイン_API/フィルターフック一覧#.E3.83.87.E3.83.BC.E3.82.BF.E3.83.99.E3.83.BC.E3.82.B9.E6.9B.B8.E3.81.8D.E8.BE.BC.E3.81.BF_4|関連フィルタ]] |
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | ID | | style="font-weight:bold" | ID | ||
− | | | + | | 更新するユーザのユーザID |
| (none) | | (none) | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | user_pass | | style="font-weight:bold" | user_pass | ||
− | | | + | | プレーンテキストパスワード |
| <tt>pre_user_pass</tt> | | <tt>pre_user_pass</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | user_login | | style="font-weight:bold" | user_login | ||
− | | | + | | ログインするためのユーザーのユーザー名を含む文字列。WordPressはユーザー名を変更することはできませんので、関数はこのフィールドを変更することはできない点に、ご注意ください。 |
| <tt>pre_user_login</tt> | | <tt>pre_user_login</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | user_nicename | | style="font-weight:bold" | user_nicename | ||
− | | | + | | URLに含まれる文字列。デフォルトは'user_login'の値 |
| <tt>pre_user_nicename</tt> | | <tt>pre_user_nicename</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | user_url | | style="font-weight:bold" | user_url | ||
− | | | + | | WebサイトのURL |
| <tt>pre_user_url</tt> | | <tt>pre_user_url</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | user_email | | style="font-weight:bold" | user_email | ||
− | | | + | | メールアドレス |
| <tt>pre_user_email</tt> | | <tt>pre_user_email</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | display_name | | style="font-weight:bold" | display_name | ||
− | | | + | | サイトに表示される文字列。デフォルトは'user_login'の値 |
| <tt>pre_user_display_name</tt> | | <tt>pre_user_display_name</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | nickname | | style="font-weight:bold" | nickname | ||
− | | | + | | ニックネーム。デフォルトは'user_login'の値 |
| <tt>pre_user_nickname</tt> | | <tt>pre_user_nickname</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | first_name | | style="font-weight:bold" | first_name | ||
− | | | + | | 名 |
| <tt>pre_user_first_name</tt> | | <tt>pre_user_first_name</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | last_name | | style="font-weight:bold" | last_name | ||
− | | | + | | 姓 |
| <tt>pre_user_last_name</tt> | | <tt>pre_user_last_name</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | description | | style="font-weight:bold" | description | ||
− | | | + | | ユーザに関する説明 |
| <tt>pre_user_description</tt> | | <tt>pre_user_description</tt> | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | rich_editing | | style="font-weight:bold" | rich_editing | ||
− | | | + | | リッチエディタ使用の有効・無効を設定。空でない場合はFalse |
| (none) | | (none) | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | user_registered | | style="font-weight:bold" | user_registered | ||
− | | | + | | ユーザ情報の登録日時(形式:Y-m-d H:i:s) |
| (none) | | (none) | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | role | | style="font-weight:bold" | role | ||
− | | | + | | ユーザ権限を設定するための文字列 |
| (none) | | (none) | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | jabber | | style="font-weight:bold" | jabber | ||
− | | | + | | Jabber アカウント |
| (none) | | (none) | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | aim | | style="font-weight:bold" | aim | ||
− | | | + | | AOL IM アカウント |
| (none) | | (none) | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | yim | | style="font-weight:bold" | yim | ||
− | | | + | | Yahoo IM アカウント |
| (none) | | (none) | ||
|-valign="top" | |-valign="top" | ||
| style="font-weight:bold" | show_admin_bar_front | | style="font-weight:bold" | show_admin_bar_front | ||
− | | | + | | フロントエンドに管理バーを表示する |
| (none) | | (none) | ||
|} | |} | ||
− | + | '''注意:''' <tt>user_pass</tt> は WordPress により自動的にハッシュ化されるため、プレーンテキストである必要があります。 | |
+ | '''注意:''' <tt>user_pass</tt> を更新するとユーザーへ通知メールが送られます。 | ||
+ | == 変更履歴<span id="Change_Log"></span> == | ||
− | + | * [[Version_3.5|3.5.0]]: stdClass または [[クラスリファレンス/WP_User|WP_User]] オブジェクトを受け取るようになりました。 | |
+ | * [[Version 2.0|2.0.0]]: 新規導入 | ||
− | == | + | == ソースファイル<span id="Source_File"></span> == |
− | </ | + | |
− | + | ||
− | + | ||
− | < | + | <tt>wp_update_user()</tt> は {{Trac|wp-includes/user.php}} にあります。 |
− | == | + | == 関連項目<span id="Related"></span> == |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | < | + | |
− | + | ||
− | </ | + | |
+ | [[関数リファレンス/wp_insert_user|wp_insert_user()]], [[関数リファレンス/wp_create_user|wp_create_user()]]<br /> | ||
{{Current User Tags}} | {{Current User Tags}} | ||
+ | , [[関数リファレンス/get_user_meta|get_user_meta()]] /[[:en:Function Reference/get_user_meta|en]] | ||
− | + | {{Tag Footer}} | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | {{原文|Function_Reference/wp_update_user| | + | {{原文|Function_Reference/wp_update_user|158132}} <!-- 21:27, 22 August 2016 Bcole808 版 --> |
+ | {{DEFAULTSORT:Wp_update_user}} | ||
[[Category:関数]] | [[Category:関数]] | ||
[[Category:wp2.0]] | [[Category:wp2.0]] | ||
[[Category:wp3.5]] | [[Category:wp3.5]] | ||
+ | |||
+ | [[en:Function Reference/wp_update_user]] | ||
+ | [[ko:Function Reference/wp_update_user]] |
2017年5月5日 (金) 17:44時点における最新版
説明
この関数はデータベース内の1件のユーザー情報を更新します。更新情報には配列としてユーザーメタ情報の複数の項目を含めることができますが、カスタムユーザーメタフィールドは更新しません。この関数が更新できるメタ情報は wp_insert_user() /en と同じです。
ユーザーメタ情報の項目1つを更新するには、update_user_meta() /en を代わりに使ってください。
新規ユーザーを作成したり、パスワード変更メールを送らずに更新したりするには、wp_insert_user() /en を代わりに使ってください。
参考: 現在ログインしているユーザーのパスワードが更新されると、Cookie はクリアされます!
特記事項
(バージョン3.6より前は) $userdata がキー 'ID' を含まなければ、新規ユーザーが作られてそのユーザー ID が返されます。 バージョン3.6以降、このようなことはありませんが、この動作は将来復活するかもしれません。チケット #16731 を見てください。
使い方
<?php wp_update_user( $userdata ) ?>
パラメータ
- $userdata
- (mixed) (必須) ユーザー情報の配列、stdClass、WP_User オブジェクトのいずれか。
- 初期値: なし
戻り値
- (mixed)
- 成功するとユーザー ID を、それ以外の場合は WP_Error オブジェクトを返します。
用例
以下の例はユーザープロフィールの項目「ウェブサイト」を更新する方法を示します:
<?php $user_id = 1; $website = 'http://wordpress.org'; $user_id = wp_update_user( array( 'ID' => $user_id, 'user_url' => $website ) ); if ( is_wp_error( $user_id ) ) { // エラー発生、おそらくユーザーが存在しなかった。 } else { // 成功! }
参考
内部で使用する関数
- get_userdata() - 渡された ID からユーザーに紐づく情報のオブジェクトを返します。
- wp_hash_password() /en
- wp_insert_user() /en - ユーザーを更新したり、存在しない場合に作成するために使われます。
- wp_get_current_user() /en
- wp_clear_auth_cookie() /en
- wp_set_auth_cookie() /en
引数の詳細
配列 $userdata には次の項目を含めることができます。
項目名 | 項目内容 | 関連フィルタ |
---|---|---|
ID | 更新するユーザのユーザID | (none) |
user_pass | プレーンテキストパスワード | pre_user_pass |
user_login | ログインするためのユーザーのユーザー名を含む文字列。WordPressはユーザー名を変更することはできませんので、関数はこのフィールドを変更することはできない点に、ご注意ください。 | pre_user_login |
user_nicename | URLに含まれる文字列。デフォルトは'user_login'の値 | pre_user_nicename |
user_url | WebサイトのURL | pre_user_url |
user_email | メールアドレス | pre_user_email |
display_name | サイトに表示される文字列。デフォルトは'user_login'の値 | pre_user_display_name |
nickname | ニックネーム。デフォルトは'user_login'の値 | pre_user_nickname |
first_name | 名 | pre_user_first_name |
last_name | 姓 | pre_user_last_name |
description | ユーザに関する説明 | pre_user_description |
rich_editing | リッチエディタ使用の有効・無効を設定。空でない場合はFalse | (none) |
user_registered | ユーザ情報の登録日時(形式:Y-m-d H:i:s) | (none) |
role | ユーザ権限を設定するための文字列 | (none) |
jabber | Jabber アカウント | (none) |
aim | AOL IM アカウント | (none) |
yim | Yahoo IM アカウント | (none) |
show_admin_bar_front | フロントエンドに管理バーを表示する | (none) |
注意: user_pass は WordPress により自動的にハッシュ化されるため、プレーンテキストである必要があります。
注意: user_pass を更新するとユーザーへ通知メールが送られます。
変更履歴
ソースファイル
wp_update_user() は wp-includes/user.php
にあります。
関連項目
wp_insert_user(), wp_create_user()
カレントユーザー関数:
get_current_user_id()/ en,
get_currentuserinfo(),
wp_get_current_user()/ en,
wp_set_current_user(),
current_user_can(),
current_user_can_for_blog()/ en
, get_user_meta() /en
最新英語版: WordPress Codex » Function_Reference/wp_update_user (最新版との差分)