Skip to content

Commit

Permalink
Updated gpppw-split-words-on-specific-characters and added gpppw-pay-…
Browse files Browse the repository at this point in the history
…per-character

Original Gist for gpppw-pay-per-character: https://gist.github.com/spivurno/bf3b4a944b307d8ec57e29f77cd0ac91
  • Loading branch information
scyt committed Sep 17, 2020
1 parent 7dd761f commit 06b73cb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
11 changes: 11 additions & 0 deletions gp-pay-per-word/gpppw-pay-per-character.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Gravity Perks // Pay Per Word // Surprise, Pay Per Character! (JS)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*
* This snippet requires the PHP counterpart gpppw-pay-per-character.php
*/
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;
} );
12 changes: 12 additions & 0 deletions gp-pay-per-word/gpppw-pay-per-character.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Gravity Perks // Pay Per Word // Surprise, Pay Per Character! (PHP)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*
* This snippet requires the JS counterpart gpppw-pay-per-character.js
*/
add_filter( 'gpppw_word_count', function( $word_count, $words ) {
// Pay per character instead of words.
$words = str_split( trim( $words ) );
return count( $words );
}, 10, 2 );
6 changes: 4 additions & 2 deletions gp-pay-per-word/gpppw-split-words-on-specific-characters.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* Gravity Perks // Pay Per Word // Split Words on Specific Characters (JS)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*
* This snippet requires the PHP counterpart gpppw-split-words-on-specific-characters.php
*/
gform.addFilter( 'gpppw_word_count', function( wordCount, text, gwppw, ppwField, formId ) {
// Splits words on periods, underscores, and asterisks.
// Splits words on periods, underscores, and asterisks.
var words = text.replace( /[\.\_\*]/g, ' ' ).match( /\S+/g );
return words == null ? 0 : words.length;
} );
} );
8 changes: 5 additions & 3 deletions gp-pay-per-word/gpppw-split-words-on-specific-characters.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
/**
* Gravity Perks // Pay Per Word // Split Words on Specific Characters (PHP)
* https://gravitywiz.com/documentation/gravity-forms-pay-per-word/
*
* This snippet requires the JS counterpart gpppw-split-words-on-specific-characters.js
*/
add_filter( 'gpppw_word_count', function( $word_count, $words ) {
// Splits words on periods, underscores and asterisks.
$words = preg_replace( '/[\.\_\*]/', ' ', $words );
// Splits words on periods, underscores and asterisks.
$words = preg_replace( '/[\.\_\*]/', ' ', $words );
return count( array_filter( preg_split( '/[ \n\r]+/', trim( $words ) ) ) );
}, 10, 2 );
}, 10, 2 );

0 comments on commit 06b73cb

Please sign in to comment.