Forked from ipokkel/my-pmpromd-display-element-html.php
Last active
June 9, 2025 11:27
-
-
Save dwanjuki/be8660f198468399dd94775946b0da2b to your computer and use it in GitHub Desktop.
Allow some HTML tags when displaying textarea fields on the member directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Allow some HTML tags when displaying textarea fields on the member directory. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpromd_display_element_html( $value, $element, $pu, $displayed_levels ) { | |
// Set the user field names that should display as HTML here. | |
$html_fields = array( 'my_textarea' ); | |
if ( in_array( $element, $html_fields ) ) { | |
// Get the raw value directly from user metadata. | |
$raw_value = get_user_meta( $pu->ID, $element, true ); | |
// If no value is found, return the original value. | |
if ( empty( $raw_value ) ) { | |
return $value; | |
} | |
// Allowed html tags. | |
$allowed_html = array( | |
'p' => array(), | |
'ul' => array(), | |
'ol' => array(), | |
'li' => array(), | |
'span' => array(), | |
); | |
// Replace line breaks with paragraph elements. | |
$value = wpautop( $raw_value ); | |
// Sanitize content for allowed HTML tags. | |
$value = wp_kses( $value, $allowed_html ); | |
} | |
return $value; | |
} | |
add_filter( 'pmpromd_get_display_value', 'my_pmpromd_display_element_html', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment