PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

gform_filter_leads

  1. I've seen a few posts on this, but we really need it... so I built it. The idea is to create a filter which lets developers restrict which leads / entries are returned to the user through the back end.

    It could be used to divide forms by department, allow back end separation by client, or by form... whatever the dev wants. Here are some sample topics:
    http://www.gravityhelp.com/forums/topic/show-only-entries-from-a-field
    http://www.gravityhelp.com/forums/topic/lead-generation-for-companies
    http://www.gravityhelp.com/forums/topic/admin-entries-filters

    Adding the filter is easy

    forms_model.php line ~2386 (immediately before return of get_lead

    $leads = apply_filters("gform_filter_leads", $leads);

    forms_model.php line ~2488 (immediately before return of get_leads

    $leads = apply_filters("gform_filter_leads", $leads);

    Very easy change, very powerful results.

    The only slight issue is that this will interfere with the counts (all/unread/starred/trashed/spam)
    There are a couple ways to handle. You could put in a little more overhead and have the counts actually run the get_leads function. Or you could just remove the counts (this is what I did since I don't think they add any value).

    entry_list.php line ~584

    <ul class="subsubsub">
    -                    <li><a class="<?php echo empty($filter) ? "current" : "" ?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>"><?php _e("All", "gravityforms"); ?> <span class="count">(<span id="all_count"><?php echo $active_lead_count ?></span>)</span></a> | </li>
    -                    <li><a class="<?php echo $read !== null ? "current" : ""?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>&filter=unread"><?php _e("Unread", "gravityforms"); ?> <span class="count">(<span id="unread_count"><?php echo $unread_count ?></span>)</span></a> | </li>
    -                    <li><a class="<?php echo $star !== null ? "current" : ""?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>&filter=star"><?php _e("Starred", "gravityforms"); ?> <span class="count">(<span id="star_count"><?php echo $starred_count ?></span>)</span></a> | </li>
    +                    <li><a class="<?php echo empty($filter) ? "current" : "" ?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>"><?php _e("All", "gravityforms"); ?></a> | </li>
    +                    <li><a class="<?php echo $read !== null ? "current" : ""?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>&filter=unread"><?php _e("Unread", "gravityforms"); ?></a> | </li>
    +                    <li><a class="<?php echo $star !== null ? "current" : ""?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>&filter=star"><?php _e("Starred", "gravityforms"); ?></a> | </li>
                         <?php
                         if(GFCommon::akismet_enabled($form_id)){
                             ?>
    -                        <li><a class="<?php echo $filter == "spam" ? "current" : ""?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>&filter=spam"><?php _e("Spam", "gravityforms"); ?> <span class="count">(<span id="spam_count"><?php echo $spam_count ?></span>)</span></a> | </li>
    +                        <li><a class="<?php echo $filter == "spam" ? "current" : ""?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>&filter=spam"><?php _e("Spam", "gravityforms"); ?></a> | </li>
                             <?php
                         }
                         ?>
    -                    <li><a class="<?php echo $filter == "trash" ? "current" : ""?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>&filter=trash"><?php _e("Trash", "gravityforms"); ?> <span class="count">(<span id="trash_count"><?php echo $trash_count ?></span>)</span></a></li>
    +                    <li><a class="<?php echo $filter == "trash" ? "current" : ""?>" href="?page=gf_entries&view=entries&id=<?php echo $form_id ?>&filter=trash"><?php _e("Trash", "gravityforms"); ?></a></li>
                     </ul>

    I think this would be a great addition to the core and of course would save me from having to make the change on every update.

    Posted 11 years ago on Thursday March 21, 2013 | Permalink
  2. Btw, here is a sample of how I've used the filter:

    public static function filter_leads($leads){
    		if(!current_user_can('remove_users')){  // we want to filter leads for lower level users
    			$user_client = get_usermeta(get_current_user_id(),'client');
    			$user_client = $user_client[0];
    			foreach ($leads as $key => $value) {
    				$post = self::get_post_from_entry($value[id]);
    				$post_client = get_post_meta('client',$post->ID);
    				$post_client = $post_client[0];
    				if ($post_client->ID != $user_client) {
    					unset($leads[$key]);
    				}
    			}
    		}
    		return $leads;
    	}
    Posted 11 years ago on Thursday March 21, 2013 | Permalink
  3. Thanks for the code. How is that working for you right now?

    Posted 11 years ago on Saturday March 23, 2013 | Permalink
  4. Since it is just a standard WordPress filter, it is very simple to get it working. Like I said, I hope you add this to your release so others can benefit.

    Posted 11 years ago on Saturday March 23, 2013 | Permalink
  5. Thanks. I forwarded your suggestion to the development team.

    Posted 11 years ago on Monday March 25, 2013 | Permalink
  6. Hi Bristweb,

    The biggest issue I see with this offhand is that it does not work well with the pagination. If you filter out x number of leads, the pagination does not know how many leads were filtered out and will not be updated. This means you could have 200 leads but filter out 199 of them. The user would see there 1 lead but the pagination would indicate that there were 10 more pages of leads for them to view.

    I've added this topic to our task queue so that we will sit down and think of the best way to allow the filtering of leads. Thanks for the sample code and encouragement to look into this! :)

    Posted 11 years ago on Wednesday March 27, 2013 | Permalink
  7. Plus 1 for a built-in hook to filter leads.

    To achieve this on my current project, I've replicated the entry_list and entry_detail pages in my theme, and then added a new page called "leads" using the gform_addon_navigation hook. I then process the info on that page and filter leads as appropriate. It does make the count redundant, but I'm not too bothered about that at this stage. I'm also increasing the leads-per-page using gform_entry_page_size to 99999 since volume isn't an issue in this case & I didn't want to run into the pagination issue.

    Posted 10 years ago on Thursday May 9, 2013 | Permalink
  8. Hi squidgemann,

    Thanks for adding your voice to this request. This task has not yet come up in our queue; however, this forum post is listed in the task so we'll review it when we discuss and plan on how to best support this. :)

    Posted 10 years ago on Thursday May 9, 2013 | Permalink