Created
October 12, 2020 22:43
-
-
Save jaredatch/a6f09902e6bf606658c1813461161c11 to your computer and use it in GitHub Desktop.
Display WPForms entries count
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 | |
/** | |
* Custom shortcode to display WPForms form entries count for a form. | |
* | |
* Basic usage: [wpf_entries_count id="FORMID" type="TYPE"]. | |
* | |
* @param array $atts Shortcode attributes. | |
* | |
* @return string | |
*/ | |
function wpf_entries_count( $atts ) { | |
// Pull ID shortcode attributes. | |
$atts = shortcode_atts( | |
[ | |
'id' => '', | |
'type' => 'all', // all, unread, read, or starred. | |
], | |
$atts | |
); | |
if ( empty( $atts['id'] ) ) { | |
return; | |
} | |
$args = [ | |
'form_id' => absint( $atts['id'] ), | |
]; | |
if ( $atts['type'] === 'unread' ) { | |
$args['viewed'] = '0'; | |
} elseif( $atts['type'] === 'read' ) { | |
$args['viewed'] = '1'; | |
} elseif ( $atts['type'] === 'starred' ) { | |
$args['starred'] = '1'; | |
} | |
return wpforms()->entry->get_entries( $args, true ); | |
} | |
add_shortcode( 'wpf_entries_count', 'wpf_entries_count' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment