• Resolved norbertk

    (@norbertk)


    I have created a custom field, named mobile_number, with the following configuration:

    This field is under the Default Registration and Default Profile forms. On the registration form, it appears correctly:

    However, when I try to add it to the user’s account form, it loses the placeholder, help text and icon.

    add_action( 'um_after_account_general', 'um_custom_lph_fields', 100 );
    
    function um_custom_lph_fields() {
    	$id = um_user('ID');
    
    	$output = '<div class="um-field">';
    
    	// Array of meta-keys
    	$names = array( 'mobile_number' );
    
    	$fields = array();
    
    	foreach( $names as $name ) {
    		$fields[ $name ] = UM()->builtin()->get_specific_field( $name );
    	}
    
    	$fields = apply_filters( 'um_account_secure_fields', $fields, $id );
    
    	foreach( $fields as $key => $data ) {
    		$output .= UM()->fields()->edit_field( $key, $data );
    	}
    
    	$output .= '</div>';
    
    	echo $output;
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support andrewshu

    (@andrewshu)

    Hello @norbertk

    You could add this code:

    function my_form_edit_mobile_number( $output, $mode ) {
    	if ( 'account' === $mode ) {
    		$additionalCode = '<span class="um-tip um-tip-e" title="YOUR TEXT">
    				<i class="um-icon-help-circled"></i>
    			</span>
    			<div class="um-clear"></div>';
    		$position   = strpos( $output, '</label>' );
    
    		if ( $position !== false ) {
    			$output = substr_replace( $output, $additionalCode, $position + strlen( '</label>' ), 0 );
    		}
    		$output = str_replace( 'placeholder=""', 'placeholder="YOUR PLACEHOLDER"', $output );
    	}
    	return $output;
    }
    add_filter( 'um_mobile_number_form_edit_field', 'my_form_edit_mobile_number', 10, 2 );

    Regards.

    Thread Starter norbertk

    (@norbertk)

    Thanks for that. Will I have to do this for every custom field that I add to the account page? There’s no way to fetch the actual field data instead of hard coding the tool-tips or placeholders?

    Plugin Support andrewshu

    (@andrewshu)

    Hello @norbertk

    You need to add this code for each field and change name of hook:

    add_filter( 'um_YOUR-FIELD-KEY_form_edit_field', 'my_form_edit_mobile_number', 10, 2 );

    Regards.

    Thread Starter norbertk

    (@norbertk)

    @andrewshu Is there a way to get the icon to display (not the help one)?

    Plugin Support andrewshu

    (@andrewshu)

    Hello @norbertk

    Where do you wand to add the icon?

    Regards.

    Plugin Support andrewshu

    (@andrewshu)

    Hi @norbertk

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding custom fields to profile’ is closed to new replies.