-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathdisplay-number-of-entries-left.php
43 lines (37 loc) · 1.16 KB
/
display-number-of-entries-left.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
<?php
/**
* Gravity Forms // Entries Left Shortcode
* https://gravitywiz.com/shortcode-display-number-of-entries-left/
*
* Instruction Video: https://www.loom.com/share/b6c46aebf0ff483496faf9994e36083e
*
* Instructions:
*
* 1. Install the snippet.
* https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
*/
add_filter( 'gform_shortcode_entries_left', 'gwiz_entries_left_shortcode', 10, 2 );
function gwiz_entries_left_shortcode( $output, $atts ) {
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
extract( shortcode_atts( array(
'id' => false,
'format' => false, // should be 'comma', 'decimal'
), $atts ) );
if ( ! $id ) {
return '';
}
$form = GFAPI::get_form( $id );
if ( ! rgar( $form, 'limitEntries' ) || ! rgar( $form, 'limitEntriesCount' ) ) {
return '';
}
$entry_count = GFAPI::count_entries( $form['id'], array(
'status' => 'active',
) );
$entries_left = rgar( $form, 'limitEntriesCount' ) - $entry_count;
$output = $entries_left;
if ( $format ) {
$format = $format == 'decimal' ? '.' : ',';
$output = number_format( $entries_left, 0, false, $format );
}
return $entries_left > 0 ? $output : 0;
}