ユーザー→ユーザーについて→プロフィール情報の下に入力項目を追加する
テキストエリアを追加する場合
function.php
<?php
//ユーザーのプロフィール情報下にテキストエリアを追加
function add_user_essay_form( $bool ) {
global $profileuser;
if ( preg_match( '/^(profile\.php|user-edit\.php)/', basename( $_SERVER['REQUEST_URI'] ) ) ) {
?>
<tr>
<th scope="row"><label for="user_essay">肩書き</label></th>
<td>
<textarea name="user_essay" rows="5" cols="30" onfocus="this.select()"><?php echo esc_attr( $profileuser->user_essay ); ?></textarea>
<p>職務や経歴などを記入してください。</p>
</td>
</tr>
<?php
}
return $bool;
}
add_action( 'show_password_fields', 'add_user_essay_form' );
function update_user_essay( $user_id, $old_user_data ) {
if ( isset( $_POST['user_essay'] ) && $old_user_data->user_essay != $_POST['user_essay'] ) {
$user_essay = wp_filter_kses( $_POST['user_essay'] );
update_user_meta( $user_id, 'user_essay', $user_essay );
}
}
add_action( 'profile_update', 'update_user_essay', 10, 2 );
?>
テキスト項目を追加する場合
function.php
<?php
function add_user_data_form($bool)
{
global $profileuser;
if ( preg_match('/^(profile\.php|user-edit\.php)/', basename($_SERVER['REQUEST_URI'])) )
{ ?>
<tr>
<th scope="row">項目1</th>
<td>
<input type="text" name="user_data1" id="user_data1" value="<?php echo esc_html($profileuser->user_data1); ?>" />
</td>
</tr>
<?php }
return $bool;
}
add_action('show_password_fields', 'add_user_data_form');
function update_user_data($user_id, $old_user_data)
{
if ( isset($_POST['user_data1']) && $old_user_data->user_data1 != $_POST['user_data1'] )
{
$user_data1 = sanitize_text_field($_POST['user_data1']);
$user_data1 = wp_filter_kses($user_data1);
$user_data1 = _wp_specialchars($user_data1);
update_user_meta($user_id, 'user_data1', $user_data1);
}
}
add_action('profile_update', 'update_user_data', 10, 2);
?>
出力する
テキストエリア
echo nl2br($userdata->user_essay);
テキスト
<?php $userdata = get_userdata('ユーザーID'); ?>
<?php echo esc_html($userdata->user_data1); ?>
https://ja.forums.wordpress.org/topic/8406
http://wordpress-design.net/archives/1927
http://aroun-d.com/2012/06/04/3917/