Advertisement
RhondaRa

Extra user fields plugin

Dec 20th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Extra user profile fields
  4. Plugin URI: http://gcps.org.au
  5. description: >-
  6. a plugin to Edit a Users Profile
  7. Version: 1.0
  8. Author: Rhonda Ramadge
  9. Author URI: http://rhondaramadge.com
  10. License: GPL2
  11. */
  12. //add_action( 'show_user_profile', 'extra_user_profile_fields' );
  13. add_action( 'edit_user_profile', 'extra_user_profile_fields' );
  14.  
  15. function extra_user_profile_fields( $user ) { ?>
  16. <h3><?php _e("Extra profile information", "blank"); ?></h3>
  17.  
  18. <table class="form-table">
  19. <tr>
  20. <th><label for="pin"><?php _e("Pin"); ?></label></th>
  21. <td>
  22. <input type="text" name="pin" id="pin" value="<?php echo esc_attr( get_the_author_meta( 'pin', $user->ID ) ); ?>" class="regular-text" /><br />
  23. <span class="description"><?php _e("Pin Number."); ?></span>
  24. </td>
  25. </tr>
  26. <tr>
  27. <th><label for="street-address"><?php _e("Street-Address"); ?></label></th>
  28. <td>
  29. <input type="text" name="street-address" id="street-address" value="<?php echo esc_attr( get_the_author_meta( 'street-address', $user->ID ) ); ?>" class="regular-text" /><br />
  30. <span class="description"><?php _e("Street address."); ?></span>
  31. </td>
  32. </tr>
  33. <tr>
  34. <th><label for="suburb"><?php _e("Suburb"); ?></label></th>
  35. <td>
  36. <input type="text" name="suburb" id="suburb" value="<?php echo esc_attr( get_the_author_meta( 'suburb', $user->ID ) ); ?>" class="regular-text" /><br />
  37. <span class="description"><?php _e("Suburb."); ?></span>
  38. </td>
  39. </tr>
  40. <tr>
  41. <th><label for="postcode"><?php _e("Postcode"); ?></label></th>
  42. <td>
  43. <input type="text" name="postcode" id="postcode" value="<?php echo esc_attr( get_the_author_meta( 'postcode', $user->ID ) ); ?>" class="regular-text" /><br />
  44. <span class="description"><?php _e("Postcode."); ?></span>
  45. </td>
  46. </tr>
  47. <tr>
  48. <th><label for="phone"><?php _e("Phone"); ?></label></th>
  49. <td>
  50. <input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" /><br />
  51. <span class="description"><?php _e("Phone Number."); ?></span>
  52. </td>
  53. </tr>
  54. <tr>
  55. <th><label for="mobile"><?php _e("Mobile"); ?></label></th>
  56. <td>
  57. <input type="text" name="mobile" id="mobile" value="<?php echo esc_attr( get_the_author_meta( 'mobile', $user->ID ) ); ?>" class="regular-text" /><br />
  58. <span class="description"><?php _e("Mobile number."); ?></span>
  59. </td>
  60. </tr>
  61. <tr>
  62. <th><label for="president-year"><?php _e("President-year"); ?></label></th>
  63. <td>
  64. <input type="text" name="president-year" id="president-year" value="<?php echo esc_attr( get_the_author_meta( 'president-year', $user->ID ) ); ?>" class="regular-text" /><br />
  65. <span class="description"><?php _e("President Year."); ?></span>
  66. </td>
  67. </tr>
  68.  
  69. <tr>
  70. <th><label for="secretary-year"><?php _e("Secretary-year"); ?></label></th>
  71. <td>
  72. <input type="text" name="secretary-year" id="secretary-year" value="<?php echo esc_attr( get_the_author_meta( 'secretary-year', $user->ID ) ); ?>" class="regular-text" /><br />
  73. <span class="description"><?php _e("Secretary Year."); ?></span>
  74. </td>
  75. </tr>
  76.  
  77. <tr>
  78. <th><label for="competition-secretary-year"><?php _e("Competition-secretary-year"); ?></label></th>
  79. <td>
  80. <input type="text" name="competition-secretary-year" id="competition-secretary-year" value="<?php echo esc_attr( get_the_author_meta( 'competition-secretary-year', $user->ID ) ); ?>" class="regular-text" /><br />
  81. <span class="description"><?php _e("Competition Secretary Year."); ?></span>
  82. </td>
  83. </tr>
  84.  
  85. <tr>
  86. <th><label for="treasurer-year"><?php _e("Treasurer-year"); ?></label></th>
  87. <td>
  88. <input type="text" name="treasurer-year" id="treasurer-year" value="<?php echo esc_attr( get_the_author_meta( 'treasurer-year', $user->ID ) ); ?>" class="regular-text" /><br />
  89. <span class="description"><?php _e("Treasurer Year."); ?></span>
  90. </td>
  91. </tr>
  92.  
  93. <tr>
  94. <th><label for="committee-member-year"><?php _e("Committee-member-year"); ?></label></th>
  95. <td>
  96. <input type="text" name="committee-member-year" id="committee-member-year" value="<?php echo esc_attr( get_the_author_meta( 'committee-member-year', $user->ID ) ); ?>" class="regular-text" /><br />
  97. <span class="description"><?php _e("Committee Member Year."); ?></span>
  98. </td>
  99. </tr>
  100. <tr>
  101. <th><label for="other-roles"><?php _e("Other-Roles"); ?></label></th>
  102. <td>
  103. <textarea type="text" name="other-roles" id="other-roles" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'other-roles', $user->ID ) ); ?></textarea><br />
  104. <span class="description"><?php _e("Other Roles."); ?></span>
  105. </td>
  106. </tr>
  107. <tr>
  108. <th><label for="joining-date"><?php _e("Joining-date"); ?></label></th>
  109. <td>
  110. <input type="text" name="joining-date" id="joining-date" value="<?php echo esc_attr( get_the_author_meta( 'joining-date', $user->ID ) ); ?>" class="regular-text" /><br />
  111. <span class="description"><?php _e("Joining Date Must be entered as yearmonthday (no spaces,/ or.) e.g. 29/6/2018 entered as 20180629"); ?></span>
  112. </td>
  113. </tr>
  114. <tr>
  115. <th><label for="year-left"><?php _e("Year left"); ?></label></th>
  116. <td>
  117. <input type="text" name="year-left" id="year-left" value="<?php echo esc_attr( get_the_author_meta( 'year-left', $user->ID ) ); ?>" class="regular-text" /><br />
  118. <span class="description"><?php _e("Year Left"); ?></span>
  119. </td>
  120. </tr>
  121. <tr>
  122. <th><label FOR="fees-paid">Are Fees Paid</label></th>
  123. <td>
  124. <?php $status = get_the_author_meta( 'fees-paid', $user->ID ); ?>
  125. <input TYPE="radio" name="fees-paid" value="yes" <?php checked( $status, 'yes' ); ?> /> Yes<br />
  126. <input TYPE="radio" name="fees-paid" value="no" <?php checked( $status, 'no' ); ?> /> No<br />
  127. <span CLASS="description">Have fees been paid.</span>
  128. </td>
  129. </tr>
  130. <tr>
  131. <th><label for="life-member"><?php _e("Life Member"); ?></label></th>
  132. <td>
  133. <input type="checkbox" name="life-member" id=" life-member " value="yes" <?php if (esc_attr( get_the_author_meta( "life-member", $user->ID )) == "yes") echo "checked"; ?> /><label for="life-member "><?php _e("Life Member"); ?></label><br />
  134.  
  135.  
  136. </td>
  137. </tr>
  138.  
  139. <tr>
  140. <th><label for="comments"><?php _e("Comments"); ?></label></th>
  141. <td>
  142. <textarea type="text" name="comments" id="comments" class="regular-text"><?php echo esc_attr( get_the_author_meta( 'comments', $user->ID ) ); ?></textarea><br />
  143.  
  144. <span class="description"><?php _e("Comments."); ?></span>
  145. </td>
  146. </tr>
  147.  
  148.  
  149. </table>
  150. <?php }
  151.  
  152. add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
  153. add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
  154.  
  155. function save_extra_user_profile_fields( $user_id ) {
  156. if ( !current_user_can( 'edit_user', $user_id ) ) {
  157. return false;
  158. }
  159. update_user_meta( $user_id, 'pin', $_POST['pin'] );
  160. update_user_meta( $user_id, 'street-address', $_POST['street-address'] );
  161. update_user_meta( $user_id, 'suburb', $_POST['suburb'] );
  162. update_user_meta( $user_id, 'postcode', $_POST['postcode'] );
  163. update_user_meta( $user_id, 'phone', $_POST['phone'] );
  164. update_user_meta( $user_id, 'mobile', $_POST['mobile'] );
  165. update_user_meta( $user_id, 'president-year', $_POST['president-year'] );
  166. update_user_meta( $user_id, 'secretary-year', $_POST['secretary-year'] );
  167. update_user_meta( $user_id, 'competition-secretary-year', $_POST['competition-secretary-year'] );
  168. update_user_meta( $user_id, 'treasurer-year', $_POST['treasurer-year'] );
  169. update_user_meta( $user_id, 'committee-member-year', $_POST['committee-member-year'] );
  170. update_user_meta( $user_id, 'joining-date', $_POST['joining-date'] );
  171. update_user_meta( $user_id, 'fees-paid', $_POST['fees-paid'] );
  172. update_user_meta( $user_id, 'life-member', $_POST['life-member'] );
  173. update_user_meta( $user_id, 'comments', $_POST['comments'] );
  174. update_user_meta( $user_id, 'other-roles', $_POST['other-roles'] );
  175. update_user_meta( $user_id, 'year-left', $_POST['year-left'] );
  176.  
  177.  
  178. }
  179.  
  180. /**
  181. * Change inline eit for a specific custom field to a prefilled drop down
  182. *
  183. * @param $data array
  184. * @param $column AC\Column
  185. *
  186. * @return mixed
  187. */
  188. function my_acp_custom_field_editing_selectbox( $data, $column ) {
  189.  
  190. if ( $column instanceof ACP\Column\CustomField ) {
  191.  
  192. if ( 'fees-paid' === $column->get_meta_key() ) {
  193. $data['type'] = 'select';
  194. $data['options'] = array(
  195. 'yes' => 'Yes',
  196. 'no' => 'No',
  197.  
  198. );
  199. }
  200.  
  201. }
  202.  
  203. return $data;
  204. }
  205. add_filter( 'acp/editing/view_settings', 'my_acp_custom_field_editing_selectbox', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement