Created
February 10, 2016 06:09
-
-
Save chihirokaasan/99268a6196967eba1274 to your computer and use it in GitHub Desktop.
WordPressのカスタムプロフィールを一番下に挿入する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function custom_user_profile( $user ) { | |
//以下カスタムプロフィールの追加フォーム | |
?> | |
<table id="custom_user_field_table" class="form-table"> | |
<tr id="custom_user_field_row"> | |
<th> | |
<!--項目名--> | |
<label for="custom_field"><?php _e('Field'); ?></label> | |
</th> | |
<td><!--追加のフォームはここ--> | |
<input type="text" name="custom_field" id="custom_field" value="<?php echo esc_attr( get_the_author_meta( 'custom_field', $user->ID ) ); ?>" class="regular-text" /><br /> | |
<span class="description"><?php _e('message is here'); ?></span> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
add_action( 'show_user_profile', 'custom_user_profile',10,2 ); | |
add_action( 'edit_user_profile', 'custom_user_profile',10,2 ); | |
//以下UserMetaのアップデート | |
add_action('profile_update', 'updateMeta',10,2 ); | |
function updateMeta(){ | |
//ここではusermetaのアップデートですが Usermeta以外についてはquery書いて別テーブルにINSERT、UPDATEも出来るね | |
$user_id = $_POST['user_id']; | |
if (!empty($_POST['custom_field'])){ | |
update_user_meta($user_id, 'custom_field', $_POST['custom_field']); | |
} | |
else { | |
delete_user_meta($user_id, 'custom_field', ''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment