Advertisement
Guest User

Untitled

a guest
Aug 29th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.04 KB | None | 0 0
  1. ////adapted from: https://support.metabox.io/topic/mb_user_profile_register-autocompletenew-password/
  2. //relevant docs: https://docs.metabox.io/extensions/mb-user-profile/#form-fields-filters
  3. function add_more_registration_fields( $fields ) {
  4.         $fields = [
  5.             'username'  => [
  6.                 'name'     => __( 'Username', 'mb-user-profile' ),
  7.                 'id'       => 'user_login',
  8.                 'type'     => 'text',
  9.                 'required' => true,
  10.                 'columns' => 6,
  11.             ],
  12.             'email'     => [
  13.                 'name'     => __( 'Email', 'mb-user-profile' ),
  14.                 'id'       => 'user_email',
  15.                 'type'     => 'email',
  16.                 'required' => true,
  17.                 'columns' => 6,
  18.                 'desc' => 'Used for account notifications and alerts (if opted-in).',
  19.             ],
  20.             'password'  => [
  21.                 'name'     => __( 'Password', 'mb-user-profile' ),
  22.                 'id'       => 'user_pass',
  23.                 'type'     => 'password',
  24.                 'required' => true,
  25.                 'columns' => 6,
  26.                 'password_strength' => 'medium',
  27.                 'desc'     => 'Choose a password with a strength of <b>Medium</b> or higher. <br><span id="password-strength" class="rwmb-password-strength"></span>',
  28.                 'attributes' => [
  29.                     'autocomplete' => 'new-password'
  30.                 ]
  31.             ],
  32.             'password2' => [
  33.                 'name'     => __( 'Confirm Password', 'mb-user-profile' ),
  34.                 'id'       => 'user_pass2',
  35.                 'type'     => 'password',
  36.                 'required' => true,
  37.                 'password_strength' => 'medium',
  38.                 'columns' => 6,
  39.             ],
  40.             // ... add more fields here
  41.         ];
  42.         return $fields;
  43.     }
  44. add_filter( 'rwmb_profile_register_fields',  'add_more_registration_fields' );
  45. //add this to the edit profile too
  46.  
  47. ////https://docs.metabox.io/extensions/mb-user-profile/#edit-default-fields
  48. //These fields need to be added this way instead of in the function preceding this one.
  49. //See: https://support.metabox.io/topic/how-to-modify-deafult-fields-specifically-on-front-end-user-registration-form/#post-36704
  50. add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
  51.     $meta_boxes[] = [
  52.         'title'  => 'Default Fields',
  53.         'id'     => 'default-fields',
  54.         'type'   => 'user',
  55.         'fields' => [
  56.             [
  57.                 'id'   => 'first_name',
  58.                 'name' => 'First Name',
  59.                 'type' => 'text',
  60.                   'required' => true,
  61.                 'columns' => 4,
  62.             ],
  63.             [
  64.                 'id'   => 'last_name',
  65.                 'name' => 'Last Name',
  66.                 'type' => 'text',
  67.                   'required' => true,
  68.                 'columns' => 4,
  69.             ],
  70.             'phonenumber'  => [
  71.             'name'     => __( 'Phone Number', 'mb-user-profile' ),
  72.             'id'       => 'phonenumber',
  73.             'type'     => 'tel',
  74.             'required' => true,
  75.             'desc' => 'Used for notifications and alerts (if opted-in).',
  76.             'columns' => 4,
  77.             //'mask' => '(999) 999-9999'
  78.             ],
  79.           /*  [
  80.                 'id'   => 'display_name',
  81.                 'name' => 'Display Name',
  82.                 'type' => 'text',
  83.             ],
  84.             [
  85.                 'id'   => 'description',
  86.                 'name' => 'Biography',
  87.                 'type' => 'textarea',
  88.             ],*/
  89.         ],
  90.         'validation' => [
  91.             'rules'  => [
  92.                 'phonenumber' => [
  93.                     'phoneUS'  => true,
  94.                     //'minlength' => 7,
  95.                 ],
  96.                 // Rules for other fields
  97.             ],
  98.             'messages' => [
  99.                 'phonenumber' => [
  100.                     'phoneUS' => "Please enter a valid US phone number.
  101.                     <br><b>Examples:</b>
  102.                         <ul>
  103.                         <li>5555555555</li>
  104.                         <li>(555) 555-5555</li>
  105.                         <li>555-555-5555</li>
  106.                         </ul>"
  107.                 ],
  108.                 // Error messages for other fields
  109.             ],
  110.         ],
  111.     ];
  112.     return $meta_boxes;
  113. } );
  114.  
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement