-
-
Save anonymous/5583d3825147be64374e1c84714ab787 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'gform_shortcode_entries_left', 'gwiz_entries_left_shortcode', 10, 2 ); | |
function gwiz_entries_left_shortcode( $output, $atts ) { | |
extract( shortcode_atts( array( | |
'id' => false, | |
'format' => false // should be 'comma', 'decimal' | |
), $atts ) ); | |
if( ! $id ) | |
return ''; | |
$form = RGFormsModel::get_form_meta( $id ); | |
if( ! rgar( $form, 'limitEntries' ) || ! rgar( $form, 'limitEntriesCount' ) ) | |
return ''; | |
$entry_count = RGFormsModel::get_lead_count( $form['id'], '', null, null, null, null, '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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment