Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. // This function shows the form fiend on registration page
  2. add_action('register_form','show_first_name_field');
  3.  
  4. // This is a check to see if you want to make a field required
  5. add_action('register_post','check_fields',10,3);
  6.  
  7. // This inserts the data
  8. add_action('user_register', 'register_extra_fields');
  9.  
  10. // This is the forms The Two forms that will be added to the wp register page
  11. function show_first_name_field(){
  12. ?>
  13.  
  14. <p>
  15. <label>Vorname<br />
  16. <input id="user_email" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST['first']; ?>" name="first"/>
  17. </label>
  18. </p>
  19.  
  20. <p>
  21. <label>Nachname<br />
  22. <input id="user_email" class="input" type="text" tabindex="20" size="25" value="<?php echo $_POST['last']; ?>" name="last"/>
  23. </label>
  24. </p>
  25.  
  26. <p>
  27. <label>Hochschule<br />
  28. <select name="hochschule" id="hochschule" class="input">
  29. <option value="Uni Augsburg" <?php selected( 'Uni Augsburg', get_the_author_meta( 'hochschule', $user->ID ) ); ?>>Uni Augsburg</option>
  30. <option value="Hochschule Augsburg" <?php selected( 'Hochschule Augsburg', get_the_author_meta( 'hochschule', $user->ID ) ); ?>>Hochschule Augsburg</option>
  31. </select>
  32. </label>
  33. </p>
  34.  
  35. <p>
  36. <label>Studiengang<br />
  37. <input type="text" class="input" name="studiengang" id="studiengang" value="<?php echo esc_attr( get_the_author_meta( 'studiengang', $user->ID ) ); ?>" class="regular-text" />
  38. </label>
  39. </p>
  40.  
  41. <p>
  42. <label>Geschlecht<br />
  43. <select name="geschlecht" id="geschlecht" class="input">
  44. <option value="männlich" <?php selected( 'männlich', get_the_author_meta( 'geschlecht', $user->ID ) ); ?>>männlich</option>
  45. <option value="weiblich" <?php selected( 'weiblich', get_the_author_meta( 'geschlecht', $user->ID ) ); ?>>weiblich</option>
  46. </label>
  47. </p>
  48.  
  49. <?php
  50. }
  51.  
  52. // This function checks to see if they didn't enter them
  53. // If no first name or last name display Error
  54. function check_fields($login, $email, $errors) {
  55. global $firstname, $lastname;
  56. if ($_POST['first'] == '') {
  57. $errors->add('empty_realname', "<strong>Fehler</strong>: Bitte gib deinen Vornamen ein.");
  58. } else {
  59. $firstname = $_POST['first'];
  60. }
  61. if ($_POST['last'] == '') {
  62. $errors->add('empty_realname', "<strong>Fehler</strong>: Bitte gib deinen Nachnamen ein.");
  63. } else {
  64. $firstname = $_POST['last'];
  65. }
  66. global $hochschule;
  67. if ( $_POST['hochschule'] == '' ) {
  68. $errors->add( 'empty_realname', "<strong>Fehler</strong>: Bitte gib deine Hochschule an." );
  69. } else {
  70. $hochschule = $_POST['hochschule'];
  71. }
  72. global $studiengang;
  73. if ( $_POST['studiengang'] == '' ) {
  74. $errors->add( 'empty_realname', "<strong>Fehler</strong>: Bitte gib deinen Studiengang ein." );
  75. } else {
  76. $studiengang = $_POST['studiengang'];
  77. }
  78. global $geschlecht;
  79. if ( $_POST['geschlecht'] == '' ) {
  80. $errors->add( 'empty_realname', "<strong>Fehler</strong>: Bitte gib dein Geschlecht an." );
  81. } else {
  82. $geschlecht = $_POST['geschlecht'];
  83. }
  84.  
  85. }
  86.  
  87. // This is where the magiv happens
  88. function register_extra_fields($user_id, $password="", $meta=array()) {
  89.  
  90. // Gotta put all the info into an array
  91. $userdata = array();
  92. $userdata['ID'] = $user_id;
  93.  
  94. // First name
  95. $userdata['first_name'] = $_POST['first'];
  96.  
  97. // Last Name
  98. $userdata['last_name'] = $_POST['last'];
  99.  
  100. // Enters into DB
  101. wp_update_user($userdata);
  102. update_usermeta( $user_id, ‘geschlecht’, $_POST['geschlecht'] );
  103. update_usermeta( $user_id, ‘hochschule’, $_POST['hochschule'] );
  104. update_usermeta( $user_id, ‘studiengang’, $_POST['studiengang'] );
  105.  
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement