Created
February 13, 2018 18:06
-
-
Save rafaehlers/1f805a18ace3e252cba598008010b1f3 to your computer and use it in GitHub Desktop.
:maxwords2 used to have manual control over the maxwords modifier
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 | |
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 = '…'; | |
/** | |
* 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