Gravity Forms + Custom Post Types - Version 2.1

Version Description

  • Fixed a bug where every 10th taxonomy was not being saved to the post. Thanks to Peter Schuster for the help on this fix
  • Fixed most php warnings
Download this release

Release Info

Developer bradvin
Plugin Icon wp plugin Gravity Forms + Custom Post Types
Version 2.1
Comparing to
See all releases

Code changes from version 2.0 to 2.1

Files changed (4) hide show
  1. gfcptaddon.php +1 -1
  2. gfcptaddon_1-5.php +4 -0
  3. gfcptaddonbase.php +15 -14
  4. readme.txt +6 -2
gfcptaddon.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Gravity Forms + Custom Post Types
4
  Plugin URI: http://themergency.com/plugins/gravity-forms-custom-post-types/
5
  Description: Allows a simple way to map a Gravity Form post entry to a custom post type. Also include custom taxonomies.
6
- Version: 2.0
7
  Author: Brad Vincent
8
  Author URI: http://themergency.com/
9
  License: GPL2
3
  Plugin Name: Gravity Forms + Custom Post Types
4
  Plugin URI: http://themergency.com/plugins/gravity-forms-custom-post-types/
5
  Description: Allows a simple way to map a Gravity Form post entry to a custom post type. Also include custom taxonomies.
6
+ Version: 2.1
7
  Author: Brad Vincent
8
  Author URI: http://themergency.com/
9
  License: GPL2
gfcptaddon_1-5.php CHANGED
@@ -29,7 +29,11 @@ if (!class_exists('GFCPTAddon1_5')) {
29
  * Override. Gets the taxonomy from our new field value
30
  */
31
  function get_field_taxonomy( $field ) {
 
32
  return $field['populateTaxonomy'];
 
 
 
33
  }
34
 
35
  /*
29
  * Override. Gets the taxonomy from our new field value
30
  */
31
  function get_field_taxonomy( $field ) {
32
+ if (array_key_exists('populateTaxonomy', $field)) {
33
  return $field['populateTaxonomy'];
34
+ } else {
35
+ return false;
36
+ }
37
  }
38
 
39
  /*
gfcptaddonbase.php CHANGED
@@ -28,19 +28,19 @@ if (!class_exists('GFCPTAddonBase')) {
28
  * Setup the form with any taxonomies
29
  */
30
  function setup_form( $form ) {
31
- //loop thru all fields
32
- foreach($form['fields'] as &$field) {
 
 
 
33
 
34
- //see if the field is using a taxonomy
35
- $taxonomy = $this->get_field_taxonomy( $field );
36
 
37
- if(!$taxonomy)
38
- continue;
39
 
40
- $this->setup_taxonomy_field( $field, $taxonomy );
41
- }
42
-
43
- return $form;
44
  }
45
 
46
  /*
@@ -103,8 +103,9 @@ if (!class_exists('GFCPTAddonBase')) {
103
  //recreate the inputs so they are captured correctly on form submission
104
  foreach( $field['choices'] as $choice ) {
105
  $counter++;
 
106
  $id = floatval( $field['id'] . '.' . $counter );
107
- $field['inputs'][] = array('label' => $choice->label, 'id' => $id);
108
  }
109
  }
110
  }
@@ -185,7 +186,7 @@ if (!class_exists('GFCPTAddonBase')) {
185
  * Save linked taxonomies for a sinle field
186
  */
187
  function save_taxonomy_field( &$field, $entry, $taxonomy ) {
188
- if ( $field['type'] == 'checkbox' ) {
189
  $term_ids = array();
190
  foreach ( $field['inputs'] as $input ) {
191
  $term_id = (int) $entry[ (string) $input['id'] ];
@@ -193,12 +194,12 @@ if (!class_exists('GFCPTAddonBase')) {
193
  $term_ids[] = $term_id;
194
  }
195
  if ( !empty ( $term_ids ))
196
- wp_set_object_terms( $entry['post_id'], $term_ids, $taxonomy );
197
 
198
  } else {
199
  $term_id = (int) $entry[$field['id']];
200
  if ( $term_id > 0 )
201
- wp_set_object_terms( $entry['post_id'], $term_id, $taxonomy );
202
  }
203
  }
204
  }
28
  * Setup the form with any taxonomies
29
  */
30
  function setup_form( $form ) {
31
+
32
+ //loop thru all fields
33
+ foreach($form['fields'] as &$field) {
34
+ //see if the field is using a taxonomy
35
+ $taxonomy = $this->get_field_taxonomy( $field );
36
 
37
+ if(!$taxonomy)
38
+ continue;
39
 
40
+ $this->setup_taxonomy_field( $field, $taxonomy );
41
+ }
42
 
43
+ return $form;
 
 
 
44
  }
45
 
46
  /*
103
  //recreate the inputs so they are captured correctly on form submission
104
  foreach( $field['choices'] as $choice ) {
105
  $counter++;
106
+ if ( ($counter % 10) == 0 ) $counter++; //thanks to Peter Schuster for the help on this fix
107
  $id = floatval( $field['id'] . '.' . $counter );
108
+ $field['inputs'][] = array('label' => $choice['text'], 'id' => $id);
109
  }
110
  }
111
  }
186
  * Save linked taxonomies for a sinle field
187
  */
188
  function save_taxonomy_field( &$field, $entry, $taxonomy ) {
189
+ if ( array_key_exists( 'type', $field ) && $field['type'] == 'checkbox' ) {
190
  $term_ids = array();
191
  foreach ( $field['inputs'] as $input ) {
192
  $term_id = (int) $entry[ (string) $input['id'] ];
194
  $term_ids[] = $term_id;
195
  }
196
  if ( !empty ( $term_ids ))
197
+ wp_set_object_terms( $entry['post_id'], $term_ids, $taxonomy, true );
198
 
199
  } else {
200
  $term_id = (int) $entry[$field['id']];
201
  if ( $term_id > 0 )
202
+ wp_set_object_terms( $entry['post_id'], $term_id, $taxonomy, true );
203
  }
204
  }
205
  }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: bradvin
