gpwc_script_args

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Change the word counts labels for all fields.
    2. Disable truncation
  5. Source
  6. Since

Description

Modify the arguments that will be passed to the word counter script.

Usage

add_filter( 'gpwc_script_args', 'my_custom_function' );

Parameters

  • default_args array

    Options used to initialize and configure the word counter script.

    • limit int

      The maximum number of words that can be entered.

    • min int

      The minimum number of words that can be entered.

    • truncate bool

      Whether or not the content should automatically be truncated when the limit is reached.

    • defaultLabel string

      Displayed when the word counter is initialized.

    • defaultLabelSingular string

      Displayed when the word counter is initialized and the limit is one.

    • counterLabel string

      Displayed as the user types, indicating how many words are left.

    • counterLabelSingular string

      Displayed as the user types, indicating how many words are left when there is only one word left.

    • limitReachedLabel string

      Displayed when the limit has been reached.

    • limitExceededLabel string

      Displayed when the limit has been exceeded. Only visible when $truncate is set to false.

    • minCounterLabel string

      Displayed as the user types when the minimum word count has not been reached.

    • minCounterLabelSingular string

      Displayed as the user types when the minimum word count is one word from being reached.

    • minReachedLabel string

      Displayed when the minimum is reached and there is no maximum.

    • minDefaultLabel string

      Displayed when a minimum is specified before user interaction.

    • minDefaultLabelSingular string

      Displayed when minimum of one is specified before user interaction.

  • field \GF_Field

    The current field object.

  • form array

    The current form object.

Examples

Change the word counts labels for all fields.

This example demonstrates the basic idea behind modifying labels for this plugin.

<?php
/**
 * Gravity Perks // Word Count // Change the Word Count Labels
 * https://gravitywiz.com/documentation/gravity-forms-word-count/
 *
 * Modify the word count labels displayed for all fields.
 */
add_filter( 'gpwc_script_args', 'gpwc_modify_script_args', 10, 3 );
function gpwc_modify_script_args( $args, $field, $form ) {

	$args['defaultLabel']       = '{count} / {limit}';
	$args['counterLabel']       = '{count} / {limit}';
	$args['limitReachedLabel']  = '<span style="font-weight:bold">{count} / {limit}</span>';
	$args['limitExceededLabel'] = '<span style="font-weight:bold;color:#f00">{count} / {limit}</span>';

	return $args;
}

Disable truncation

This example will prevent the words in a specific field from being truncated when the limit is reached.

<?php
/**
 * Gravity Perks // Word Count // Disable Truncation
 * https://gravitywiz.com/documentation/gravity-forms-word-count/
 *
 * Instruction Video: https://www.loom.com/share/4f588b75b8bb46d7b2d1bdb9ce11f56e
 *
 * This will prevent the words in a specific field from being truncated when the limit is reached.
 */
add_filter( 'gpwc_script_args', function( $args, $field ) {
	// Update "123" to your form ID and "4" to your Word-Count-enabled field.
	if ( $field->formId == 123 && $field->id == 4 ) {
		$args['truncate'] = false;
	}
	return $args;
}, 10, 2 );

Source

This filter is located in GP_Word_Count::register_init_scripts() in class-gp-word-count.php.

Since

This filter is available since GP Word Count 1.3.1.