Gravity Forms + Custom Post Types - Version 3.1.20

Version Description

  • Fixed PHP notice on Gravity Forms Coupons Add-On page.
  • Fixed PHP warning when populating taxonomies.
  • Updated formatting of PHP files in plugin to better conform to the WordPress Coding Standards.
Download this release

Release Info

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

Code changes from version 3.1.19 to 3.1.20

Files changed (4) hide show
  1. gfcptaddon.php +119 -113
  2. gfcptaddon_1-5.php +354 -338
  3. gfcptaddonbase.php +155 -120
  4. readme.txt +6 -0
gfcptaddon.php CHANGED
@@ -3,124 +3,130 @@
3
  Plugin Name: Gravity Forms + Custom Post Types
4
  Plugin URI: https://gravitywiz.com/
5
  Description: Map your Gravity-Forms-generated posts to a custom post type and/or custom taxonomies.
6
- Version: 3.1.19
7
  Author: Gravity Wiz
8
  Author URI: https://gravitywiz.com/
9
  License: GPL2
10
  */
11
 
12
- add_action('init', array('GFCPTAddon', 'init'), 20);
13
- add_action('admin_notices', array('GFCPTAddon', 'admin_warnings'), 20);
14
 
15
  class GFCPTAddon {
16
 
17
- private static $name = 'Gravity Forms + Custom Post Types';
18
- private static $slug = 'GFCPTAddon';
19
- private static $version = '3.1.19';
20
- private static $min_gravityforms_version = '1.9.3';
21
-
22
- //Plugin starting point. Will load appropriate files
23
- public static function init(){
24
-
25
- if(self::is_gravityforms_installed()){
26
-
27
- global $gf_cpt_addon;
28
-
29
- //include the base class
30
- require_once(self::get_base_path() . '/gfcptaddonbase.php');
31
-
32
- //only supports 1.5 and over
33
- require_once(self::get_base_path() . '/gfcptaddon_1-5.php');
34
- $gf_cpt_addon = new GFCPTAddon1_5();
35
-
36
- //start me up!
37
- $gf_cpt_addon->init(__FILE__);
38
- }
39
- }
40
-
41
- //display admin warnings if GF is not the correct version or GF is not installed
42
- public static function admin_warnings() {
43
- if ( !self::is_gravityforms_installed() ) {
44
- $message = __('requires Gravity Forms to be installed.', self::$slug);
45
- } else if ( !self::is_gravityforms_supported() ) {
46
- $message = __('requires a minimum Gravity Forms version of ', self::$slug) . self::$min_gravityforms_version;
47
- }
48
-
49
- if (empty($message)) {
50
- return;
51
- }
52
- ?>
53
- <div class="error">
54
- <p>
55
- <?php _e('The plugin ', self::$slug); ?><strong><?php echo self::$name; ?></strong> <?php echo $message; ?><br />
56
- <?php _e('Please ',self::$slug); ?><a href="http://bit.ly/getgravityforms"><?php _e(' download the latest version ',self::$slug); ?></a><?php _e(' of Gravity Forms and try again.',self::$slug) ?>
57
- </p>
58
- </div>
59
- <?php
60
- }
61
-
62
- /*
63
- * Check if GF is installed
64
- */
65
- private static function is_gravityforms_installed(){
66
- return class_exists( 'RGForms' );
67
- }
68
-
69
- /*
70
- * Check if the installed version of GF is supported
71
- */
72
- private static function is_gravityforms_supported(){
73
- return self::check_gravityforms_version( self::$min_gravityforms_version,'>=' );
74
- }
75
-
76
- /*
77
- * Do a GF version compare
78
- */
79
- private static function check_gravityforms_version($version, $operator){
80
- if(class_exists('GFCommon')){
81
- return version_compare( GFCommon::$version, $version, $operator );
82
- }
83
- return false;
84
- }
85
-
86
- /*
87
- * Returns the url of the plugin's root folder
88
- */
89
- protected function get_base_url(){
90
- return plugins_url(null, __FILE__);
91
- }
92
-
93
- /*
94
- * Returns the physical path of the plugin's root folder
95
- */
96
- protected static function get_base_path(){
97
- return dirname( __FILE__ );
98
- }
99
-
100
- /**
101
- * starts_with
102
- * Tests if a text starts with an given string.
103
- *
104
- * @param string
105
- * @param string
106
- * @return bool
107
- */
108
- public static function starts_with($haystack, $needle){
109
- return strpos($haystack, $needle) === 0;
110
- }
111
-
112
- /*
113
- * returns true if a needle can be found in a haystack
114
- */
115
- public static function str_contains($haystack, $needle) {
116
- if (empty($haystack) || empty($needle))
117
- return false;
118
-
119
- $pos = strpos(strtolower($haystack), strtolower($needle));
120
-
121
- if ($pos === false)
122
- return false;
123
- else
124
- return true;
125
- }
126
- }
 
 
 
 
 
 
3
  Plugin Name: Gravity Forms + Custom Post Types
4
  Plugin URI: https://gravitywiz.com/
5
  Description: Map your Gravity-Forms-generated posts to a custom post type and/or custom taxonomies.
6
+ Version: 3.1.20
7
  Author: Gravity Wiz
8
  Author URI: https://gravitywiz.com/
9
  License: GPL2
10
  */
11
 
12
+ add_action( 'init', array( 'GFCPTAddon', 'init' ), 20 );
13
+ add_action( 'admin_notices', array( 'GFCPTAddon', 'admin_warnings' ), 20 );
14
 
15
  class GFCPTAddon {
16
 
17
+ private static $name = 'Gravity Forms + Custom Post Types';
18
+ private static $slug = 'GFCPTAddon';
19
+ private static $version = '3.1.20';
20
+ private static $min_gravityforms_version = '1.9.3';
21
+
22
+ //Plugin starting point. Will load appropriate files
23
+ public static function init() {
24
+
25
+ if ( self::is_gravityforms_installed() ) {
26
+
27
+ global $gf_cpt_addon;
28
+
29
+ //include the base class
30
+ require_once( self::get_base_path() . '/gfcptaddonbase.php' );
31
+
32
+ //only supports 1.5 and over
33
+ require_once( self::get_base_path() . '/gfcptaddon_1-5.php' );
34
+ $gf_cpt_addon = new GFCPTAddon1_5();
35
+
36
+ //start me up!
37
+ $gf_cpt_addon->init( __FILE__ );
38
+ }
39
+ }
40
+
41
+ //display admin warnings if GF is not the correct version or GF is not installed
42
+ public static function admin_warnings() {
43
+ if ( ! self::is_gravityforms_installed() ) {
44
+ $message = __( 'requires Gravity Forms to be installed.', self::$slug );
45
+ } elseif ( ! self::is_gravityforms_supported() ) {
46
+ $message = __( 'requires a minimum Gravity Forms version of ', self::$slug ) . self::$min_gravityforms_version;
47
+ }
48
+
49
+ if ( empty( $message ) ) {
50
+ return;
51
+ }
52
+ ?>
53
+ <div class="error">
54
+ <p>
55
+ <?php _e( 'The plugin ', self::$slug ); ?>
56
+ <strong><?php echo self::$name; ?></strong> <?php echo $message; ?><br/>
57
+ <?php _e( 'Please ', self::$slug ); ?><a
58
+ href="http://bit.ly/getgravityforms"><?php _e( ' download the latest version ', self::$slug ); ?></a><?php _e( ' of Gravity Forms and try again.', self::$slug ); ?>
59
+ </p>
60
+ </div>
61
+ <?php
62
+ }
63
+
64
+ /*
65
+ * Check if GF is installed
66
+ */
67
+ private static function is_gravityforms_installed() {
68
+ return class_exists( 'RGForms' );
69
+ }
70
+
71
+ /*
72
+ * Check if the installed version of GF is supported
73
+ */
74
+ private static function is_gravityforms_supported() {
75
+ return self::check_gravityforms_version( self::$min_gravityforms_version, '>=' );
76
+ }
77
+
78
+ /*
79
+ * Do a GF version compare
80
+ */
81
+ private static function check_gravityforms_version( $version, $operator ) {
82
+ if ( class_exists( 'GFCommon' ) ) {
83
+ return version_compare( GFCommon::$version, $version, $operator );
84
+ }
85
+
86
+ return false;
87
+ }
88
+
89
+ /*
90
+ * Returns the url of the plugin's root folder
91
+ */
92
+ protected function get_base_url() {
93
+ return plugins_url( null, __FILE__ );
94
+ }
95
+
96
+ /*
97
+ * Returns the physical path of the plugin's root folder
98
+ */
99
+ protected static function get_base_path() {
100
+ return dirname( __FILE__ );
101
+ }
102
+
103
+ /**
104
+ * starts_with
105
+ * Tests if a text starts with an given string.
106
+ *
107
+ * @param string
108
+ * @param string
109
+ *
110
+ * @return bool
111
+ */
112
+ public static function starts_with( $haystack, $needle ) {
113
+ return strpos( $haystack, $needle ) === 0;
114
+ }
115
+
116
+ /*
117
+ * returns true if a needle can be found in a haystack
118
+ */
119
+ public static function str_contains( $haystack, $needle ) {
120
+ if ( empty( $haystack ) || empty( $needle ) ) {
121
+ return false;
122
+ }
123
+
124
+ $pos = strpos( strtolower( $haystack ), strtolower( $needle ) );
125
+
126
+ if ( $pos === false ) {
127
+ return false;
128
+ } else {
129
+ return true;
130
+ }
131
+ }
132
+ }
gfcptaddon_1-5.php CHANGED
@@ -1,342 +1,358 @@
1
  <?php
2
 
