-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathgpnf-nested-entries-max-message.php
44 lines (37 loc) · 1.32 KB
/
gpnf-nested-entries-max-message.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Gravity Perks // Nested Forms // Override Max Entries Message
* https://gravitywiz.com/documentation/gravity-forms-nested-form/
*
* This snippet allows overrides the default button message in the Nested Form Perk
* and shows the user the minimum and maximum number of entries that can be added.
*
* @version 0.1
*/
// Update "123" to your form ID and "4" to your field ID. Remove "_123_4" to apply this globally.
add_filter( 'gpnf_template_args_123_4', function ( $args, $form_field ) {
// $args->add_button_message is not always present when this hook is applied
if ( ! array_key_exists( 'add_button_message', $args ) ) {
return $args;
}
$min = $form_field->gpnfEntryLimitMin;
$max = $form_field->gpnfEntryLimitMax;
$message = null;
if ( ( empty( $min ) || $min === '0' ) && ! empty( $max ) ) {
$message = 'You can add no more than ' . $max . ' entries.';
} elseif ( ( empty( $max ) || $max === '0' ) && ! empty( $min ) ) {
$message = 'You must add at least ' . $min . ' entries.';
} elseif ( ! empty( $min ) && ! empty( $max ) ) {
$message = 'You must add at least ' . $min . ' entries and no more than ' . $max . ' entries.';
}
if ( ! is_null( $message ) ) {
$args['add_button_message'] = sprintf(
'
<p class="gpnf-add-entry-max">
%s
</p>',
$message
);
}
return $args;
}, 10, 2 );