Advertisement
MrPauloeN

Save extra user fields profile WordPress

Nov 22nd, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. # Save extra user fields profile
  2.  
  3. function czystespalanie__save_extra_user_profile_fields( $user_id ) {
  4.     if ( !current_user_can( 'edit_user', $user_id ) ) {
  5.         return false;
  6.     }
  7.     if ( ! empty( $_POST['address'] ))      update_user_meta( $user_id, 'address',      sanitize_text_field( $_POST['address']      ));
  8.     if ( ! empty( $_POST['city'] ))         update_user_meta( $user_id, 'city',         sanitize_text_field( $_POST['city']         ));
  9.     if ( ! empty( $_POST['postalcode'] ))   update_user_meta( $user_id, 'postalcode',   sanitize_text_field( $_POST['postalcode']   ));
  10.     if ( ! empty( $_POST['tel'] ) && preg_match( '/^[0-9 +-]*$/', $_POST['tel'] ))
  11.                                             update_user_meta( $user_id, 'tel',          sanitize_text_field( $_POST['tel']          ));
  12. }
  13. add_action( 'personal_options_update', 'czystespalanie__save_extra_user_profile_fields' );
  14. add_action( 'edit_user_profile_update', 'czystespalanie__save_extra_user_profile_fields' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement