gpui_unique_id_attributes

  1. Description
  2. Usage
  3. Parameters
  4. Since
  5. Example
    1. Change the Length of the Unique to be Generated.

Description

Allows you to modify the attributes that will be used to generate a unique ID using a custom function.

Usage

add_filter( 'gpui_unique_id_attributes', 'my_custom_function', 10, 3 );

Parameters

  • atts array

    The following properties are passed in the $atts array.

    • type string

      The type of unique ID to generate: ‘alphanumeric’, ‘numeric’, ‘sequential’.

    • starting_number integer

      The number at which to start when creating a sequential unique ID.

    • length string

      The length of the unique ID.

    • prefix string

      A string of characters to be prepended to the unique ID.

    • suffix string

      A string of characters to be appended to the unique ID.

  • form_id string

The ID of the form for which the unique ID is being generated.

The ID of the field for which the unique ID is being generated.

Since

This filter is available since GP Unique ID 1.0.0

Example

Change the Length of the Unique to be Generated.


add_filter( 'gpui_unique_id_attributes', 'my_custom_unique_id_attributes', 10, 3 );
function my_custom_unique_id_attributes( $atts, $form_id, $field_id ) {

    // if this is our desired field
    if( $field_id == 1 ) {
        // bypass 'numeric' ID min character length of 9
        $atts['length'] = 4;
    }

    // return modified attributes
    return $atts;
}
 

Â