• 1.
    <?php
  • 2.
    /**
  • 3.
     * Gravity Wiz // Gravity Forms // Entry Count Shortcode
  • 4.
     *
  • 5.
     * Extends the [gravityforms] shortcode, providing a custom action to retrieve the total entry count and
  • 6.
     * also providing the ability to retrieve counts by entry status (i.e. 'trash', 'spam', 'unread', 'starred').
  • 7.
     *
  • 8.
     * @version	  1.0
  • 9.
     * @author    David Smith <[email protected]>
  • 10.
     * @license   GPL-2.0+
  • 11.
     * @link      http://gravitywiz.com/...
  • 12.
     * 
  • 13.
     *  added alternate text to display until a specified minimum count threshold is achieved.
  • 14.
     *  Dean Suhr 2021-09-20
  • 15.
     * [gravityforms action="entry_count" id="1" display_min="500" display_min_alt_text="this text is displayed until the display_min threshold is reached"]
  • 16.
    /
  • 17.
     *   
  • 18.
    add_filter( 'gform_shortcode_entry_count', 'gwiz_entry_count_shortcode', 10, 2 );
  • 19.
    function gwiz_entry_count_shortcode( $output, $atts ) {
  • 20.
     
  • 21.
        extract( shortcode_atts( array(
  • 22.
            'id' => false,
  • 23.
            'status' => 'total', // accepts 'total', 'unread', 'starred', 'trash', 'spam'
  • 24.
            'format' => false, // should be 'comma', 'decimal'
  • 25.
            'display_min'  => false, // minimum value before count is displayed
  • 26.
            'display_min_alt_text'  => false // alternate text if display_min is not reached
  • 27.
        ), $atts ) );
  • 28.
     
  • 29.
        $valid_statuses = array( 'total', 'unread', 'starred', 'trash', 'spam' );
  • 30.
     
  • 31.
        if( ! $id || ! in_array( $status, $valid_statuses ) ) {
  • 32.
            return current_user_can( 'update_core' ) ? __( 'Invalid "id" (the form ID) or "status" (i.e. "total", "trash", etc.) parameter passed.' ) : '';
  • 33.
        }
  • 34.
     
  • 35.
        $counts = GFFormsModel::get_form_counts( $id );
  • 36.
        $output = rgar( $counts, $status );
  • 37.
     
  • 38.
        if ( $display_min > 0 and $output >= $display_min ) {
  • 39.
            // have reached numeric display minimum threshold
  • 40.
            if( $format ) {
  • 41.
                $format = $format == 'decimal' ? '.' : ',';
  • 42.
                $output = number_format( $entries_left, 0, false, $format );
  • 43.
            }
  • 44.
        } else {
  • 45.
            // have NOT reached numeric display minimum threshold
  • 46.
            $output = $display_min_alt_text;
  • 47.
        }
  • 48.
        
  • 49.
        return $output;
  • 50.
    }
<?php /** * Gravity Wiz // Gravity Forms // Entry Count Shortcode * * Extends the [gravityforms] shortcode, providing a custom action to retrieve the total entry count and * also providing the ability to retrieve counts by entry status (i.e. 'trash', 'spam', 'unread', 'starred'). * * @version 1.0 * @author David Smith <[email protected]> * @license GPL-2.0+ * @link http://gravitywiz.com/... * * added alternate text to display until a specified minimum count threshold is achieved. * Dean Suhr 2021-09-20 * [gravityforms action="entry_count" id="1" display_min="500" display_min_alt_text="this text is displayed until the display_min threshold is reached"] / * add_filter( 'gform_shortcode_entry_count', 'gwiz_entry_count_shortcode', 10, 2 ); function gwiz_entry_count_shortcode( $output, $atts ) { extract( shortcode_atts( array( 'id' => false, 'status' => 'total', // accepts 'total', 'unread', 'starred', 'trash', 'spam' 'format' => false, // should be 'comma', 'decimal' 'display_min' => false, // minimum value before count is displayed 'display_min_alt_text' => false // alternate text if display_min is not reached ), $atts ) ); $valid_statuses = array( 'total', 'unread', 'starred', 'trash', 'spam' ); if( ! $id || ! in_array( $status, $valid_statuses ) ) { return current_user_can( 'update_core' ) ? __( 'Invalid "id" (the form ID) or "status" (i.e. "total", "trash", etc.) parameter passed.' ) : ''; } $counts = GFFormsModel::get_form_counts( $id ); $output = rgar( $counts, $status ); if ( $display_min > 0 and $output >= $display_min ) { // have reached numeric display minimum threshold if( $format ) { $format = $format == 'decimal' ? '.' : ','; $output = number_format( $entries_left, 0, false, $format ); } } else { // have NOT reached numeric display minimum threshold $output = $display_min_alt_text; } return $output; }

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter