Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spivurno/9f8f1fc9805079fedefe660a0669eb0a to your computer and use it in GitHub Desktop.
Save spivurno/9f8f1fc9805079fedefe660a0669eb0a to your computer and use it in GitHub Desktop.
/**
* Gravity Perks // Pay Per Word // Split Words on Specific Characters (JS)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*/
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;
} );
<?php
/**
* Gravity Perks // Pay Per Word // Split Words on Specific Characters (PHP)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*/
add_filter( 'gpppw_word_count', function( $word_count, $words ) {
// Splits words on periods, underscores and asterisks.
$words = preg_replace( '/[\.\_\*]/', ' ', $words );
return count( array_filter( preg_split( '/[ \n\r]+/', trim( $words ) ) ) );
}, 10, 2 );
@spivurno
Copy link
Author

spivurno commented Mar 7, 2020

@mohitit How would you want to use this with a character counter?

@mohitit
Copy link

mohitit commented Mar 7, 2020

i am using pay per word perk first time... Can we customize this this plugin to pay per character?

@spivurno
Copy link
Author

spivurno commented Mar 8, 2020

@mohitit I'm not sure why I never thought of it, but yes, this can easily be modified to support paying per character. New snippet here: https://gist.github.com/spivurno/bf3b4a944b307d8ec57e29f77cd0ac91

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