Created
September 4, 2014 15:14
-
-
Save spivurno/afac61057595ea9c625a to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Entry Count Shortcode
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
<?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/... | |
*/ | |
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' | |
), $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( $format ) { | |
$format = $format == 'decimal' ? '.' : ','; | |
$output = number_format( $output, 0, false, $format ); | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@marktenney I don't think Gravity Forms has a way to get all counts via a function but you can query the database directly easy enough.
$total_unread = $wpdb->get_var( "select count( id ) from wp_gf_entry where is_read = 0 and status = 'active'" );