Advertisement
afsarwebdev

WP User Profile Custom Field

May 14th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.97 KB | None | 0 0
  1. //User profile custom field for extra information (Backend in Dashboard user profile)
  2.  
  3. // user profile custom field
  4. add_action('show_user_profile', 'yoursite_extra_user_profile_fields');
  5. add_action('edit_user_profile', 'yoursite_extra_user_profile_fields');
  6. function yoursite_extra_user_profile_fields($user)
  7. {
  8. ?>
  9. <h3><?php _e("Extra profile information", "blank"); ?></h3>
  10. <table class="form-table">
  11. <tr>
  12. <th><label for="designation"><?php _e("Designation"); ?></label></th>
  13. <td>
  14. <input type="text" name="designation" id="designation" class="regular-text"
  15. value="<?php echo esc_attr(get_the_author_meta('designation', $user->ID)); ?>"/><br/>
  16. <span class="description"><?php _e("Enter your designation."); ?></span>
  17. </td>
  18. </tr>
  19. <tr>
  20. <th><label for="facebook_p_link"><?php _e("Facebook Profile Link"); ?></label></th>
  21. <td>
  22. <input type="text" name="facebook_p_link" id="facebook_p_link" class="regular-text"
  23. value="<?php echo esc_attr(get_the_author_meta('facebook_p_link', $user->ID)); ?>"/><br/>
  24. <span class="description"><?php _e("Enter your Facebook Link."); ?></span>
  25. </td>
  26. </tr>
  27. <tr>
  28. <th><label for="twitter_p_link"><?php _e("Twitter Profile Link"); ?></label></th>
  29. <td>
  30. <input type="text" name="twitter_p_link" id="twitter_p_link" class="regular-text"
  31. value="<?php echo esc_attr(get_the_author_meta('twitter_p_link', $user->ID)); ?>"/><br/>
  32. <span class="description"><?php _e("Enter your Twitter Link."); ?></span>
  33. </td>
  34. </tr>
  35. <tr>
  36. <th><label for="linkedin_p_link"><?php _e("Linkedin Profile Link"); ?></label></th>
  37. <td>
  38. <input type="text" name="linkedin_p_link" id="linkedin_p_link" class="regular-text"
  39. value="<?php echo esc_attr(get_the_author_meta('linkedin_p_link', $user->ID)); ?>"/><br/>
  40. <span class="description"><?php _e("Enter your Twitter Link."); ?></span>
  41. </td>
  42. </tr>
  43. <tr>
  44. <th><label for="pinterest_p_link"><?php _e("Pintrest Profile Link"); ?></label></th>
  45. <td>
  46. <input type="text" name="pinterest_p_link" id="pinterest_p_link" class="regular-text"
  47. value="<?php echo esc_attr(get_the_author_meta('pinterest_p_link', $user->ID)); ?>"/><br/>
  48. <span class="description"><?php _e("Enter your Pinterest Link."); ?></span>
  49. </td>
  50. </tr>
  51. <tr>
  52. <th><label for="gplus_p_link"><?php _e("Google Plus Profile Link"); ?></label></th>
  53. <td>
  54. <input type="text" name="gplus_p_link" id="gplus_p_link" class="regular-text"
  55. value="<?php echo esc_attr(get_the_author_meta('gplus_p_link', $user->ID)); ?>"/><br/>
  56. <span class="description"><?php _e("Enter your Google Plus Link."); ?></span>
  57. </td>
  58. </tr>
  59. <tr>
  60. <th><label for="vk_p_link"><?php _e("VK Profile Link"); ?></label></th>
  61. <td>
  62. <input type="text" name="vk_p_link" id="vk_p_link" class="regular-text"
  63. value="<?php echo esc_attr(get_the_author_meta('vk_p_link', $user->ID)); ?>"/><br/>
  64. <span class="description"><?php _e("Enter your VK Link."); ?></span>
  65. </td>
  66. </tr>
  67. </table>
  68. <?php
  69. }
  70.  
  71. // user profile data save
  72. add_action('personal_options_update', 'yoursite_save_extra_user_profile_fields');
  73. add_action('edit_user_profile_update', 'yoursite_save_extra_user_profile_fields');
  74. function yoursite_save_extra_user_profile_fields($user_id)
  75. {
  76. $saved = false;
  77. if (current_user_can('edit_user', $user_id)) {
  78. update_user_meta($user_id, 'designation', $_POST['designation']);
  79. $saved = true;
  80. }
  81. if (current_user_can('edit_user', $user_id)) {
  82. update_user_meta($user_id, 'facebook_p_link', $_POST['facebook_p_link']);
  83. $saved = true;
  84. }
  85. if (current_user_can('edit_user', $user_id)) {
  86. update_user_meta($user_id, 'twitter_p_link', $_POST['twitter_p_link']);
  87. $saved = true;
  88. }
  89. if (current_user_can('edit_user', $user_id)) {
  90. update_user_meta($user_id, 'linkedin_p_link', $_POST['linkedin_p_link']);
  91. $saved = true;
  92. }
  93. if (current_user_can('edit_user', $user_id)) {
  94. update_user_meta($user_id, 'pinterest_p_link', $_POST['pinterest_p_link']);
  95. $saved = true;
  96. }
  97. if (current_user_can('edit_user', $user_id)) {
  98. update_user_meta($user_id, 'gplus_p_link', $_POST['gplus_p_link']);
  99. $saved = true;
  100. }
  101. if (current_user_can('edit_user', $user_id)) {
  102. update_user_meta($user_id, 'vk_p_link', $_POST['vk_p_link']);
  103. $saved = true;
  104. }
  105. return true;
  106. }
  107.  
  108. //Display result in Front-end
  109. <div class="ic-author-info media">
  110. <?php echo get_avatar(get_the_author_meta()); ?>
  111. <div class="media-body">
  112. <h4><?php echo get_the_author(); ?></h4>
  113. <span><?php echo esc_attr(get_the_author_meta('designation', $user_ID)); ?></span>
  114. <p><?php echo get_the_author_meta('description'); ?></p>
  115. <div class="ic-social">
  116. <ul>
  117.  
  118. <?php if (!empty(get_the_author_meta('facebook_p_link', $user->ID))) : ?>
  119. <li>
  120. <a href="<?php echo esc_url(get_the_author_meta('facebook_p_link', $user->ID)); ?>">
  121. <i class="icofont icofont-social-facebook"></i>
  122. </a>
  123. </li>
  124. <?php endif; ?>
  125.  
  126. <?php if (!empty(get_the_author_meta('twitter_p_link', $user->ID))) : ?>
  127. <li>
  128. <a href="<?php echo esc_url(get_the_author_meta('twitter_p_link', $user->ID)); ?>">
  129. <i class="icofont icofont-social-facebook"></i>
  130. </a>
  131. </li>
  132. <?php endif; ?>
  133. <?php if (!empty(get_the_author_meta('linkedin_p_link', $user->ID))) : ?>
  134. <li>
  135. <a href="<?php echo esc_url(get_the_author_meta('linkedin_p_link', $user->ID)); ?>">
  136. <i class="icofont icofont-social-linkedin"></i>
  137. </a>
  138. </li>
  139. <?php endif; ?>
  140. <?php if (!empty(get_the_author_meta('pinterest_p_link', $user->ID))) : ?>
  141. <li>
  142. <a href="<?php echo esc_url(get_the_author_meta('pinterest_p_link', $user->ID)); ?>">
  143. <i class="icofont icofont-social-pinterest"></i>
  144. </a>
  145. </li>
  146. <?php endif; ?>
  147. <?php if (!empty(get_the_author_meta('gplus_p_link', $user->ID))) : ?>
  148. <li>
  149. <a href="<?php echo esc_url(get_the_author_meta('gplus_p_link', $user->ID)); ?>">
  150. <i class="icofont icofont-social-google-plus"></i>
  151. </a>
  152. </li>
  153. <?php endif; ?>
  154. <?php if (!empty(get_the_author_meta('vk_p_link', $user->ID))) : ?>
  155. <li>
  156. <a href="<?php echo esc_url(get_the_author_meta('vk_p_link', $user->ID)); ?>">
  157. <i class="icofont icofont-social-social-vk"></i>
  158. </a>
  159. </li>
  160. <?php endif; ?>
  161. </ul>
  162. </div>
  163. <div class="ic-navigation">
  164. <ul>
  165. <?php previous_post_link('<li class="float-left nav-prev">%link</li>', '<span><i class="icofont icofont-long-arrow-left"></i></span> Previous'); ?>
  166. <?php next_post_link('<li class="float-right nav-next">%link</li>', 'Next <span><i class="icofont icofont-long-arrow-right"></i></span>'); ?>
  167. </ul>
  168. </div>
  169. </div>
  170. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement