Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active August 6, 2019 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xnau/d75adc466ab749be88ac038357d5e4f8 to your computer and use it in GitHub Desktop.
Save xnau/d75adc466ab749be88ac038357d5e4f8 to your computer and use it in GitHub Desktop.
Demonstrates how to allow HTML in Participants Database text fields
<?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;
}
@xnau
Copy link
Author

xnau commented Jan 5, 2018

Download this as a zip file, then install as a plugin, using the "add plugin" item in the WP plugins menu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment