当サイト、Codex 日本語版は今後積極的な更新は行わない予定です。後継となる新ユーザーマニュアルは、https://ja.wordpress.org/support/ にあります。
万が一、当サイトで重大な問題を発見した際などは、フォーラムWordSlack #docs チャンネルでお知らせください。</p>

「関数リファレンス/wp insert user」の版間の差分

提供: WordPress Codex 日本語版
移動先: 案内検索
(en:Function Reference/wp insert user 13:49, 29 March 2017 Lpointet 版を流し込み。)
 
154行目: 154行目:
 
locale
 
locale
 
</pre>
 
</pre>
When performing an update operation using [[関数リファレンス/wp_insert_user|<tt>wp_insert_user</tt>]], user_pass should be the hashed password and not the plain text password.
+
When performing an update operation using [[関数リファレンス/wp_insert_user|<tt>wp_insert_user()</tt>]], user_pass should be the hashed password and not the plain text password.
  
 
== 変更履歴<span id="Change_Log"></span> ==
 
== 変更履歴<span id="Change_Log"></span> ==
174行目: 174行目:
 
{{原文|Function_Reference/wp_insert_user|160340}} <!-- 13:49, 29 March 2017 Lpointet 版 -->
 
{{原文|Function_Reference/wp_insert_user|160340}} <!-- 13:49, 29 March 2017 Lpointet 版 -->
  
{{DEFAULTSORT:Wp_update_user}}
+
{{DEFAULTSORT:Wp_insert_user}}
 
[[Category:関数]]
 
[[Category:関数]]
  

2017年5月5日 (金) 16:26時点における版

このページ「関数リファレンス/wp insert user」は未翻訳です。和訳や日本語情報を加筆してくださる協力者を求めています

説明

Insert /Update a user into the database. For updating an existing user and sending a password change email, use wp_update_user() /en function instead.

使い方

<?php wp_insert_user( $userdata ); ?>

パラメータ

$userdata
mixed) (必須) An array of user data, stdClass or WP_User object.
初期値: なし

戻り値

(mixed) 
  • If successful, returns the newly-created user's user_id
  • If query fails returns a WP_Error object
  • If user_login is longer than 60 characters, returns a WP_Error object.
  • If user_nicename is longer than 50 characters, returns a WP_Error object.

用例

Below is an example showing how to insert a new user with the website profile field filled.

<?php

$website = "http://example.com";
$userdata = array(
    'user_login'  =>  'login_name',
    'user_url'    =>  $website,
    'user_pass'   =>  NULL  // When creating an user, `user_pass` is expected.
);

$user_id = wp_insert_user( $userdata ) ;

//On success
if ( ! is_wp_error( $user_id ) ) {
    echo "User created : ". $user_id;
}

?>

参考

内部で使われる関数

この関数は内部で以下の関数を使います。

  • Uses: $wpdb WordPress database layer.
  • Uses: apply_filters() Calls filters for most of the $userdata fields with the prefix 'pre_user'. See description above.
  • Uses: do_action() Calls 'profile_update' hook when updating giving the user's ID
  • Uses: do_action() Calls 'user_register' hook when creating a new user giving the user's ID

引数の詳細

配列 $userdata には次の項目を含めることができます。

Field Name Description Associated Filter
ID An integer that will be used for updating an existing user. (none)
user_pass A string that contains the plain text password for the user. pre_user_pass
user_login A string that contains the user's username for logging in. pre_user_login
user_nicename A string that contains a URL-friendly name for the user. The default is the user's username. pre_user_nicename
user_url A string containing the user's URL for the user's web site. pre_user_url
user_email A string containing the user's email address. pre_user_email
display_name A string that will be shown on the site. Defaults to user's username. It is likely that you will want to change this, for both appearance and security through obscurity (that is if you dont use and delete the default admin user). pre_user_display_name
nickname The user's nickname, defaults to the user's username. pre_user_nickname
first_name The user's first name. pre_user_first_name
last_name The user's last name. pre_user_last_name
description A string containing content about the user. pre_user_description
rich_editing A string for whether to enable the rich editor or not. False if not empty. (none)
user_registered The date the user registered. Format is Y-m-d H:i:s. (none)
role A string used to set the user's role. (none)
jabber User's Jabber account. (none)
aim User's AOL IM account. (none)
yim User's Yahoo IM account. (none)
locale User's locale. (none)


If there is no ID, a new user will be created. If you pass an ID , the user with that ID will be updated, and these meta fields are updated if set in $userdata otherwise they are set to null:

first_name,
last_name, 
nickname,
description,
rich_editing,
comment_shortcuts,
admin_color,
use_ssl,
show_admin_bar_front,
locale

When performing an update operation using wp_insert_user(), user_pass should be the hashed password and not the plain text password.

変更履歴

  • 4.7.0: Now accepts 'locale' as $userdata's key
  • 3.5.0: Now accepts stdClass or WP_User object
  • Since: 2.0.0

ソースファイル

As of 3.1 wp_insert_user() is located in wp-includes/user.php.

関連項目

wp_update_user(), wp_create_user()
ブログユーザー関数: add_user_to_blog(), add_new_user_to_blog(), remove_user_from_blog(), get_users_of_blog(), is_user_member_of_blog()


関数リファレンステンプレートタグ目次もご覧ください。


最新英語版: WordPress Codex » Function_Reference/wp_insert_user最新版との差分