Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. function custom_user_profile( $user ) {
  2. //以下カスタムプロフィールの追加フォーム
  3. ?>
  4. <table id="custom_user_field_table" class="form-table">
  5. <tr id="custom_user_field_row">
  6. <th>
  7. <!--項目名-->
  8. <label for="custom_field"><?php _e('Field'); ?></label>
  9. </th>
  10. <td><!--追加のフォームはここ-->
  11. <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 />
  12. <span class="description"><?php _e('message is here'); ?></span>
  13. </td>
  14. </tr>
  15. </table>
  16. <?php
  17. }
  18. add_action( 'show_user_profile', 'custom_user_profile',10,2 );
  19. add_action( 'edit_user_profile', 'custom_user_profile',10,2 );
  20. //以下UserMetaのアップデート
  21. add_action('profile_update', 'updateMeta',10,2 );
  22. function updateMeta(){
  23. //ここではusermetaのアップデートですが Usermeta以外についてはquery書いて別テーブルにINSERT、UPDATEも出来るね
  24. $user_id = $_POST['user_id'];
  25. if (!empty($_POST['custom_field'])){
  26. update_user_meta($user_id, 'custom_field', $_POST['custom_field']);
  27. }
  28. else {
  29. delete_user_meta($user_id, 'custom_field', '');
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement