Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Created February 13, 2018 18:06
Show Gist options
  • Save rafaehlers/1f805a18ace3e252cba598008010b1f3 to your computer and use it in GitHub Desktop.
Save rafaehlers/1f805a18ace3e252cba598008010b1f3 to your computer and use it in GitHub Desktop.
:maxwords2 used to have manual control over the maxwords modifier
<?php
add_filter( 'gform_merge_tag_filter', function ( $value, $merge_tag, $modifier, $field, $raw_value ) {
if( 'all_fields' !== $merge_tag && 'maxwords2' === $modifier ) {
/* Number of words to display */
$max = 4;
$more_placeholder = '&hellip;';
/**
* Use htmlentities instead, so that entities are double-encoded, and decoding restores original values.
* @see https://core.trac.wordpress.org/ticket/29533#comment:3
*/
$value = force_balance_tags( wp_specialchars_decode( wp_trim_words( htmlentities( $raw_value ), $max, $more_placeholder ) ) );
return $value;
}
return $value;
}, 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment