Description
Filter the calculated word count for the current field on the frontend.
This filter must be used with its PHP counterpart to handle filtering the word count on the frontend.
Usage
gform.addFilter( 'gpppw_word_count', 'my_custom_function' );
Parameters
wordCount int
The calculated word count.
text string
The string of words to be counted.
gwppw \GWPayPerWord
The current instance of the GWPayPerWord object.
ppwField object
An array of options used to handle the Pay Per Word functionality.
formId int
The current form object.
Examples
Pay Per Character
Change Pay Per Word’s behavior to charge per character instead of per word. This snippet must be paired with its PHP counterpart.
gform.addFilter( 'gpppw_word_count', function( wordCount, text, gwppw, ppwField, formId ) {
// Pay per character instead of words.
var words = text.split( '' );
return words == null ? 0 : words.length;
} );
Split Words on Specific Characters
In this example, Pay Per Word splits words on periods, underscores, and asterisks. This snippet must be paired with its PHP counterpart.
gform.addFilter( 'gpppw_word_count', function( wordCount, text, gwppw, ppwField, formId ) {
// Splits words on periods, underscores, and asterisks.
var words = text.replace( /[\.\_\*]/g, ' ' ).match( /\S+/g );
return words == null ? 0 : words.length;
} );
Since
This filter is available since Gravity Forms Pay Per Word 1.0.6.