Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created May 2, 2025 10:13
Show Gist options
  • Save ipokkel/955e15268a4a7b6c6ecf94aa63ad3696 to your computer and use it in GitHub Desktop.
Save ipokkel/955e15268a4a7b6c6ecf94aa63ad3696 to your computer and use it in GitHub Desktop.
<?php
/**
* Automatically add paragraphs for set elements displayed 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 be formatted here.
$autop_fields = array( 'field_one', 'field_two', 'field_three' );
if ( in_array( $element, $autop_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;
}
// Check if we lost HTML during processing.
if ( ! empty( $raw_value ) && $raw_value !== $value && strpos( $raw_value, '<' ) !== false && strpos( $value, '<' ) === false ) {
// Apply wp_kses_post to ensure only allowed HTML remains (redundant safety)
$value = wp_kses_post( $raw_value );
}
// Apply wpautop to add paragraph tags while preserving HTML.
$value = wpautop( $value );
}
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