• I am close to executing what i need, but I think I am using the wrong hook and cannot locate the proper one.

    My goal it relatively simple to change the output of a custom meta field from simple text to an unordered list. Right now, the text field is displaying it’s content as a group of words separated by commas. I’ve been able to write the code to convert each item to a bulleted list. But, when it shows up on the profile page it is not in the correct location.

    Here are two images. The first shows the current state, where Areas of Expertise has a list of items separated by commas and is positioned in the second column after Member Type. The second image shows the same page with a code snippet applied. The Areas of Expertise now are bulleted, but come above all the other data.Profile Page - comma separated itemsProfile Page - bulleted items

    Here is the code I’m using:

    add_filter(‘um_profile_field_filter_hook__DIR_AREAS_OF_EXPERTISE’, ‘um_profile_field_filter_hook__DIR_AREAS_OF_EXPERTISE’);
    function um_profile_field_filter_hook__DIR_AREAS_OF_EXPERTISE() {
    if (um_user(‘DIR_AREAS_OF_EXPERTISE’) != ”) {echo ‘<div class=”um-field um-field-DIR_AREAS_OF_EXPERTISE um-field-multiselect” data-key=”DIR_AREAS_OF_EXPERTISE”><div class=”um-field-label”><label for=”DIR_AREAS_OF_EXPERTISE-637″>Areas of Expertise</label><div class=”um-clear”></div></div><div class=”um-field-area”><div class=”um-field-value”>

    • ‘ . str_replace(“,”,”
    • “,um_user(‘DIR_AREAS_OF_EXPERTISE’)) . ‘

    </div></div></div>’;}
    }

    Here is link to the profile page:
    https://nschbc.uycc.com/user/thomas-ackerson/
    Also, the Areas of Expertise show on the profile cards. Here’s a link to a sample search result.
    https://nschbc.uycc.com/find-a-consultant/?DIR_AREAS_OF_EXPERTISE=Accounting&um_search=1

    Should I be using a different hook, other than um_profile_field_filter_hook__DIR_AREAS_OF_EXPERTISE, so that it displays after Member Type? Or should I be going at this in a different way?

    Thanks, in advance, for any help you can offer.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter uycc

    (@uycc)

    It looks like my code is not displaying right in the previous message.
    Here is is again:

    add_filter('um_profile_field_filter_hook__DIR_AREAS_OF_EXPERTISE', 'um_profile_field_filter_hook__DIR_AREAS_OF_EXPERTISE');
    function um_profile_field_filter_hook__DIR_AREAS_OF_EXPERTISE() {
    	if (um_user('DIR_AREAS_OF_EXPERTISE') != '') {echo '<div class="um-field um-field-DIR_AREAS_OF_EXPERTISE um-field-multiselect" data-key="DIR_AREAS_OF_EXPERTISE"><div class="um-field-label"><label for="DIR_AREAS_OF_EXPERTISE-637">Areas of Expertise</label><div class="um-clear"></div></div><div class="um-field-area"><div class="um-field-value"><ul><li>' . str_replace(",","</li><li>",um_user('DIR_AREAS_OF_EXPERTISE')) . '</li></ul></div></div></div>';}
    }
    Thread Starter uycc

    (@uycc)

    I couldn’t find the right hook for placement of the previous code. So, I went into um-fields.php and added an if/else. This way everytime the key was set to DIR_AREAS_OF_EXPERTISE the output was made to use a bulleted list

    		switch( $type ) {
    
    			/* Default */
    			default:
    
    				$output .= '<div class="um-field' . $classes . '"' . $conditional . ' data-key="'.$key.'">';
    
    						if ( isset( $data['label'] ) ) {
    							$output .= $this->field_label($label, $key, $data);
    						}
    						
    						$res = $this->field_value( $key, $default, $data );
    						$expertisekey = $key;
    						if( ! empty( $res ) ){
    							$res = stripslashes( $res );
    						}
    if ($expertisekey == 'DIR_AREAS_OF_EXPERTISE') {
        
    						$data['is_view_field'] = true;
    						$res = apply_filters("um_view_field", $res, $data, $type );
    						$res = apply_filters("um_view_field_value_{$type}", $res, $data );
    						$res = '<ul><li>' . str_replace(",","</li><li>",$res) . '</li></ul>';
    
    						$output .= '<div class="um-field-area">';
    						$output .= '<div class="um-field-value">' . $res . '</div>';
    						$output .= '</div>';
    
    						$output .= '</div>';
    } else {
        
    						$data['is_view_field'] = true;
    						$res = apply_filters("um_view_field", $res, $data, $type );
    						$res = apply_filters("um_view_field_value_{$type}", $res, $data );
    
    						$output .= '<div class="um-field-area">';
    						$output .= '<div class="um-field-value">' . $res . '</div>';
    						$output .= '</div>';
    
    						$output .= '</div>';
    } 
    
    				break;

    Not as elegant a solution as I would have liked. And, whenever there’s an upadate to the Ultimate Member plugin, I have to check to make sure it’s still working properly. But, it gets the job done.

    I would appreciate the help if anyone has a better/cleaner solution

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hi @uycc,

    We can only provide guides that are related to UM as the customization is beyond our free support. However, you may ask this on our github repo so our lead developers can check it and give you guides:

    https://github.com/ultimatemember/ultimatemember/issues

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Find the right hook’ is closed to new replies.