• Folks-

    Admittedly, I am trying to swim in a deeper part of the pool than I have ever played in… I’m hoping you can help.

    I have been customizing the profile page for a site I’m building. So far, I have been able to achieve everything I need with CSS I’m pretty comfortable with that). There is one part, however, I need to change the structure of the content–the HTML.

    This is the part I need to change:

    <div class="um-meta">
    	<span>XXXXXXXXX</span>
    	<span class="b">•</span>
    	<span>XXXXXXXXX</span>
    	<span class="b">•</span>
    	<span><a href="mailto:XXXXXXXXX" title="XXXXXXXXX">XXXXXXXXX</a></span>
    	<span class="b">•</span>
    	<span>XXXXXXXXX</span>
    </div>

    So, looking at the profile.php template, I see that I need to use the do_action( ‘um_profile_header’, $args ); hook to substitute my modified code. I think I understand how to do that.

    I also found the default callback function, um_profile_header. Looking at that, I found the part that I need to change:

    <?php if ( ! empty( $args['metafields'] ) ) { ?>
    	<div class="um-meta">
    		<?php echo UM()->profile()->show_meta( $args['metafields'] ); ?>
    	</div>
    <?php }

    I have never seen that particular syntax before, so I’m not sure, but I think its calling a function. I cannot seem to find where a show_meta() function is defined to see what it is doing by default.

    Then, can I replace that function by using the same delete_action, add_action process that is used with hooks?

    Any guidance you can provide is greatly appreciated.

    –don

Viewing 10 replies - 1 through 10 (of 10 total)
  • @theotherdon

    ../plugins/ultimate-member/includes/core/class-profile.php
    409 function show_meta( $array ) {

    Thread Starter theotherdon

    (@theotherdon)

    @missveronicatv — thanks for that! I have found the function, and I’m pretty sure I understand what its doing. Now, what’s the proper way to replace it?

    Obviously, not by editing the core file! Do I copy class-profile.php into my theme file and edit it there? Do I use delete_action, add_action in my functions file? Or is there some other way?

    @theotherdon

    <?php echo UM()->profile()->show_meta( $args['metafields'] ); ?>

    This is the only place in UM where your function is called.
    You can copy the function show_meta code
    and replace the name with function show_meta_custom
    and add the function code to your active theme’s functions.php file
    where you make your customizations.

    <?php echo show_meta_custom( $args['metafields'] ); ?>

    • This reply was modified 3 years, 1 month ago by missveronica.
    Plugin Support andrewshu

    (@andrewshu)

    Hi @theotherdon

    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

    Thread Starter theotherdon

    (@theotherdon)

    @missveronicatv

    It worked!

    Thank you for all of your help!

    • This reply was modified 3 years, 1 month ago by theotherdon.
    Thread Starter theotherdon

    (@theotherdon)

    @missveronicatv –

    Another week, another challenge!

    So, in my customized show_meta function, I was able to use:

    $items[] = apply_filters( 'um_show_meta_item_html', '<p class="' . $key . '">' . $value . '</p>', $key );

    instead of the original spans & bullets. This works just as I want, except…

    In my custom profile form, I have added a field called “Supervisor. This field is a drop-down whose options are populated by a callback script that lists every user who has the UM role of “supervisor.” (This is the first thing you helped me with, and it works fine.

    So, if the user whose profile I am displaying has a supervisor (most of them do) then I want to go get some additional user data about the supervisor and display it.

    Here’s where I’m at… I have added the following code :

    $testvar = 'No work';
    if ($key === 'Supervisor') {
    	$theSupervisor = get_user_by('display_name', $value);
    	if ( ! empty( $theSupervisor ) ) {
    		$testvar = 'it works';
    	}
    
    	$value = $value . ', ' . $testvar;
    }
    
    $items[] = apply_filters( 'um_show_meta_item_html', '<p class="' . $key . '">' . $value . '</p>', $key );

    This displays $testvar as “No work.” The user object is not getting got.

    I know the value of the “Supervisor” key is the display_name of a user (It has to be, because that’s what the script supplies to the field. Yet, $theSupervisor is empty.

    Could it be that $value is NOT a string at this point? Its also possible that I bolloxed the syntax–but I don’t think so. Any ideas?

    Thanks, as always.

    –don

    • This reply was modified 3 years, 1 month ago by theotherdon.
    • This reply was modified 3 years, 1 month ago by theotherdon.
    • This reply was modified 3 years, 1 month ago by theotherdon.

    @theotherdon

    You can’t use display_name

    $field string Required
    The field to retrieve the user with. id | ID | slug | email | login.

    https://developer.ww.wp.xz.cn/reference/functions/get_user_by/

    Thread Starter theotherdon

    (@theotherdon)

    Well… carp!

    I guess I’ll have to figure out some way to store the user ID or email.

    @theotherdon

    In your dropdown use ID as index and display_name as value,

    Thread Starter theotherdon

    (@theotherdon)

    @missveronicatv

    That would have been good too! Before I saw your suggestion, i figured out a solution (probably not as efficient, but this site will always have a membership of <50 users). Using what you helped me with to build the dropdown, I wrote a new function:

    function get_supervisor_login($sup_name) {
       $args = array(
    	'role' => 'um_supervisor',
    	'orderby' => 'user_nicename',
    	'order' => 'ASC'
       );
       $users = get_users( $args );
       foreach( $users as $user ) {
         if($user->display_name == $sup_name){
    	$login_name = $user->user_login;
         }
       }
       return $login_name;
    }

    This gets me the login (which was one of the pieces of data I needed anyway, and from that I can use get_user_by() to get the rest.

    Thanks for your continued help!

    –don

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

The topic ‘Modifying profile meta HTML’ is closed to new replies.