Skip to content

Instantly share code, notes, and snippets.

@vfontjr
Created January 4, 2023 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfontjr/5d072ab98c24568ca3a1ab9a690ef3ed to your computer and use it in GitHub Desktop.
Save vfontjr/5d072ab98c24568ca3a1ab9a690ef3ed to your computer and use it in GitHub Desktop.
Count Formidable Entries by User Role
<?php
add_action('frm_display_form_action', 'check_entry_count', 8, 3);
function check_entry_count($params, $fields, $form) {
global $user_ID;
/* get the current user object */
$current_user = wp_get_current_user();
remove_filter('frm_continue_to_new', '__return_false', 50);
if( $form->id == 5 and !is_admin() ) { //replace 5 with the ID of your form
$count = FrmEntry::getRecordCount("form_id=". $form->id ." AND user_id=".$user_ID);
if ( ( in_array('public', $current_user->roles) && $count >= 50 ) || ( in_array('business', $current_user->roles) && $count >= 100 ) ) {
echo 'This form is closed';
add_filter('frm_continue_to_new', '__return_false', 50);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment