Created
February 27, 2020 19:48
-
-
Save spivurno/9f8f1fc9805079fedefe660a0669eb0a to your computer and use it in GitHub Desktop.
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
/** | |
* 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; | |
} ); |
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 | |
/** | |
* 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 ); |
@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
i am using pay per word perk first time... Can we customize this this plugin to pay per character?