• Resolved palopoliart7

    (@palopoliart7)


    Hello, I used a custom code to display user URL next to social icons on profile page. That works perfectly. Here is the code :

    add_filter("um_builtin_all_user_fields","um_092221_website_url_social");
    function um_092221_website_url_social( $fields ){
    
        foreach ( $fields as $field => $args ) {
            if ( isset( $field ) && $field == 'user_url' ) {
                $fields[ $field ]['advanced'] = 'social';
                $fields[ $field ]['icon'] = 'um-faicon-globe';
                $fields[ $field ]['match'] = 'https://';
                $fields[ $field ]['color'] = '#553198';            
            }
        }
    
        return $fields;
    }

    My problem is that I try to do the same with the user email with this code, but it creates a link adding automatically ‘https://’ before the value of the user email :

    add_filter("um_builtin_all_user_fields","um_092221_email_social");
    function um_092221_email_social( $fields ){
    
        foreach ( $fields as $field => $args ) {
            if ( isset( $field ) && $field == 'user_email' ) {
                $fields[ $field ]['advanced'] = 'social';
                $fields[ $field ]['icon'] = 'um-icon-android-mail';
                // $fields[ $field ]['match'] = 'https://';
                $fields[ $field ]['color'] = '#553198';            
            }
        }
    
        return $fields;
    }

    How to take away the ‘http://’ ? I guess it has to do with the ‘match’ key (that I commented on my second code), but could not figure out how to do that. Can you help ?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • @palopoliart7

    Have you tried with mailto:?

    • This reply was modified 2 years, 10 months ago by missveronica.
    Plugin Support Yurii

    (@yuriinalivaiko)

    Hello @palopoliart7

    Items in the Social URLs section are sanitized via the esc_url() function. This function prepends http:// if the URL appears to be an absolute link that does not contain a scheme. You should add a protocol mailto to convert email to valid URL.

    Try to use this code to display the user_email and user_url in the Social URLs section of the profile header.

    add_action( 'um_after_profile_header_name_args', 'um_custom_filter_social_urls_on', 49 );
    add_action( 'um_after_profile_header_name_args', 'um_custom_filter_social_urls_off', 51 );
    
    function um_custom_filter_social_urls_on() {
    	add_filter( 'um_builtin_all_user_fields', 'um_custom_website_url_social' );
    	add_filter( 'um_profile_user_email__filter', 'um_custom_user_email_to_link' );
    }
    
    function um_custom_filter_social_urls_off() {
    	remove_filter( 'um_builtin_all_user_fields', 'um_custom_website_url_social' );
    	remove_filter( 'um_profile_user_email__filter', 'um_custom_user_email_to_link' );
    }
    
    function um_custom_website_url_social( $fields ) {
    
    	foreach ( $fields as $field => &$args ) {
    		if ( 'user_url' === $field ) {
    			$args['advanced'] = 'social';
    			$args['icon']     = 'um-faicon-globe';
    			$args['match']    = 'https://';
    			$args['color']    = '#444';
    		}
    		if ( 'user_email' === $field ) {
    			$args['advanced'] = 'social';
    			$args['icon']     = 'um-icon-android-mail';
    			$args['match']    = null;
    			$args['color']    = '#444';
    		}
    	}
    
    	return $fields;
    }
    
    function um_custom_user_email_to_link( $value ) {
    	return 'mailto:' . $value;
    }

    Regards

    Thread Starter palopoliart7

    (@palopoliart7)

    Thank you! I went for another solution for now, to display the email under the user Title as plain text and that works for what I want.

    Did not try your solution but my guess is that it would work!

    Plugin Support Yurii

    (@yuriinalivaiko)

    Hi palopoliart7

    Thank you for letting us know that you went for another solution so we’re going to go ahead and mark this thread Resolved.

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

    Regards

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Add email in Profile Connect section’ is closed to new replies.