Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scyt/8f92c925f201f4337fdc5048741b2564 to your computer and use it in GitHub Desktop.
Save scyt/8f92c925f201f4337fdc5048741b2564 to your computer and use it in GitHub Desktop.
/**
* Gravity Perks // Pay Per Word // Ignore Words Between Parentheses (JS)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*/
gform.addFilter( 'gpppw_word_count', function( wordCount, text, gwppw, ppwField, formId ) {
// Removes words between parentheses.
var words = text.replace( /\(([^)]+)\)/g, '' ).match( /\S+/g );
return words == null ? 0 : words.length;
} );
<?php
/**
* Gravity Perks // Pay Per Word // Ignore Words Between Parentheses (PHP)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*/
add_filter( 'gpppw_word_count', function( $word_count, $words ) {
// Removes words between parentheses.
$words = preg_replace( '/\(([^)]+)\)/', ' ', $words );
return count( array_filter( preg_split( '/[ \n\r]+/', trim( $words ) ) ) );
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment