Hello @ochime
Sorry, can’t understand. I check your code on my site and I see the correct HTML. What do you mean about “the button div rendered as text”?
Regards.
Thread Starter
ochime
(@ochime)
Sorry for the unclear information.
My idea is to display information:
- Nickname -> Displayed successfully
- Add a button; when clicked, a pop-up modal will appear -> Displayed successfully but cannot be clicked.
Upon inspecting the element, the <button>Test – Click Here</button> element is rendered as plain text instead of a <button> element.”
@ochime
You can try to add class="button" to show a button.
Thread Starter
ochime
(@ochime)
@missveronicatv
<button class”button”>Test</button>
I’ve done your suggestions, but it doesn’t solve the problem
When i inspect element, output only “Test” without element <button>
Thread Starter
ochime
(@ochime)
@missveronicatv @andrewshu
add_action("um_members_list_after_user_name_tmpl","um_122021_display_view_profile");
add_action('um_members_just_after_name_tmpl','um_122021_display_view_profile',100 );
function um_122021_display_view_profile( $args ){
?>
<div class="um-members-edit-btn">
<a href="{{user.profile_url}}" >
<?php _e( 'View profile','ultimate-member' ) ?>
</a>
<button>Test</button>
</div>
<?php
}
Using the above hook and adding a button, the result is rendered as a button element
@ochime
Add the class to your a tag.
<a href="..." title="..." class="button">Click here</a>
Thread Starter
ochime
(@ochime)
@missveronicatv
Yes, I’ve applied the method and here’s my updated function
add_action('um_members_after_user_name', 'my_members_after_user_name', 10, 2);
function my_members_after_user_name($user_id, $args) {
$nickname = um_user('nickname');
$role_map = [
'subscriber' => 'Guest',
'um_owner' => 'Owner',
'customer' => 'Customer',
];
// Role function mapping
$function_map = [
'subscriber' => 'subscriber33',
'um_owner' => 'owner33',
'customer' => 'customer33',
];
$displayed_role = isset($role_map[$user_role]) ? $role_map[$user_role] : 'User';
// Default function if role not found
$content_function = isset($function_map[$user_role]) ? $function_map[$user_role] : null;
$current_user = wp_get_current_user();
?>
<div id="wrapperModal-<?php echo esc_attr($user_id); ?>" class="wrapper-modal">
<div class="custom-member-info">
<div><?php echo esc_html($displayed_role); ?></div>
<div class="button-wrapper">
<a href="#" id="info-popup-link-<?php echo esc_attr($user_id); ?>" class="info-popup-link">More Info</a>
</div>
</div>
<!-- Modal -->
<div id="modalUserDetails-<?php echo esc_attr($user_id); ?>" class="custom-modal" style="display: none;">
<div class="modal-content">
<span id="closeModalDetails-<?php echo esc_attr($user_id); ?>" class="close-modal">×</span>
<h2>User Details</h2>
<?php
if ($content_function && function_exists($content_function)) {
// Call function based on user role
echo call_user_func($content_function, $user_id);
} else {
echo "<p>User role not recognized.</p>";
}
?>
</div>
</div>
</div>
<?php
}
function owner33($user_id) {
um_fetch_user($user_id); // Set user context based on user_id
$nickname = um_user('nickname');
$city_district = um_user('city');
$phone_number = um_user('mobile_number');
if (!$nickname) {
$nickname = "Name not available";
}
if (!$city_district) {
$city_district = "Residence not available";
}
if (!$phone_number) {
$phone_number = "Phone number not available";
}
// Create HTML with table and button
$content = "
<table class='owner-info-table'>
<tr>
<td>Name</td>
<td>$nickname</td>
</tr>
<tr>
<td>Phone Number</td>
<td>$phone_number</td>
</tr>
<tr>
<td>Residence</td>
<td>$city_district</td>
</tr>
</table>
<button class='custom-button'>Click Me</button>
";
// Debug: log content before wp_kses_post
error_log('Content before wp_kses_post: ' . $content);
// Sanitize HTML to allow specific elements with wp_kses_post
$content = wp_kses_post($content);
// Debug: log content after wp_kses_post
error_log('Content after wp_kses_post: ' . $content);
um_reset_user(); // Reset user context
return $content; // Return sanitized content
}
Even using wp_kses_post, the output is still rendered as plain text.
Are there any suggestions on how to resolve this?
Thanks
Thread Starter
ochime
(@ochime)
@missveronicatv
Thank you for your response.
I will study the link you provided.
I found a solution for <a> to have class=”button”.
However, I still don’t understand about the tr and td tags, since the output is still rendered as text
Thread Starter
ochime
(@ochime)
@missveronicatv
Because all HTML output remains rendered as plain text, even when using direct echo within the hook, I suspect the issue stems from the sanitization or escaping process applied by Ultimate Member during rendering.
Is there another way?
I tried:
add_action('um_members_after_user_name_tmpl', function($args) {
echo '<table><tr><td>Name</td><td>HTML</td></tr></table>';
}, 10);
The output is rendered as HTML.
Is this the correct hook?
Thanks
-
This reply was modified 1 year, 6 months ago by
ochime.
@ochime
Yes, you can edit the Members Directory grid template
.../plugins/ultimate-member/templates/members-grid.php
where you have your hook um_members_after_user_name_tmpl at line 86
and save the new template as your custom template.
https://docs.ultimatemember.com/article/1516-templates-map
Hi @ochime
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