3
  Donate link: http://themergency.com/donate/
4
  Tags: form,forms,gravity,gravity form,gravity forms,CPT,custom post types,custom post type,taxonomy,taxonomies
5
  Requires at least: 3.0
6
- Tested up to: 3.1
7
- Stable tag: 2.0
8
 
9
  Easily map your forms that create posts to a custom post type. Also map dropdown select, radio buttons list and checkboxes lists to a custom taxonomy.
10
 
@@ -57,6 +57,10 @@ With **v1.5** of Gravity Forms, again things are alot easier. Under the advanced
57
 
58
  == Changelog ==
59
 
 
 
 
 
60
  = 2.0 =
61
  * Added support for both Gravity Forms v1.5 beta and v.1.4.5
62
  * Now supports linking taxonomies to Drop Downs, Multiple Choice or Checkboxes
3
  Donate link: http://themergency.com/donate/
4
  Tags: form,forms,gravity,gravity form,gravity forms,CPT,custom post types,custom post type,taxonomy,taxonomies
5
  Requires at least: 3.0
6
+ Tested up to: 3.2
7
+ Stable tag: 2.1
8
 
9
  Easily map your forms that create posts to a custom post type. Also map dropdown select, radio buttons list and checkboxes lists to a custom taxonomy.
10
 
57
 
58
  == Changelog ==
59
 
60
+ = 2.1 =
61
+ * Fixed a bug where every 10th taxonomy was not being saved to the post. Thanks to Peter Schuster for the help on this fix
62
+ * Fixed most php warnings
63
+
64
  = 2.0 =
65
  * Added support for both Gravity Forms v1.5 beta and v.1.4.5
66
  * Now supports linking taxonomies to Drop Downs, Multiple Choice or Checkboxes