Advertisement
vapvarun

Add new user meta fields for learndash dashboard profile

May 31st, 2022
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. add_filter( 'ld_dashboard_user_profile_fields', 'add_custom_profile_fields' );
  2.  
  3. // Add custom field in the profile settings form.
  4. function add_custom_profile_fields($profile_fields) {
  5.     $profile_fields['user_url']        = array(
  6.                 'title' => esc_html__( 'Custom Field', 'ld-dashboard' ),
  7.                 'tag'   => 'input',
  8.                 'type'  => 'text',
  9.                 'name'  => 'custom_field',
  10.                 'value' => get_user_meta( $current_user->ID, 'custom_field', true ),
  11.                 'class' => 'form-url',
  12.             )
  13.     return $profile_fields;
  14. }
  15.  
  16. add_action( 'ld_dashboard_save_user_profile_fields', 'update_custom_meta_field' );
  17.  
  18. // Save custom field data.
  19. function update_custom_meta_field() {
  20.     if ( isset( $_POST['custom_field'] ) && '' != $_POST['custom_field'] ) {
  21.             update_user_meta( $current_user->ID, 'custom_field', sanitize_text_field( wp_unslash( $_POST['custom_field'] ) ) );
  22.     } else {
  23.         update_user_meta( $current_user->ID, 'custom_field', '' );
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement