gpppw_word_count (JS)

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Pay Per Character
    2. Split Words on Specific Characters
  5. Since

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.

/**
 * 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.
	return [...text].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.

/**
 * 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.
	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.