
The minimum viable product of Gravity Forms was launched in 2009 as a plugin that had an excellent UI to create nice looking forms and offered a wealth of options for notification messages. It’s grown over the years to include an extensive API and add-on framework that now justifies considering it as more of an application framework. Built on top of WordPress that is in itself an application platform / framework. Frameworkception!
For a great overview of the Gravity Forms approach, head over to Steven Henty’s 2014 post covering the Gravity Forms API which is where this overview diagram comes from. In May of this year, Steven started a beta program to flush out his own minimum viable product ideas of an add-on for Gravity Forms that provided the ability to create customized workflows on submitted forms. At the earliest stages I could tell it had some serious potential and sent him a fair bit of feedback. Just before the beta wrapped up in September, I deployed Gravity Flow on a production event fundraising microsite with great success. Through it – and judicious use of the GF API – I converted a highly manual process of tallying entry point values and preparing daily summary reports into a low-effort task that could be handled through one screen / step in a workflow.
Gravity Flow has had several point releases since its’ 1.0 launch in October of this year with some amazing new features. Today, I got a chance to dive into using what will surely become an essential element for anyone using WordPress / Gravity Forms + Flow as an application framework – adding a custom step type. The rest of this blog post is a nuts & bolts look at how you can use it and the Gravity Forms + Custom Post Type plugin to move posts along the publishing track in parallel to a workflow.
Pre-Requisites
- Installation of Gravity Forms, Gravity Flow, Gravity Flow + Custom Post Types
- Optional – Use of ACF and WCK to handle registering custom post type, taxonomies and custom fields.
Preparation
- Create Custom Post Type + Taxonomies / Custom Fields for your use case.
- Create a Form and use the post title field type to identify the custom post type and name.
- Match meta data between form and post type using the populate from taxonomy feature.
ACF Users – I’ve opened a support ticket on GF + CPT for a unique case that relates to the way ACF uses custom fields and save events to generate taxonomy values.
Update: Support ticket has hack to solve populate taxonomies and post types into the plugin until a > v3.1 version supports it directly. - Create an approval workflow step for appropriate resource – including the {workflow_approve_link} for one-click approvals.
At this point – when a user submits the form it creates a draft entry in your custom post type and you have confirmed that your content admin is ok that it is ready to publish.
Let’s get steppin’
The Gravity_Flow_Step abstract base class is used to create new step types. Extend this class to add custom steps to the workflow step settings.
The documentation for adding a custom step is pretty clear about how to create a class that extends Gravity_Flow_Step to let you do….anything. In this case, the secret sauce I cooked up was:
- get_settings function – Pull the list of post statuses via get_post_statuses into an array to populate the select choices for the workflow settings screen.
Note: This only returns the core post statuses, so your mileage may vary if you’re registering custom post statuses such as with Piklist. get_icon_url function – Obligatory custom icon by overriding the get_icon_url function
I chose to go with the closest to WP post status icon I could manage.- process function – retrieve the entry to get custom post type object, validate the pre-state as default before updating post to new (selected via settings) post status.
The full gist – living on ye ol Github – where I also documented how to achieve similar result via the gravityflow_step_complete action. While it achieved similar result – it would fire in far too many step cases for my needs.
https://gist.github.com/Idealien/63b313ca66e458950f18#file-gflow-custom-step-function-php
Again – Huge props to Steven Henty and his team for building another versatile piece of the building block puzzle that helps me answer automation and integration challenges within the WordPress and Gravity Forms environments. This may be close to the last code I write with it for 2015 – but it makes me very excited for what lies ahead in the new year!
Going with the Flow?
I’d be curious to see the gists or code snippets from anyone else that is using Gravity Flow extensively or excitedly.
Post ’em if you got em!
I’ve updated the GF+CPT support request – https://wordpress.org/support/topic/populate-custom-field-from-taxonomy – with three one line snippets that will enable you to populate taxonomy / custom post types until the GravityWiz wonder team can roll in a more robust solution in a future release.
Note – This will have to be included as part of a plugin – cannot operate as a part of theme functions.php.