Last active
August 6, 2019 14:24
-
-
Save xnau/d75adc466ab749be88ac038357d5e4f8 to your computer and use it in GitHub Desktop.
Demonstrates how to allow HTML in Participants Database text fields
This file contains 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 | |
/** | |
* @wordpress-plugin | |
* Plugin Name: PDB Allow HTML | |
* Description: Installs a filter allowing HTML in Participants Database text fields | |
*/ | |
add_filter( 'pdb-text_field_output', 'xnau_allow_html_in_text', 10, 2 ); | |
/** | |
* allows sanitized HTML in text fields | |
* | |
* @param string $text the sanitized content | |
* @param object $field the current field | |
* | |
* @return string the field content to display | |
*/ | |
function xnau_allow_html_in_text( $text, $field ) | |
{ | |
if ( $field->form_element === 'text-line' ) { | |
/* | |
* the wp_kses_post function sanitizes the value by only allowing | |
* certain HTML tags | |
* see: https://developer.wordpress.org/reference/functions/wp_kses_post/ | |
*/ | |
$text = wp_kses_post( $field->value ); | |
} | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download this as a zip file, then install as a plugin, using the "add plugin" item in the WP plugins menu.