3
- if (!class_exists('GFCPTAddon1_5')) {
4
-
5
- /*
6
- * GFCPT Addon class targetting version 1.5 of Gravity Forms
7
- */
8
- class GFCPTAddon1_5 extends GFCPTAddonBase {
9
-
10
- /*
11
- * Override. Include a couple more hooks
12
- */
13
- public function init() {
14
- //hook up the defaults
15
- parent::init();
16
-
17
- //then add these for 1.5...
18
- //add our advanced options to the form builder
19
- add_action('gform_field_standard_settings', array(&$this, 'render_field_standard_settings'), 10, 2);
20
- add_action('gform_field_advanced_settings', array(&$this, 'render_field_advanced_settings'), 10, 2);
21
-
22
- //include javascript for the form builder
23
- add_action('gform_editor_js', array(&$this, 'render_editor_js'));
24
-
25
- // filter to add a new tooltip
26
- add_filter('gform_tooltips', array(&$this, 'add_gf_tooltips'));
27
- }
28
-
29
- /*
30
- * Override. Gets the post type from our new field value
31
- */
32
- function get_field_post_type( $field ) {
33
- if ( isset( $field->populatePostType ) ) {
34
- return $field->populatePostType;
35
- }
36
-
37
- return false;
38
- }
39
-
40
- /*
41
- * Override. Gets the taxonomy from our new field value
42
- */
43
- function get_field_taxonomy( $field ) {
44
- if ( isset( $field->populateTaxonomy ) ) {
45
- return $field->populateTaxonomy;
46
- } elseif ( isset( $field->saveToTaxonomy ) ) {
47
- return $field->saveToTaxonomy;
48
- }
49
-
50
- return false;
51
- }
52
-
53
- /*
54
- * Override. Gets the custom post type from the post title field value
55
- */
56
- function get_form_post_type( $form ) {
57
- foreach ( $form['fields'] as $field ) {
58
- if ( $field['type'] == 'post_title' && $field['saveAsCPT'] )
59
- return $field['saveAsCPT'];
60
- }
61
- return false;
62
- }
63
-
64
- function get_form_parent_post_id( $form ) {
65
- foreach ( $form['fields'] as $field ) {
66
- if ( $field['type'] == 'select' && $field['setParentPost'] ) {
67
- $parent_id = RGForms::post('input_'.$field['id']);
68
- return $parent_id;
69
- }
70
- }
71
- return 0;
72
- }
73
-
74
- /*
75
- * Add tooltips for the new field values
76
- */
77
- function add_gf_tooltips($tooltips){
78
- $tooltips["form_field_populate_post_type"] = "<h6>Populate with a Post Type</h6>Check this box to populate this field from a specific post type.";
79
- $tooltips["form_field_set_parent_post"] = "<h6>Try to set parent</h6>If this is checked, and the form creates a post type, then the parent for the newly created post type will be set from the value of this field. Please note that this only works for heirarcical post typs e.g. pages";
80
- $tooltips["form_field_custom_taxonomy"] = "<h6>Populate with a Taxonomy</h6>Check this box to populate this field from a custom taxonomy.";
81
- $tooltips["form_field_custom_post_type"] = sprintf( '<h6>%s</h6> %s', __( 'Post Type', 'gravityforms' ), __( 'This form will create a WordPress post. Which post type should that post be assigned? Use this setting to specify the desired post type.' ) );
82
- $tooltips["form_field_save_to_taxonomy"] = "<h6>Save To Taxonomy</h6>Check this box to save this field to a specific custom taxonomy. Please note that the taxonomy must NOT be hierarchical.";
83
- $tooltips["form_field_tax_enhanced"] = "<h6>Enable Enhanced UI</h6>By selecting this option, this field will be tranformed into a 'tag input' control which makes it more user-friendly for selecting existing and capturing new taxonomies.";
84
- return $tooltips;
85
- }
86
-
87
- /*
88
- * Add some advanced settings to the fields
89
- */
90
- function render_field_standard_settings( $position, $form_id ) {
91
- if( $position == 50 ) {
92
- ?>
93
- <li class="custom_post_type_field_setting field_setting">
94
- <label for="field_populate_custom_post_type"><?php _e( 'Post Type', 'gravityforms' ); ?> <?php gform_tooltip("form_field_custom_post_type") ?></label>
95
- <select id="field_populate_custom_post_type" onchange="SetFieldProperty('saveAsCPT', jQuery(this).val());">
96
- <?php foreach( $this->get_post_types( $form_id ) as $post_type ): ?>
97
- <option value="<?php echo $post_type->name; ?>" <?php selected( 'post', $post_type->name ); ?>><?php echo $post_type->label; ?></option>
98
- <?php endforeach; ?>
99
- </select>
100
- </li>
101
- <?php
102
- }
103
-
104
- }
105
-
106
- /*
107
- * Add some advanced settings to the fields
108
- */
109
- function render_field_advanced_settings($position, $form_id){
110
- if($position == 50){
111
- ?>
112
- <li class="populate_with_taxonomy_field_setting field_setting" style="display:list-item;">
113
- <input type="checkbox" id="field_enable_populate_with_taxonomy" />
114
- <label for="field_enable_populate_with_taxonomy" class="inline">
115
- <?php _e("Populate with a Taxonomy", "gravityforms"); ?>
116
- </label>
117
- <?php gform_tooltip("form_field_custom_taxonomy") ?><br />
118
- <select id="field_populate_taxonomy" onchange="SetFieldProperty('populateTaxonomy', jQuery(this).val());" style="margin-top:10px; display:none;">
119
- <option value="" style="color:#999;">Select a Taxonomy</option>
120
- <?php foreach( $this->get_taxonomies( $form_id ) as $taxonomy ): ?>
121
- <option value="<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->label; ?></option>
122
- <?php endforeach; ?>
123
- </select>
124
- </li>
125
- <li class="populate_with_post_type_field_setting field_setting" style="display:list-item;">
126
- <input type="checkbox" class="toggle_setting" id="field_enable_populate_with_post_type" />
127
- <label for="field_enable_populate_with_post_type" class="inline">
128
- <?php _e("Populate with a Post Type", "gravityforms"); ?>
129
- </label>
130
- <?php gform_tooltip("form_field_populate_post_type") ?><br />
131
- <div style="margin-top:10px; display:none;">
132
- <select id="field_populate_post_type" onchange="SetFieldProperty('populatePostType', jQuery(this).val());">
133
- <option value="" style="color:#999;">Select a Post Type</option>
134
- <?php
135
- foreach( $this->get_post_types( $form_id ) as $post_type ): ?>
136
- <option value="<?php echo $post_type->name; ?>"><?php echo $post_type->label; ?></option>
137
- <?php endforeach; ?>
138
- </select>
139
- <input type="checkbox" class="check_parent" onclick="SetFieldProperty('setParentPost', this.checked);" id="field_set_parent_post" />
140
- <label for="field_set_parent_post" class="inline">
141
- <?php _e("Try to set parent", "gravityforms"); ?>
142
- </label>
143
- <?php gform_tooltip("form_field_set_parent_post") ?>
144
- </div>
145
- </li>
146
- <li class="save_to_taxonomy_field_setting field_setting" style="display:list-item;">
147
- <input type="checkbox" class="toggle_setting" id="field_enable_save_to_taxonomy" />
148
- <label for="field_enable_save_to_taxonomy" class="inline">
149
- <?php _e("Save To Taxonomy", "gravityforms"); ?>
150
- </label>
151
- <?php gform_tooltip("form_field_save_to_taxonomy") ?>
152
- <div style="margin-top:10px; display:none;">
153
- <select id="field_save_to_taxonomy" onchange="SetFieldProperty('saveToTaxonomy', jQuery(this).val());">
154
- <option value="" style="color:#999;">Select a Taxonomy</option>
155
- <?php foreach( $this->get_taxonomies( $form_id ) as $taxonomy ):
156
- if ( $taxonomy->hierarchical === false ): ?>
157
- <option value="<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->label; ?></option>
158
- <?php endif; ?>
159
- <?php endforeach; ?>
160
-
161
- </select>
162
- <input type="checkbox" class="check_tax_enhanced" onclick="SetFieldProperty('taxonomyEnhanced', this.checked);" id="field_tax_enhanced" />
163
- <label for="field_tax_enhanced" class="inline">
164
- <?php _e("Enable enhanced UI", "gravityforms"); ?>
165
- </label>
166
- <?php gform_tooltip("form_field_tax_enhanced") ?>
167
- </div>
168
- </li>
169
- <?php
170
- }
171
-
172
- }
173
-
174
- /*
175
- * render some custom JS to get the settings to work
176
- */
177
- function render_editor_js(){
178
- ?>
179
- <script type='text/javascript'>
180
-
181
- jQuery(document).bind("gform_load_field_settings", function(event, field, form){
182
- //only show taxonomy for selects and radios
183
- var valid_types = new Array('select', 'radio', 'checkbox', 'multiselect');
184
-
185
- //alert(field['type']);
186
-
187
- if(jQuery.inArray(field['type'], valid_types) != -1) {
188
-
189
- var $taxonomy_setting_container = jQuery(".populate_with_taxonomy_field_setting");
190
- //show the setting container!
191
- $taxonomy_setting_container.show();
192
-
193
- //get the saved taxonomy
194
- var populateTaxonomy = (typeof field['populateTaxonomy'] != 'undefined' && field['populateTaxonomy'] != '') ? field['populateTaxonomy'] : false;
195
-
196
- if (populateTaxonomy != false) {
197
- //check the checkbox if previously checked
198
- $taxonomy_setting_container.find("input:checkbox").attr("checked", "checked");
199
- //set the select and show
200
- $taxonomy_setting_container.find("select").val(populateTaxonomy).show();
201
- } else {
202
- $taxonomy_setting_container.find("input:checkbox").removeAttr("checked");
203
- $taxonomy_setting_container.find("select").val('').hide();
204
- }
205
-
206
- if (field['type'] == 'select') {
207
- var $populate_post_type_container = jQuery(".populate_with_post_type_field_setting");
208
- $populate_post_type_container.show();
209
-
210
- //get the saved post type
211
- var populatePostType = (typeof field['populatePostType'] != 'undefined' && field['populatePostType'] != '') ? field['populatePostType'] : false;
212
-
213
- if (populatePostType != false) {
214
- //check the checkbox if previously checked
215
- $populate_post_type_container.find("input.toggle_setting").attr("checked", "checked");
216
- //set the select
217
- $populate_post_type_container.find("select").val(populatePostType);
218
- //show the div
219
- $populate_post_type_container.find("div").show();
220
-
221
- //get the saved check for setting the parent post
222
- var setParent = (typeof field['setParentPost'] != 'undefined' && field['setParentPost'] != '') ? field['setParentPost'] : false;
223
- if (setParent != false) {
224
- $populate_post_type_container.find(".check_parent").attr("checked", "checked");
225
- } else {
226
- $populate_post_type_container.find(".check_parent").removeAttr("checked");
227
- }
228
- } else {
229
- /*$taxonomy_setting_container.find("input.toggle_setting").removeAttr("checked");
230
- $taxonomy_setting_container.find("select").val('');*/
231
- $populate_post_type_container.find("input.toggle_setting").removeAttr("checked");
232
- $populate_post_type_container.find("select").val('');
233
- }
234
-
235
- }
236
-
237
- } else if (field['type'] == 'post_title') {
238
-
239
- var $cpt_setting_container = jQuery(".custom_post_type_field_setting" ),
240
- saveAsCPT = ( typeof field['saveAsCPT'] != 'undefined' && field['saveAsCPT'] != '') ? field['saveAsCPT'] : 'post';
241
-
242
- //set the select and show
243
- $cpt_setting_container.show().find( 'select' ).val( saveAsCPT );
244
-
245
- } else if (field['type'] == 'text') {
246
- var $tax_setting_container = jQuery('.save_to_taxonomy_field_setting');
247
-
248
- $tax_setting_container.show();
249
-
250
- var saveToTax = (typeof field['saveToTaxonomy'] != 'undefined' && field['saveToTaxonomy'] != '') ? field['saveToTaxonomy'] : false;
251
-
252
- if (saveToTax != false) {
253
- //check the checkbox if previously checked
254
- $tax_setting_container.find("input.toggle_setting").attr("checked", "checked");
255
- //set the select
256
- $tax_setting_container.find("select").val(saveToTax);
257
- //show the div
258
- $tax_setting_container.find("div").show();
259
-
260
- //get the saved check for using enhanced UI
261
- var useEnhancedUI = (typeof field['taxonomyEnhanced'] != 'undefined' && field['taxonomyEnhanced'] != '') ? field['taxonomyEnhanced'] : false;
262
- if (useEnhancedUI != false) {
263
- $tax_setting_container.find(".check_tax_enhanced").attr("checked", "checked");
264
- } else {
265
- $tax_setting_container.find(".check_tax_enhanced").removeAttr("checked");
266
- }
267
-
268
- } else {
269
- $tax_setting_container.find("input.toggle_setting").removeAttr("checked");
270
- $tax_setting_container.find("div").hide();
271
- $tax_setting_container.find(".check_tax_enhanced").removeAttr("checked");
272
- $tax_setting_container.find("select").val('');
273
- }
274
- }
275
- });
276
-
277
- jQuery(".populate_with_taxonomy_field_setting input:checkbox").click(function() {
278
- var checked = jQuery(this).is(":checked");
279
- var $select = jQuery(this).parent(".populate_with_taxonomy_field_setting:first").find("select");
280
- if(checked){
281
- $select.slideDown();
282
-
283
- //uncheck post type
284
- var $pt_container = jQuery(this).parents("ul:first").find(".populate_with_post_type_field_setting:first");
285
- var $pt_check = $pt_container.find("input.toggle_setting");
286
- var $pt_div = $pt_container.find("div");
287
- if ($pt_check.is(":checked")) {
288
-
289
- SetFieldProperty('populatePostType','');
290
- $pt_div.slideUp();
291
- $pt_check.removeAttr('checked');
292
-
293
- }
294
-
295
- } else {
296
- SetFieldProperty('populateTaxonomy','');
297
- $select.slideUp();
298
- }
299
- });
300
-
301
- jQuery(".populate_with_post_type_field_setting .toggle_setting").click(function() {
302
- var checked = jQuery(this).is(":checked");
303
- var $div = jQuery(this).parent(".populate_with_post_type_field_setting:first").find("div");
304
- if(checked){
305
- $div.slideDown();
306
- //uncheck taxonomy
307
- var $tax_container = jQuery(this).parents("ul:first").find(".populate_with_taxonomy_field_setting:first");
308
- var $tax_check = $tax_container.find("input:checkbox");
309
- var $tax_select = $tax_container.find("select");
310
- if ($tax_check.is(":checked")) {
311
-
312
- SetFieldProperty('populateTaxonomy','');
313
- $tax_select.slideUp();
314
- $tax_check.removeAttr('checked');
315
-
316
- }
317
-
318
- } else {
319
- SetFieldProperty('populatePostType','');
320
- $div.slideUp();
321
- }
322
- });
323
-
324
- jQuery(".save_to_taxonomy_field_setting .toggle_setting").click(function() {
325
- var checked = jQuery(this).is(":checked");
326
- var $div = jQuery(this).parent(".save_to_taxonomy_field_setting:first").find("div");
327
- if(checked){
328
- $div.slideDown();
329
- } else {
330
- SetFieldProperty('saveToTaxonomy','');
331
- $div.slideUp();
332
- }
333
- });
334
-
335
- </script>
336
- <?php
337
- }
338
-
339
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
 
341
  }
342
- ?>
1
  <?php
2
 
3
+ if ( ! class_exists( 'GFCPTAddon1_5' ) ) {
4
+
5
+ /*
6
+ * GFCPT Addon class targetting version 1.5 of Gravity Forms
7
+ */
8
+
9
+ class GFCPTAddon1_5 extends GFCPTAddonBase {
10
+
11
+ /*
12
+ * Override. Include a couple more hooks
13
+ */
14
+ public function init() {
15
+ //hook up the defaults
16
+ parent::init();
17
+
18
+ //then add these for 1.5...
19
+ //add our advanced options to the form builder
20
+ add_action( 'gform_field_standard_settings', array( &$this, 'render_field_standard_settings' ), 10, 2 );
21
+ add_action( 'gform_field_advanced_settings', array( &$this, 'render_field_advanced_settings' ), 10, 2 );
22
+
23
+ //include javascript for the form builder
24
+ add_action( 'gform_editor_js', array( &$this, 'render_editor_js' ) );
25
+
26
+ // filter to add a new tooltip
27
+ add_filter( 'gform_tooltips', array( &$this, 'add_gf_tooltips' ) );
28
+ }
29
+
30
+ /*
31
+ * Override. Gets the post type from our new field value
32
+ */
33
+ function get_field_post_type( $field ) {
34
+ if ( isset( $field->populatePostType ) ) {
35
+ return $field->populatePostType;
36
+ }
37
+
38
+ return false;
39
+ }
40
+
41
+ /*
42
+ * Override. Gets the taxonomy from our new field value
43
+ */
44
+ function get_field_taxonomy( $field ) {
45
+ if ( isset( $field->populateTaxonomy ) ) {
46
+ return $field->populateTaxonomy;
47
+ } elseif ( isset( $field->saveToTaxonomy ) ) {
48
+ return $field->saveToTaxonomy;
49
+ }
50
+
51
+ return false;
52
+ }
53
+
54
+ /*
55
+ * Override. Gets the custom post type from the post title field value
56
+ */
57
+ function get_form_post_type( $form ) {
58
+ foreach ( $form['fields'] as $field ) {
59
+ if ( $field['type'] == 'post_title' && $field['saveAsCPT'] ) {
60
+ return $field['saveAsCPT'];
61
+ }
62
+ }
63
+
64
+ return false;
65
+ }
66
+
67
+ function get_form_parent_post_id( $form ) {
68
+ foreach ( $form['fields'] as $field ) {
69
+ if ( $field['type'] == 'select' && $field['setParentPost'] ) {
70
+ $parent_id = RGForms::post( 'input_' . $field['id'] );
71
+
72
+ return $parent_id;
73
+ }
74
+ }
75
+
76
+ return 0;
77
+ }
78
+
79
+ /*
80
+ * Add tooltips for the new field values
81
+ */
82
+ function add_gf_tooltips( $tooltips ) {
83
+ $tooltips['form_field_populate_post_type'] = '<h6>Populate with a Post Type</h6>Check this box to populate this field from a specific post type.';
84
+ $tooltips['form_field_set_parent_post'] = '<h6>Try to set parent</h6>If this is checked, and the form creates a post type, then the parent for the newly created post type will be set from the value of this field. Please note that this only works for heirarcical post typs e.g. pages';
85
+ $tooltips['form_field_custom_taxonomy'] = '<h6>Populate with a Taxonomy</h6>Check this box to populate this field from a custom taxonomy.';
86
+ $tooltips['form_field_custom_post_type'] = sprintf( '<h6>%s</h6> %s', __( 'Post Type', 'gravityforms' ), __( 'This form will create a WordPress post. Which post type should that post be assigned? Use this setting to specify the desired post type.' ) );
87
+ $tooltips['form_field_save_to_taxonomy'] = '<h6>Save To Taxonomy</h6>Check this box to save this field to a specific custom taxonomy. Please note that the taxonomy must NOT be hierarchical.';
88
+ $tooltips['form_field_tax_enhanced'] = "<h6>Enable Enhanced UI</h6>By selecting this option, this field will be tranformed into a 'tag input' control which makes it more user-friendly for selecting existing and capturing new taxonomies.";
89
+
90
+ return $tooltips;
91
+ }
92
+
93
+ /*
94
+ * Add some advanced settings to the fields
95
+ */
96
+ function render_field_standard_settings( $position, $form_id ) {
97
+ if ( $position == 50 ) {
98
+ ?>
99
+ <li class="custom_post_type_field_setting field_setting">
100
+ <label for="field_populate_custom_post_type"><?php _e( 'Post Type', 'gravityforms' ); ?><?php gform_tooltip( 'form_field_custom_post_type' ); ?></label>
101
+ <select id="field_populate_custom_post_type"
102
+ onchange="SetFieldProperty('saveAsCPT', jQuery(this).val());">
103
+ <?php foreach ( $this->get_post_types( $form_id ) as $post_type ) : ?>
104
+ <option value="<?php echo $post_type->name; ?>" <?php selected( 'post', $post_type->name ); ?>><?php echo $post_type->label; ?></option>
105
+ <?php endforeach; ?>
106
+ </select>
107
+ </li>
108
+ <?php
109
+ }
110
+
111
+ }
112
+
113
+ /*
114
+ * Add some advanced settings to the fields
115
+ */
116
+ function render_field_advanced_settings( $position, $form_id ) {
117
+ if ( $position == 50 ) {
118
+ ?>
119
+ <li class="populate_with_taxonomy_field_setting field_setting" style="display:list-item;">
120
+ <input type="checkbox" id="field_enable_populate_with_taxonomy"/>
121
+ <label for="field_enable_populate_with_taxonomy" class="inline">
122
+ <?php _e( 'Populate with a Taxonomy', 'gravityforms' ); ?>
123
+ </label>
124
+ <?php gform_tooltip( 'form_field_custom_taxonomy' ); ?><br/>
125
+ <select id="field_populate_taxonomy"
126
+ onchange="SetFieldProperty('populateTaxonomy', jQuery(this).val());"
127
+ style="margin-top:10px; display:none;">
128
+ <option value="" style="color:#999;">Select a Taxonomy</option>
129
+ <?php foreach ( $this->get_taxonomies( $form_id ) as $taxonomy ) : ?>
130
+ <option value="<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->label; ?></option>
131
+ <?php endforeach; ?>
132
+ </select>
133
+ </li>
134
+ <li class="populate_with_post_type_field_setting field_setting" style="display:list-item;">
135
+ <input type="checkbox" class="toggle_setting" id="field_enable_populate_with_post_type"/>
136
+ <label for="field_enable_populate_with_post_type" class="inline">
137
+ <?php _e( 'Populate with a Post Type', 'gravityforms' ); ?>
138
+ </label>
139
+ <?php gform_tooltip( 'form_field_populate_post_type' ); ?><br/>
140
+ <div style="margin-top:10px; display:none;">
141
+ <select id="field_populate_post_type"
142
+ onchange="SetFieldProperty('populatePostType', jQuery(this).val());">
143
+ <option value="" style="color:#999;">Select a Post Type</option>
144
+ <?php
145
+ foreach ( $this->get_post_types( $form_id ) as $post_type ) :
146
+ ?>
147
+ <option value="<?php echo $post_type->name; ?>"><?php echo $post_type->label; ?></option>
148
+ <?php endforeach; ?>
149
+ </select>
150
+ <input type="checkbox" class="check_parent"
151
+ onclick="SetFieldProperty('setParentPost', this.checked);" id="field_set_parent_post"/>
152
+ <label for="field_set_parent_post" class="inline">
153
+ <?php _e( 'Try to set parent', 'gravityforms' ); ?>
154
+ </label>
155
+ <?php gform_tooltip( 'form_field_set_parent_post' ); ?>
156
+ </div>
157
+ </li>
158
+ <li class="save_to_taxonomy_field_setting field_setting" style="display:list-item;">
159
+ <input type="checkbox" class="toggle_setting" id="field_enable_save_to_taxonomy"/>
160
+ <label for="field_enable_save_to_taxonomy" class="inline">
161
+ <?php _e( 'Save To Taxonomy', 'gravityforms' ); ?>
162
+ </label>
163
+ <?php gform_tooltip( 'form_field_save_to_taxonomy' ); ?>
164
+ <div style="margin-top:10px; display:none;">
165
+ <select id="field_save_to_taxonomy"
166
+ onchange="SetFieldProperty('saveToTaxonomy', jQuery(this).val());">
167
+ <option value="" style="color:#999;">Select a Taxonomy</option>
168
+ <?php
169
+ foreach ( $this->get_taxonomies( $form_id ) as $taxonomy ) :
170
+ if ( $taxonomy->hierarchical === false ) :
171
+ ?>
172
+ <option value="<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->label; ?></option>
173
+ <?php endif; ?>
174
+ <?php endforeach; ?>
175
+
176
+ </select>
177
+ <input type="checkbox" class="check_tax_enhanced"
178
+ onclick="SetFieldProperty('taxonomyEnhanced', this.checked);" id="field_tax_enhanced"/>
179
+ <label for="field_tax_enhanced" class="inline">
180
+ <?php _e( 'Enable enhanced UI', 'gravityforms' ); ?>
181
+ </label>
182
+ <?php gform_tooltip( 'form_field_tax_enhanced' ); ?>
183
+ </div>
184
+ </li>
185
+ <?php
186
+ }
187
+
188
+ }
189
+
190
+ /*
191
+ * render some custom JS to get the settings to work
192
+ */
193
+ function render_editor_js() {
194
+ ?>
195
+ <script type='text/javascript'>
196
+
197
+ jQuery(document).bind("gform_load_field_settings", function (event, field, form) {
198
+ //only show taxonomy for selects and radios
199
+ var valid_types = new Array('select', 'radio', 'checkbox', 'multiselect');
200
+
201
+ //alert(field['type']);
202
+
203
+ if (jQuery.inArray(field['type'], valid_types) != -1) {
204
+
205
+ var $taxonomy_setting_container = jQuery(".populate_with_taxonomy_field_setting");
206
+ //show the setting container!
207
+ $taxonomy_setting_container.show();
208
+
209
+ //get the saved taxonomy
210
+ var populateTaxonomy = (typeof field['populateTaxonomy'] != 'undefined' && field['populateTaxonomy'] != '') ? field['populateTaxonomy'] : false;
211
+
212
+ if (populateTaxonomy != false) {
213
+ //check the checkbox if previously checked
214
+ $taxonomy_setting_container.find("input:checkbox").attr("checked", "checked");
215
+ //set the select and show
216
+ $taxonomy_setting_container.find("select").val(populateTaxonomy).show();
217
+ } else {
218
+ $taxonomy_setting_container.find("input:checkbox").removeAttr("checked");
219
+ $taxonomy_setting_container.find("select").val('').hide();
220
+ }
221
+
222
+ if (field['type'] == 'select') {
223
+ var $populate_post_type_container = jQuery(".populate_with_post_type_field_setting");
224
+ $populate_post_type_container.show();
225
+
226
+ //get the saved post type
227
+ var populatePostType = (typeof field['populatePostType'] != 'undefined' && field['populatePostType'] != '') ? field['populatePostType'] : false;
228
+
229
+ if (populatePostType != false) {
230
+ //check the checkbox if previously checked
231
+ $populate_post_type_container.find("input.toggle_setting").attr("checked", "checked");
232
+ //set the select
233
+ $populate_post_type_container.find("select").val(populatePostType);
234
+ //show the div
235
+ $populate_post_type_container.find("div").show();
236
+
237
+ //get the saved check for setting the parent post
238
+ var setParent = (typeof field['setParentPost'] != 'undefined' && field['setParentPost'] != '') ? field['setParentPost'] : false;
239
+ if (setParent != false) {
240
+ $populate_post_type_container.find(".check_parent").attr("checked", "checked");
241
+ } else {
242
+ $populate_post_type_container.find(".check_parent").removeAttr("checked");
243
+ }
244
+ } else {
245
+ /*$taxonomy_setting_container.find("input.toggle_setting").removeAttr("checked");
246
+ $taxonomy_setting_container.find("select").val('');*/
247
+ $populate_post_type_container.find("input.toggle_setting").removeAttr("checked");
248
+ $populate_post_type_container.find("select").val('');
249
+ }
250
+
251
+ }
252
+
253
+ } else if (field['type'] == 'post_title') {
254
+
255
+ var $cpt_setting_container = jQuery(".custom_post_type_field_setting"),
256
+ saveAsCPT = (typeof field['saveAsCPT'] != 'undefined' && field['saveAsCPT'] != '') ? field['saveAsCPT'] : 'post';
257
+
258
+ //set the select and show
259
+ $cpt_setting_container.show().find('select').val(saveAsCPT);
260
+
261
+ } else if (field['type'] == 'text') {
262
+ var $tax_setting_container = jQuery('.save_to_taxonomy_field_setting');
263
+
264
+ $tax_setting_container.show();
265
+
266
+ var saveToTax = (typeof field['saveToTaxonomy'] != 'undefined' && field['saveToTaxonomy'] != '') ? field['saveToTaxonomy'] : false;
267
+
268
+ if (saveToTax != false) {
269
+ //check the checkbox if previously checked
270
+ $tax_setting_container.find("input.toggle_setting").attr("checked", "checked");
271
+ //set the select
272
+ $tax_setting_container.find("select").val(saveToTax);
273
+ //show the div
274
+ $tax_setting_container.find("div").show();
275
+
276
+ //get the saved check for using enhanced UI
277
+ var useEnhancedUI = (typeof field['taxonomyEnhanced'] != 'undefined' && field['taxonomyEnhanced'] != '') ? field['taxonomyEnhanced'] : false;
278
+ if (useEnhancedUI != false) {
279
+ $tax_setting_container.find(".check_tax_enhanced").attr("checked", "checked");
280
+ } else {
281
+ $tax_setting_container.find(".check_tax_enhanced").removeAttr("checked");
282
+ }
283
+
284
+ } else {
285
+ $tax_setting_container.find("input.toggle_setting").removeAttr("checked");
286
+ $tax_setting_container.find("div").hide();
287
+ $tax_setting_container.find(".check_tax_enhanced").removeAttr("checked");
288
+ $tax_setting_container.find("select").val('');
289
+ }
290
+ }
291
+ });
292
+
293
+ jQuery(".populate_with_taxonomy_field_setting input:checkbox").click(function () {
294
+ var checked = jQuery(this).is(":checked");
295
+ var $select = jQuery(this).parent(".populate_with_taxonomy_field_setting:first").find("select");
296
+ if (checked) {
297
+ $select.slideDown();
298
+
299
+ //uncheck post type
300
+ var $pt_container = jQuery(this).parents("ul:first").find(".populate_with_post_type_field_setting:first");
301
+ var $pt_check = $pt_container.find("input.toggle_setting");
302
+ var $pt_div = $pt_container.find("div");
303
+ if ($pt_check.is(":checked")) {
304
+
305
+ SetFieldProperty('populatePostType', '');
306
+ $pt_div.slideUp();
307
+ $pt_check.removeAttr('checked');
308
+
309
+ }
310
+
311
+ } else {
312
+ SetFieldProperty('populateTaxonomy', '');
313
+ $select.slideUp();
314
+ }
315
+ });
316
+
317
+ jQuery(".populate_with_post_type_field_setting .toggle_setting").click(function () {
318
+ var checked = jQuery(this).is(":checked");
319
+ var $div = jQuery(this).parent(".populate_with_post_type_field_setting:first").find("div");
320
+ if (checked) {
321
+ $div.slideDown();
322
+ //uncheck taxonomy
323
+ var $tax_container = jQuery(this).parents("ul:first").find(".populate_with_taxonomy_field_setting:first");
324
+ var $tax_check = $tax_container.find("input:checkbox");
325
+ var $tax_select = $tax_container.find("select");
326
+ if ($tax_check.is(":checked")) {
327
+
328
+ SetFieldProperty('populateTaxonomy', '');
329
+ $tax_select.slideUp();
330
+ $tax_check.removeAttr('checked');
331
+
332
+ }
333
+
334
+ } else {
335
+ SetFieldProperty('populatePostType', '');
336
+ $div.slideUp();
337
+ }
338
+ });
339
+
340
+ jQuery(".save_to_taxonomy_field_setting .toggle_setting").click(function () {
341
+ var checked = jQuery(this).is(":checked");
342
+ var $div = jQuery(this).parent(".save_to_taxonomy_field_setting:first").find("div");
343
+ if (checked) {
344
+ $div.slideDown();
345
+ } else {
346
+ SetFieldProperty('saveToTaxonomy', '');
347
+ $div.slideUp();
348
+ }
349
+ });
350
+
351
+ </script>
352
+ <?php
353
+ }
354
+
355
+ }
356
 
357
  }
358
+ ?>
gfcptaddonbase.php CHANGED
@@ -1,17 +1,18 @@
1
  <?php
2
 
3
- if (!class_exists('GFCPTAddonBase')) {
4
 
5
  /*
6
  * Base class for the GFCPT Addon. All common code is in here and differences per version are overrided
7
  */
 
8
  class GFCPTAddonBase {
9
 
10
- protected $_has_tag_inputs = false;
11
- protected $_included_js;
12
- protected $_tag_inputs = array();
13
- protected $_tag_map = array();
14
- protected $_tag_terms = array();
15
 
16
 
17
  /*
@@ -19,39 +20,42 @@ if (!class_exists('GFCPTAddonBase')) {
19
  */
20
  public function init() {
21
  //alter the way forms are rendered by inserting taxomony dropdowns,radios and checkboxes
22
- add_filter('gform_pre_render' , array(&$this, 'setup_form') );
23
 
24
  //alter the way forms are rendered by the admin too!
25
- add_filter('gform_admin_pre_render' , array(&$this, 'setup_form') );
26
 
27
  //alter the form for submission - this is mainly for checkboxes
28
- add_filter('gform_pre_submission_filter', array(&$this, 'setup_form') );
29
 
30
  add_filter( 'gform_form_post_get_meta', array( $this, 'setup_form_on_export' ) );
31
 
32
  //set the post type when saving a post
33
- add_filter("gform_post_data", array(&$this, 'set_post_values'), 10, 2);
34
 
35
- if( class_exists( 'gform_update_post' ) ) {
36
- remove_filter( 'gform_after_submission', array( 'gform_update_post', 'delete_custom_taxonomy_save' ), 1, 2 );
 
 
 
37
  }
38
 
39
  //intercept the form save and save any taxonomy links if needed
40
- add_action( 'gform_after_create_post', array( $this, 'save_taxonomies'), 10, 3 );
41
 
42
  //enqueue scripts to the page
43
- add_action( 'gform_enqueue_scripts', array( $this, 'enqueue_form_scripts' ), 10, 2 );
44
  add_action( 'gform_register_init_scripts', array( $this, 'register_init_scripts' ), 10, 2 );
45
 
46
- add_filter("gform_preview_styles", array(&$this, 'preview_print_styles'), 10, 2);
47
 
48
- add_filter( 'gform_entry_field_value', array( $this, 'display_term_name_on_entry_detail' ), 10, 4 );
49
  add_filter( 'gform_entries_field_value', array( $this, 'display_term_name_on_entry_list' ), 10, 4 );
50
- add_filter( 'gform_export_field_value', array( $this, 'display_term_name_on_export' ), 10, 4 );
51
 
52
- add_filter( 'gform_entry_field_value', array( $this, 'display_post_title_on_entry_detail' ), 10, 4 );
53
  add_filter( 'gform_entries_field_value', array( $this, 'display_post_title_on_entry_list' ), 10, 4 );
54
- add_filter( 'gform_export_field_value', array( $this, 'display_post_title_on_export' ), 10, 4 );
55
 
56
 
57
  }
@@ -61,36 +65,40 @@ if (!class_exists('GFCPTAddonBase')) {
61
  */
62
  function setup_form( $form ) {
63
 
64
- //loop thru all fields
65
- foreach($form['fields'] as &$field) {
 
66
 
67
- //see if the field is using a taxonomy
68
- $taxonomy = $this->get_field_taxonomy( $field );
69
 
70
- if($taxonomy) {
71
- $this->setup_taxonomy_field( $field, $taxonomy );
72
- continue;
73
- }
74
 
75
- //if its a select then check if we have set a post type
76
- if ($field['type'] == 'select') {
 
 
77
 
78
- $post_type = $this->get_field_post_type( $field );
 
79
 
80
- if ($post_type) {
81
- $this->setup_post_type_field( $field, $post_type );
82
- continue;
83
- }
84
 
 
 
 
 
 
 
85
  }
86
- }
87
 
88
- return $form;
89
  }
90
 
91
  function setup_form_on_export( $form ) {
92
 
93
- if( in_array( rgpost( 'action' ), array( 'rg_select_export_form', 'gf_process_export' ) ) ) {
94
  $form = $this->setup_form( $form );
95
  }
96
 
@@ -99,23 +107,27 @@ if (!class_exists('GFCPTAddonBase')) {
99
 
100
  function register_init_scripts( $form ) {
101
 
102
- $inputs = array();
103
  $taxonomies = array();
104
 
105
- foreach( $form['fields'] as $field ) {
106
 
107
- if( ! $this->has_tax_enhanced_ui( $field ) ) {
108
  continue;
109
  }
110
 
111
- $inputs[] = array( 'input' => sprintf( '#input_%d_%d', $form['id'], $field->id ), 'taxonomy' => $field->saveToTaxonomy );
112
- if( ! array_key_exists( $field->saveToTaxonomy, $taxonomies ) ) {
 
 
 
 
113
  $taxonomies[ $field->saveToTaxonomy ] = get_terms( $field->saveToTaxonomy, 'orderby=name&hide_empty=0&fields=names' );
114
  }
115
 
116
  }
117
 
118
- if( empty( $inputs ) ) {
119
  return;
120
  }
121
 
@@ -142,37 +154,37 @@ if (!class_exists('GFCPTAddonBase')) {
142
 
143
  function enqueue_form_scripts( $form ) {
144
 
145
- if( ! $this->has_tax_enhanced_ui( $form ) ) {
146
  return;
147
  }
148
 
149
- wp_register_style( 'gfcpt_jquery_ui_theme', plugins_url( 'css/custom/jquery-ui-1.8.16.custom.css' , __FILE__ ) );
150
  wp_enqueue_style( 'gfcpt_jquery_ui_theme' );
151
 
152
- wp_register_style( 'gfcpt_tagit_css', plugins_url( 'css/jquery.tagit.css' , __FILE__ ) );
153
  wp_enqueue_style( 'gfcpt_tagit_css' );
154
 
155
  wp_enqueue_script( 'jquery-ui-core' );
156
  wp_enqueue_script( 'jquery-ui-widget' );
157
  wp_enqueue_script( 'jquery-ui-autocomplete' );
158
 
159
- wp_register_script( 'gfcpt_tagit_js', plugins_url( 'js/tag-it.js' , __FILE__ ), array( 'jquery-ui-widget' ) );
160
  wp_enqueue_script( 'gfcpt_tagit_js' );
161
 
162
- wp_register_script( 'gfcpt_tagit_init_js', plugins_url( 'js/tag-it.init.js' , __FILE__ ), array('gfcpt_tagit_js' ), false, true );
163
  wp_enqueue_script( 'gfcpt_tagit_init_js' );
164
 
165
  }
166
 
167
  function has_tax_enhanced_ui( $form_or_field ) {
168
 
169
- if( is_a( $form_or_field, 'GF_Field' ) ) {
170
- if( $form_or_field->get_input_type() == 'text' && $form_or_field->saveToTaxonomy && $form_or_field->taxonomyEnhanced ) {
171
  return true;
172
  }
173
  } else {
174
- foreach( $form_or_field['fields'] as $field ) {
175
- if( $this->has_tax_enhanced_ui( $field ) ) {
176
  return true;
177
  }
178
  }
@@ -192,19 +204,21 @@ if (!class_exists('GFCPTAddonBase')) {
192
  function set_post_values( $post_data, $form ) {
193
 
194
  //check if the form saves a post
195
- if ( $this->is_form_a_post_form($form) ) {
196
  $target_post_type = $this->get_form_post_type( $form );
197
 
198
- if ($target_post_type)
199
  $post_data["post_type"] = $target_post_type;
 
200
 
201
  //then check if we have set a parent
202
  $parent_post_id = $this->get_form_parent_post_id( $form );
203
 
204
- if ($parent_post_id > 0) {
205
- $post_data["post_parent"] = $parent_post_id;
206
  }
207
  }
 
208
  return $post_data;
209
 
210
  }
@@ -213,12 +227,21 @@ if (!class_exists('GFCPTAddonBase')) {
213
  * Checks if a form includes a 'post field'
214
  */
215
  function is_form_a_post_form( $form ) {
216
- foreach ($form["fields"] as $field) {
217
- if(in_array($field["type"],
218
- array("post_category","post_title","post_content",
219
- "post_excerpt","post_tags","post_custom_fields","post_image")))
 
 
 
 
 
 
 
220
  return true;
 
221
  }
 
222
  return false;
223
  }
224
 
@@ -279,23 +302,26 @@ if (!class_exists('GFCPTAddonBase')) {
279
  * setup a field if it is linked to a post type
280
  */
281
  function setup_post_type_field( &$field, $post_type ) {
282
- $first_choice = $field['choices'][0]['text'];
283
- $field['choices'] = $this->load_post_type_choices( $post_type, $first_choice, $field );
284
  $field->enableChoiceValue = true;
285
  }
286
 
287
- function load_post_type_choices($post_type, $first_choice = '', $field ) {
288
  $posts = $this->load_posts_hierarchical( $post_type, $field->formId, $field->id );
289
- if ($first_choice === '' || $first_choice === 'First Choice'){
290
  // if no default option is specified, dynamically create based on post type name
291
- $post_type_obj = get_post_type_object($post_type);
292
- $choices[] = array('text' => "-- select a {$post_type_obj->labels->singular_name} --", 'value' => '');
 
 
 
293
  } else {
294
- $choices[] = array('text' => $first_choice, 'value' => '');
295
  }
296
 
297
- foreach($posts as $post) {
298
- $choices[] = array('value' => $post->ID, 'text' => $post->post_title);
299
  }
300
 
301
  return $choices;
@@ -305,28 +331,30 @@ if (!class_exists('GFCPTAddonBase')) {
305
  * Get a hierarchical list of posts
306
  */
307
  function load_posts_hierarchical( $post_type, $form_id, $field_id ) {
308
- $args = gf_apply_filters( 'gfcpt_get_posts_args', array( $form_id, $field_id ), array(
309
  'post_type' => $post_type,
310
- 'numberposts' => -1,
311
  'orderby' => $post_type == 'page' ? 'menu_order' : 'title',
312
  'order' => $post_type == 'page' ? null : 'ASC',
313
  'post_status' => 'publish'
314
  ) );
315
  $posts = get_posts( $args );
 
316
  return $this->walk_posts( $posts );
317
  }
318
 
319
  /*
320
  * Helper function to recursively 'walk' the posts
321
  */
322
- function walk_posts( $input_array, $parent_id=0, &$out_array=array(), $level=0 ){
323
  foreach ( $input_array as $item ) {
324
  if ( $item->post_parent == $parent_id ) {
325
- $item->post_title = str_repeat('--', $level) . $item->post_title;
326
- $out_array[] = $item;
327
- $this->walk_posts( $input_array, $item->ID, $out_array, $level+1 );
328
  }
329
  }
 
330
  return $out_array;
331
  }
332
 
@@ -335,8 +363,8 @@ if (!class_exists('GFCPTAddonBase')) {
335
  */
336
  function setup_taxonomy_field( &$field, $taxonomy ) {
337
 
338
- $first_choice = rgars( $field, 'choices/0/text' );
339
- $field['choices'] = $this->load_taxonomy_choices( $taxonomy, $field['type'], $first_choice, $field );
340
  $field->enableChoiceValue = true;
341
 
342
  //now check if we are dealing with a checkbox list and do some extra magic
@@ -346,15 +374,15 @@ if (!class_exists('GFCPTAddonBase')) {
346
 
347
  $counter = 0;
348
  //recreate the inputs so they are captured correctly on form submission
349
- foreach( $field['choices'] as $choice ) {
350
 
351
  //thanks to Peter Schuster for the help on this fix
352
- $counter++;
353
  if ( $counter % 10 == 0 ) {
354
- $counter++;
355
  }
356
 
357
- $id = $field['id'] . '.' . $counter;
358
  $inputs[] = array( 'label' => $choice['text'], 'id' => $id );
359
  }
360
 
@@ -366,29 +394,36 @@ if (!class_exists('GFCPTAddonBase')) {
366
  /*
367
  * Load any taxonomy terms
368
  */
369
- function load_taxonomy_choices($taxonomy, $type, $first_choice = '', $field ) {
370
  $choices = array();
371
 
372
- if ( in_array( $field->get_input_type(), gf_apply_filters( array( 'gfcpt_hierarchical_display', $field->formId, $field->fieldId ), array( 'select', 'multiselect' ) ) ) ) {
 
 
 
 
373
 
374
  $terms = $this->load_taxonomy_hierarchical( $taxonomy, $field );
375
 
376
- if( $field->get_input_type() == 'select' ) {
377
  if ( $first_choice !== '' && $first_choice !== 'First Choice' && empty( $field->placeholder ) ) {
378
  // if no default option is specified, dynamically create based on taxonomy name
379
- $taxonomy = get_taxonomy($taxonomy);
380
- $choices[] = array('text' => "-- select a {$taxonomy->labels->singular_name} --", 'value' => '');
 
 
 
381
  }
382
  }
383
 
384
  } else {
385
- $terms = get_terms($taxonomy, 'orderby=name&hide_empty=0');
386
  }
387
 
388
- if ( !array_key_exists("errors",$terms) ) {
389
- foreach($terms as $term) {
390
- $choices[] = array('value' => $term->term_id, 'text' => $term->name);
391
- }
392
  }
393
 
394
  return $choices;
@@ -400,18 +435,19 @@ if (!class_exists('GFCPTAddonBase')) {
400
  function load_taxonomy_hierarchical( $taxonomy, $field ) {
401
 
402
  $args = gf_apply_filters( 'gfcpt_taxonomy_args', array( $field->formId, $field->id ), array(
403
- 'taxonomy' => $taxonomy,
404
- 'orderby' => 'name',
405
- 'hierarchical' => 1,
406
- 'hide_empty' => 0
407
  ), $field );
408
 
409
- $terms = get_categories( $args );
410
 
411
- if ( array_key_exists("errors",$terms) ) {
412
  return $terms;
413
  } else {
414
  $parent = isset( $args['parent'] ) ? $args['parent'] : 0;
 
415
  return $this->walk_terms( $terms, $parent );
416
  }
417
 
@@ -420,14 +456,15 @@ if (!class_exists('GFCPTAddonBase')) {
420
  /*
421
  * Helper function to recursively 'walk' the taxonomy terms
422
  */
423
- function walk_terms( $input_array, $parent_id=0, &$out_array=array(), $level=0 ){
424
  foreach ( $input_array as $item ) {
425
  if ( $item->parent == $parent_id ) {
426
- $item->name = str_repeat('--', $level) . $item->name;
427
- $out_array[] = $item;
428
- $this->walk_terms( $input_array, $item->term_id, $out_array, $level+1 );
429
  }
430
  }
 
431
  return $out_array;
432
  }
433
 
@@ -441,11 +478,13 @@ if (!class_exists('GFCPTAddonBase')) {
441
 
442
  $this->delete_custom_taxonomies( $entry, $form );
443
 
444
- foreach( $form['fields'] as &$field ) {
445
 
446
  $taxonomy = $this->get_field_taxonomy( $field );
447
 
448
- if ( !$taxonomy ) continue;
 
 
449
 
450
  $this->save_taxonomy_field( $field, $entry, $taxonomy );
451
  }
@@ -455,22 +494,17 @@ if (!class_exists('GFCPTAddonBase')) {
455
  /**
456
  * Remove Custom Taxonomies
457
  *
 
458
  * @author ekaj
459
- * @return void
460
  */
461
  public function delete_custom_taxonomies( $entry, $form ) {
462
  // Check if the submission contains a WordPress post
463
- if (! empty($entry['post_id']) )
464
- {
465
- foreach( $form['fields'] as &$field )
466
- {
467
- $taxonomy = false;
468
- if ( array_key_exists('populateTaxonomy', $field) ) {
469
- $taxonomy = $field['populateTaxonomy'];
470
- }
471
 
472
  if ( $taxonomy ) {
473
- wp_set_object_terms( $entry['post_id'], NULL, $taxonomy );
474
  }
475
  }
476
  }
@@ -483,13 +517,13 @@ if (!class_exists('GFCPTAddonBase')) {
483
 
484
  $terms = array();
485
 
486
- switch( $field->get_input_type() ) {
487
  case 'multiselect':
488
 
489
  $value = $entry[ $field->id ];
490
  $terms = json_decode( $value );
491
 
492
- if( ! is_array( $terms ) ) {
493
  $terms = explode( ',', $value );
494
  }
495
 
@@ -527,9 +561,9 @@ if (!class_exists('GFCPTAddonBase')) {
527
 
528
  $return = $term_id;
529
 
530
- if( $field->populateTaxonomy && ! empty( $term_id ) ) {
531
  $term = get_term( (int) $term_id, $field->populateTaxonomy );
532
- if( ! is_wp_error( $term ) ) {
533
  $return = $term->name;
534
  }
535
  }
@@ -543,7 +577,7 @@ if (!class_exists('GFCPTAddonBase')) {
543
 
544
  function display_term_name_on_entry_list( $value, $form_id, $field_id ) {
545
 
546
- if( is_numeric( $field_id ) ) {
547
  $field = GFFormsModel::get_field( GFAPI::get_form( $form_id ), $field_id );
548
  $value = $this->get_term_name( $value, $field );
549
  }
@@ -557,8 +591,9 @@ if (!class_exists('GFCPTAddonBase')) {
557
 
558
  function get_post_title( $post_id, $field ) {
559
 
560
- if( $field->populatePostType && ! empty( $post_id ) ) {
561
  $post = get_post( $post_id );
 
562
  return $post ? $post->post_title : $post_id;
563
  }
564
 
@@ -571,7 +606,7 @@ if (!class_exists('GFCPTAddonBase')) {
571
 
572
  function display_post_title_on_entry_list( $value, $form_id, $field_id ) {
573
 
574
- if( is_numeric( $field_id ) ) {
575
  $field = GFFormsModel::get_field( GFAPI::get_form( $form_id ), $field_id );
576
  $value = $this->get_post_title( $value, $field );
577
  }
1
  <?php
2
 
3
+ if ( ! class_exists( 'GFCPTAddonBase' ) ) {
4
 
5
  /*
6
  * Base class for the GFCPT Addon. All common code is in here and differences per version are overrided
7
  */
8
+
9
  class GFCPTAddonBase {
10
 
11
+ protected $_has_tag_inputs = false;
12
+ protected $_included_js;
13
+ protected $_tag_inputs = array();
14
+ protected $_tag_map = array();
15
+ protected $_tag_terms = array();
16
 
17
 
18
  /*
20
  */
21
  public function init() {
22
  //alter the way forms are rendered by inserting taxomony dropdowns,radios and checkboxes
23
+ add_filter( 'gform_pre_render', array( &$this, 'setup_form' ) );
24
 
25
  //alter the way forms are rendered by the admin too!
26
+ add_filter( 'gform_admin_pre_render', array( &$this, 'setup_form' ) );
27
 
28
  //alter the form for submission - this is mainly for checkboxes
29
+ add_filter( 'gform_pre_submission_filter', array( &$this, 'setup_form' ) );
30
 
31
  add_filter( 'gform_form_post_get_meta', array( $this, 'setup_form_on_export' ) );
32
 
33
  //set the post type when saving a post
34
+ add_filter( "gform_post_data", array( &$this, 'set_post_values' ), 10, 2 );
35
 
36
+ if ( class_exists( 'gform_update_post' ) ) {
37
+ remove_filter( 'gform_after_submission', array(
38
+ 'gform_update_post',
39
+ 'delete_custom_taxonomy_save'
40
+ ), 1, 2 );
41
  }
42
 
43
  //intercept the form save and save any taxonomy links if needed
44
+ add_action( 'gform_after_create_post', array( $this, 'save_taxonomies' ), 10, 3 );
45
 
46
  //enqueue scripts to the page
47
+ add_action( 'gform_enqueue_scripts', array( $this, 'enqueue_form_scripts' ), 10, 2 );
48
  add_action( 'gform_register_init_scripts', array( $this, 'register_init_scripts' ), 10, 2 );
49
 
50
+ add_filter( "gform_preview_styles", array( &$this, 'preview_print_styles' ), 10, 2 );
51
 
52
+ add_filter( 'gform_entry_field_value', array( $this, 'display_term_name_on_entry_detail' ), 10, 4 );
53
  add_filter( 'gform_entries_field_value', array( $this, 'display_term_name_on_entry_list' ), 10, 4 );
54
+ add_filter( 'gform_export_field_value', array( $this, 'display_term_name_on_export' ), 10, 4 );
55
 
56
+ add_filter( 'gform_entry_field_value', array( $this, 'display_post_title_on_entry_detail' ), 10, 4 );
57
  add_filter( 'gform_entries_field_value', array( $this, 'display_post_title_on_entry_list' ), 10, 4 );
58
+ add_filter( 'gform_export_field_value', array( $this, 'display_post_title_on_export' ), 10, 4 );
59
 
60
 
61
  }
65
  */
66
  function setup_form( $form ) {
67
 
68
+ if ( empty( $form['fields'] ) ) {
69
+ return $form;
70
+ }
71
 
72
+ //loop thru all fields
73
+ foreach ( $form['fields'] as &$field ) {
74
 
75
+ //see if the field is using a taxonomy
76
+ $taxonomy = $this->get_field_taxonomy( $field );
 
 
77
 
78
+ if ( $taxonomy ) {
79
+ $this->setup_taxonomy_field( $field, $taxonomy );
80
+ continue;
81
+ }
82
 
83
+ //if its a select then check if we have set a post type
84
+ if ( $field['type'] == 'select' ) {
85
 
86
+ $post_type = $this->get_field_post_type( $field );
 
 
 
87
 
88
+ if ( $post_type ) {
89
+ $this->setup_post_type_field( $field, $post_type );
90
+ continue;
91
+ }
92
+
93
+ }
94
  }
 
95
 
96
+ return $form;
97
  }
98
 
99
  function setup_form_on_export( $form ) {
100
 
101
+ if ( in_array( rgpost( 'action' ), array( 'rg_select_export_form', 'gf_process_export' ) ) ) {
102
  $form = $this->setup_form( $form );
103
  }
104
 
107
 
108
  function register_init_scripts( $form ) {
109
 
110
+ $inputs = array();
111
  $taxonomies = array();
112
 
113
+ foreach ( $form['fields'] as $field ) {
114
 
115
+ if ( ! $this->has_tax_enhanced_ui( $field ) ) {
116
  continue;
117
  }
118
 
119
+ $inputs[] = array(
120
+ 'input' => sprintf( '#input_%d_%d', $form['id'], $field->id ),
121
+ 'taxonomy' => $field->saveToTaxonomy
122
+ );
123
+
124
+ if ( ! array_key_exists( $field->saveToTaxonomy, $taxonomies ) ) {
125
  $taxonomies[ $field->saveToTaxonomy ] = get_terms( $field->saveToTaxonomy, 'orderby=name&hide_empty=0&fields=names' );
126
  }
127
 
128
  }
129
 
130
+ if ( empty( $inputs ) ) {
131
  return;
132
  }
133
 
154
 
155
  function enqueue_form_scripts( $form ) {
156
 
157
+ if ( ! $this->has_tax_enhanced_ui( $form ) ) {
158
  return;
159
  }
160
 
161
+ wp_register_style( 'gfcpt_jquery_ui_theme', plugins_url( 'css/custom/jquery-ui-1.8.16.custom.css', __FILE__ ) );
162
  wp_enqueue_style( 'gfcpt_jquery_ui_theme' );
163
 
164
+ wp_register_style( 'gfcpt_tagit_css', plugins_url( 'css/jquery.tagit.css', __FILE__ ) );
165
  wp_enqueue_style( 'gfcpt_tagit_css' );
166
 
167
  wp_enqueue_script( 'jquery-ui-core' );
168
  wp_enqueue_script( 'jquery-ui-widget' );
169
  wp_enqueue_script( 'jquery-ui-autocomplete' );
170
 
171
+ wp_register_script( 'gfcpt_tagit_js', plugins_url( 'js/tag-it.js', __FILE__ ), array( 'jquery-ui-widget' ) );
172
  wp_enqueue_script( 'gfcpt_tagit_js' );
173
 
174
+ wp_register_script( 'gfcpt_tagit_init_js', plugins_url( 'js/tag-it.init.js', __FILE__ ), array( 'gfcpt_tagit_js' ), false, true );
175
  wp_enqueue_script( 'gfcpt_tagit_init_js' );
176
 
177
  }
178
 
179
  function has_tax_enhanced_ui( $form_or_field ) {
180
 
181
+ if ( is_a( $form_or_field, 'GF_Field' ) ) {
182
+ if ( $form_or_field->get_input_type() == 'text' && $form_or_field->saveToTaxonomy && $form_or_field->taxonomyEnhanced ) {
183
  return true;
184
  }
185
  } else {
186
+ foreach ( $form_or_field['fields'] as $field ) {
187
+ if ( $this->has_tax_enhanced_ui( $field ) ) {
188
  return true;
189
  }
190
  }
204
  function set_post_values( $post_data, $form ) {
205
 
206
  //check if the form saves a post
207
+ if ( $this->is_form_a_post_form( $form ) ) {
208
  $target_post_type = $this->get_form_post_type( $form );
209
 
210
+ if ( $target_post_type ) {
211
  $post_data["post_type"] = $target_post_type;
212
+ }
213
 
214
  //then check if we have set a parent
215
  $parent_post_id = $this->get_form_parent_post_id( $form );
216
 
217
+ if ( $parent_post_id > 0 ) {
218
+ $post_data["post_parent"] = $parent_post_id;
219
  }
220
  }
221
+
222
  return $post_data;
223
 
224
  }
227
  * Checks if a form includes a 'post field'
228
  */
229
  function is_form_a_post_form( $form ) {
230
+ foreach ( $form["fields"] as $field ) {
231
+ if ( in_array( $field["type"],
232
+ array(
233
+ "post_category",
234
+ "post_title",
235
+ "post_content",
236
+ "post_excerpt",
237
+ "post_tags",
238
+ "post_custom_fields",
239
+ "post_image"
240
+ ) ) ) {
241
  return true;
242
+ }
243
  }
244
+
245
  return false;
246
  }
247
 
302
  * setup a field if it is linked to a post type
303
  */
304
  function setup_post_type_field( &$field, $post_type ) {
305
+ $first_choice = $field['choices'][0]['text'];
306
+ $field['choices'] = $this->load_post_type_choices( $post_type, $first_choice, $field );
307
  $field->enableChoiceValue = true;
308
  }
309
 
310
+ function load_post_type_choices( $post_type, $first_choice = '', $field ) {
311
  $posts = $this->load_posts_hierarchical( $post_type, $field->formId, $field->id );
312
+ if ( $first_choice === '' || $first_choice === 'First Choice' ) {
313
  // if no default option is specified, dynamically create based on post type name
314
+ $post_type_obj = get_post_type_object( $post_type );
315
+ $choices[] = array(
316
+ 'text' => "-- select a {$post_type_obj->labels->singular_name} --",
317
+ 'value' => ''
318
+ );
319
  } else {
320
+ $choices[] = array( 'text' => $first_choice, 'value' => '' );
321
  }
322
 
323
+ foreach ( $posts as $post ) {
324
+ $choices[] = array( 'value' => $post->ID, 'text' => $post->post_title );
325
  }
326
 
327
  return $choices;
331
  * Get a hierarchical list of posts
332
  */
333
  function load_posts_hierarchical( $post_type, $form_id, $field_id ) {
334
+ $args = gf_apply_filters( 'gfcpt_get_posts_args', array( $form_id, $field_id ), array(
335
  'post_type' => $post_type,
336
+ 'numberposts' => - 1,
337
  'orderby' => $post_type == 'page' ? 'menu_order' : 'title',
338
  'order' => $post_type == 'page' ? null : 'ASC',
339
  'post_status' => 'publish'
340
  ) );
341
  $posts = get_posts( $args );
342
+
343
  return $this->walk_posts( $posts );
344
  }
345
 
346
  /*
347
  * Helper function to recursively 'walk' the posts
348
  */
349
+ function walk_posts( $input_array, $parent_id = 0, &$out_array = array(), $level = 0 ) {
350
  foreach ( $input_array as $item ) {
351
  if ( $item->post_parent == $parent_id ) {
352
+ $item->post_title = str_repeat( '--', $level ) . $item->post_title;
353
+ $out_array[] = $item;
354
+ $this->walk_posts( $input_array, $item->ID, $out_array, $level + 1 );
355
  }
356
  }
357
+
358
  return $out_array;
359
  }
360
 
363
  */
364
  function setup_taxonomy_field( &$field, $taxonomy ) {
365
 
366
+ $first_choice = rgars( $field, 'choices/0/text' );
367
+ $field['choices'] = $this->load_taxonomy_choices( $taxonomy, $field['type'], $first_choice, $field );
368
  $field->enableChoiceValue = true;
369
 
370
  //now check if we are dealing with a checkbox list and do some extra magic
374
 
375
  $counter = 0;
376
  //recreate the inputs so they are captured correctly on form submission
377
+ foreach ( $field['choices'] as $choice ) {
378
 
379
  //thanks to Peter Schuster for the help on this fix
380
+ $counter ++;
381
  if ( $counter % 10 == 0 ) {
382
+ $counter ++;
383
  }
384
 
385
+ $id = $field['id'] . '.' . $counter;
386
  $inputs[] = array( 'label' => $choice['text'], 'id' => $id );
387
  }
388
 
394
  /*
395
  * Load any taxonomy terms
396
  */
397
+ function load_taxonomy_choices( $taxonomy, $type, $first_choice = '', $field ) {
398
  $choices = array();
399
 
400
+ if ( in_array( $field->get_input_type(), gf_apply_filters( array(
401
+ 'gfcpt_hierarchical_display',
402
+ $field->formId,
403
+ $field->fieldId
404
+ ), array( 'select', 'multiselect' ) ) ) ) {
405
 
406
  $terms = $this->load_taxonomy_hierarchical( $taxonomy, $field );
407
 
408
+ if ( $field->get_input_type() == 'select' ) {
409
  if ( $first_choice !== '' && $first_choice !== 'First Choice' && empty( $field->placeholder ) ) {
410
  // if no default option is specified, dynamically create based on taxonomy name
411
+ $taxonomy = get_taxonomy( $taxonomy );
412
+ $choices[] = array(
413
+ 'text' => "-- select a {$taxonomy->labels->singular_name} --",
414
+ 'value' => ''
415
+ );
416
  }
417
  }
418
 
419
  } else {
420
+ $terms = get_terms( $taxonomy, 'orderby=name&hide_empty=0' );
421
  }
422
 
423
+ if ( ! array_key_exists( "errors", $terms ) ) {
424
+ foreach ( $terms as $term ) {
425
+ $choices[] = array( 'value' => $term->term_id, 'text' => $term->name );
426
+ }
427
  }
428
 
429
  return $choices;
435
  function load_taxonomy_hierarchical( $taxonomy, $field ) {
436
 
437
  $args = gf_apply_filters( 'gfcpt_taxonomy_args', array( $field->formId, $field->id ), array(
438
+ 'taxonomy' => $taxonomy,
439
+ 'orderby' => 'name',
440
+ 'hierarchical' => 1,
441
+ 'hide_empty' => 0
442
  ), $field );
443
 
444
+ $terms = get_categories( $args );
445
 
446
+ if ( array_key_exists( "errors", $terms ) ) {
447
  return $terms;
448
  } else {
449
  $parent = isset( $args['parent'] ) ? $args['parent'] : 0;
450
+
451
  return $this->walk_terms( $terms, $parent );
452
  }
453
 
456
  /*
457
  * Helper function to recursively 'walk' the taxonomy terms
458
  */
459
+ function walk_terms( $input_array, $parent_id = 0, &$out_array = array(), $level = 0 ) {
460
  foreach ( $input_array as $item ) {
461
  if ( $item->parent == $parent_id ) {
462
+ $item->name = str_repeat( '--', $level ) . $item->name;
463
+ $out_array[] = $item;
464
+ $this->walk_terms( $input_array, $item->term_id, $out_array, $level + 1 );
465
  }
466
  }
467
+
468
  return $out_array;
469
  }
470
 
478
 
479
  $this->delete_custom_taxonomies( $entry, $form );
480
 
481
+ foreach ( $form['fields'] as &$field ) {
482
 
483
  $taxonomy = $this->get_field_taxonomy( $field );
484
 
485
+ if ( ! $taxonomy ) {
486
+ continue;
487
+ }
488
 
489
  $this->save_taxonomy_field( $field, $entry, $taxonomy );
490
  }
494
  /**
495
  * Remove Custom Taxonomies
496
  *
497
+ * @return void
498
  * @author ekaj
 
499
  */
500
  public function delete_custom_taxonomies( $entry, $form ) {
501
  // Check if the submission contains a WordPress post
502
+ if ( ! empty( $entry['post_id'] ) ) {
503
+ foreach ( $form['fields'] as &$field ) {
504
+ $taxonomy = rgar( $field, 'populateTaxonomy' );
 
 
 
 
 
505
 
506
  if ( $taxonomy ) {
507
+ wp_set_object_terms( $entry['post_id'], null, $taxonomy );
508
  }
509
  }
510
  }
517
 
518
  $terms = array();
519
 
520
+ switch ( $field->get_input_type() ) {
521
  case 'multiselect':
522
 
523
  $value = $entry[ $field->id ];
524
  $terms = json_decode( $value );
525
 
526
+ if ( ! is_array( $terms ) ) {
527
  $terms = explode( ',', $value );
528
  }
529
 
561
 
562
  $return = $term_id;
563
 
564
+ if ( $field->populateTaxonomy && ! empty( $term_id ) ) {
565
  $term = get_term( (int) $term_id, $field->populateTaxonomy );
566
+ if ( ! is_wp_error( $term ) ) {
567
  $return = $term->name;
568
  }
569
  }
577
 
578
  function display_term_name_on_entry_list( $value, $form_id, $field_id ) {
579
 
580
+ if ( is_numeric( $field_id ) ) {
581
  $field = GFFormsModel::get_field( GFAPI::get_form( $form_id ), $field_id );
582
  $value = $this->get_term_name( $value, $field );
583
  }
591
 
592
  function get_post_title( $post_id, $field ) {
593
 
594
+ if ( $field->populatePostType && ! empty( $post_id ) ) {
595
  $post = get_post( $post_id );
596
+
597
  return $post ? $post->post_title : $post_id;
598
  }
599
 
606
 
607
  function display_post_title_on_entry_list( $value, $form_id, $field_id ) {
608
 
609
+ if ( is_numeric( $field_id ) ) {
610
  $field = GFFormsModel::get_field( GFAPI::get_form( $form_id ), $field_id );
611
  $value = $this->get_post_title( $value, $field );
612
  }
readme.txt CHANGED
@@ -81,6 +81,12 @@ When populating a Drop Down field with a post type, you may wish to set the sele
81
 
82
  == Changelog ==
83
 
 
 
 
 
 
 
84
  = 3.1.19 =
85
 
86
  * Bumped plugin version.
81
 
82
  == Changelog ==
83
 
84
+ = 3.1.20 =
85
+
86
+ * Fixed PHP notice on Gravity Forms Coupons Add-On page.
87
+ * Fixed PHP warning when populating taxonomies.
88
+ * Updated formatting of PHP files in plugin to better conform to the WordPress Coding Standards.
89
+
90
  = 3.1.19 =
91
 
92
  * Bumped plugin version.