Gravity Forms has released a major update with version 2.3. It addressed some organizational issues that probably needed addressing. But it also is breaking sites that have custom code that access Gravity Forms database tables directly. This post addresses how to fix some of the Gravity Forms update issues that may arise.
The proper way to directly query or alter a gravity forms database table is through their API.
So if your code is accessing the database table using the table name, it may break as that table may no longer exist.
The issue:
Gravity Forms version 2.3 has replaced the tables rg_lead and rg_lead_detail with gf_entry and gf_entry_meta.
There are other changes. Here is a link to the new database schema if you want to see exactly which tables were renamed with the update. I am only dressing the two most commonly accessed.
The fix:
If you have access to your files, you can do a search for ‘rg_lead’ and see if any of these lines appear
$wpdb->prefix.’rg_lead’
$wpdb->prefix.’rg_lead_detail’
or a more specific line would contain your actual database prefix like the default wp_. For example:
wp_rg_lead
wp_rg_lead_detail
$wpdb->prefix.’rg_lead’ can be replaced with a call to the Gravity Forms API:
GFFormsModel::get_entry_table_name()
$wpdb->prefix.’rg_lead_detail’ can be replaced with a call to the Gravity Forms API:
GFFormsModel::get_entry_meta_table_name()
Column names:
In conjunction with the new table names, Gravity Forms also updated some column names. The most relevant here are concerning the old ‘lead_details’ table. So if your code queries that table it is likely using old column names. Here are the changes:
- ‘lead_id’ is now ‘entry_id’
- ‘field_number’ is now ‘meta_key’
- ‘value’ is now ‘meta_value’
So if you are still breaking after the update, search for the old string and replace it with the new.
This cannot be done in preparation as the ‘new’ strings will not work with versions prior to 2.3. If you really need this be done in advance, you can add a conditional based upon which Gravity Forms version you are using.
This is a very general example of how you might do this:
$lead_col = GFForms::$version >= ‘2.3’?’entry_id’:’lead_id’;
$field_col = GFForms::$version >= ‘2.3’?’meta_key’:’field_number’;
$value_col = GFForms::$version >= ‘2.3’?’meta_value’:’value’;
Or:
if (\GFForms::$version >= '2.3'){
$table = \GFFormsModel::get_entry_meta_table_name();
$wpdb->insert($table, array(
'meta_value' => $value,
'meta_key' => $key,
'entry_id' => $id,
'form_id' => $form['id']
));
}
else {
$table = \GFFormsModel::get_lead_details_table_name();
$wpdb->insert($table, array(
'value' => $value,
'field_number' => $key,
'lead_id' => $id,
'form_id' => $form['id']
));
}
Of course the best way to deal with the column names is to not use them at all. Instead use the API:
\gform_update_meta( $entry[‘id’], ‘field number’, ‘value’ );
Hopefully this takes care of your Gravity Forms update issues related to Version 2.3. If not, feel free to contact us at support@anvilzephyr.com.