Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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', '');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement