Version Description
- Fixed issue with "Save To Taxonomy" setting not properly saving the entered taxonomy.
Download this release
Release Info
Developer | claygriffiths |
Plugin | Gravity Forms + Custom Post Types |
Version | 3.1.18 |
Comparing to | |
See all releases |
Code changes from version 3.0.1 to 3.1.18
- css/custom/jquery-ui-1.8.16.custom.css +10 -0
- css/jquery.tagit.css +1 -1
- gfcptaddon.php +10 -37
- gfcptaddon_1-5.php +53 -83
- gfcptaddonbase.php +583 -421
- js/tag-it.init.js +23 -16
- js/tag-it.js +6 -6
- readme.txt +185 -37
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- screenshot-3.png +0 -0
- screenshot-4.png +0 -0
- screenshot-5.png +0 -0
- screenshot-6.png +0 -0
- screenshot-7.png +0 -0
css/custom/jquery-ui-1.8.16.custom.css
CHANGED
@@ -340,3 +340,13 @@
|
|
340 |
font-weight: normal;
|
341 |
margin: -1px;
|
342 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
font-weight: normal;
|
341 |
margin: -1px;
|
342 |
}
|
343 |
+
|
344 |
+
|
345 |
+
|
346 |
+
|
347 |
+
/**
|
348 |
+
* Custom Styles
|
349 |
+
*/
|
350 |
+
|
351 |
+
.ui-autocomplete { border-radius: 3px; font-size: 13px; }
|
352 |
+
.ui-menu .ui-menu-item { float: none; display: block; padding: 0 2px; border-radius: 1px; width: auto; }
|
css/jquery.tagit.css
CHANGED
@@ -4,7 +4,7 @@ ul.tagit {
|
|
4 |
margin-left: inherit; /* usually we don't want the regular ul margins. */
|
5 |
margin-right: inherit;
|
6 |
width: 47%;
|
7 |
-
border: 1px solid #AAA;
|
8 |
}
|
9 |
|
10 |
ul.tagit li {
|
4 |
margin-left: inherit; /* usually we don't want the regular ul margins. */
|
5 |
margin-right: inherit;
|
6 |
width: 47%;
|
7 |
+
border: 1px solid #AAA;
|
8 |
}
|
9 |
|
10 |
ul.tagit li {
|
gfcptaddon.php
CHANGED
@@ -1,39 +1,14 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Gravity Forms + Custom Post Types
|
4 |
-
Plugin URI:
|
5 |
-
Description:
|
6 |
-
Version: 3.
|
7 |
-
Author:
|
8 |
-
Author URI:
|
9 |
License: GPL2
|
10 |
-
|
11 |
-
------------------------------------------------------------------------
|
12 |
-
Copyright 2011 Themergency
|
13 |
-
|
14 |
-
This program is free software; you can redistribute it and/or modify
|
15 |
-
it under the terms of the GNU General Public License as published by
|
16 |
-
the Free Software Foundation; either version 2 of the License, or
|
17 |
-
(at your option) any later version.
|
18 |
-
|
19 |
-
This program is distributed in the hope that it will be useful,
|
20 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
-
GNU General Public License for more details.
|
23 |
-
|
24 |
-
You should have received a copy of the GNU General Public License
|
25 |
-
along with this program; if not, write to the Free Software
|
26 |
-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
27 |
*/
|
28 |
|
29 |
-
// Include Gravity Forms
|
30 |
-
//if (!class_exists('RGForms'))
|
31 |
-
// @include_once(WP_PLUGIN_DIR . '/gravityforms/gravityforms.php');
|
32 |
-
//if (!class_exists('RGFormsModel'))
|
33 |
-
// @include_once(WP_PLUGIN_DIR . '/gravityforms/forms_model.php');
|
34 |
-
//if (!class_exists('GFCommon'))
|
35 |
-
// @include_once(WP_PLUGIN_DIR . '/gravityforms/common.php');
|
36 |
-
|
37 |
add_action('init', array('GFCPTAddon', 'init'), 20);
|
38 |
add_action('admin_notices', array('GFCPTAddon', 'admin_warnings'), 20);
|
39 |
|
@@ -41,8 +16,8 @@ class GFCPTAddon {
|
|
41 |
|
42 |
private static $name = 'Gravity Forms + Custom Post Types';
|
43 |
private static $slug = 'GFCPTAddon';
|
44 |
-
private static $version = '
|
45 |
-
private static $min_gravityforms_version = '1.
|
46 |
|
47 |
//Plugin starting point. Will load appropriate files
|
48 |
public static function init(){
|
@@ -118,9 +93,8 @@ class GFCPTAddon {
|
|
118 |
/*
|
119 |
* Returns the physical path of the plugin's root folder
|
120 |
*/
|
121 |
-
protected function get_base_path(){
|
122 |
-
|
123 |
-
return WP_PLUGIN_DIR . '/' . $folder;
|
124 |
}
|
125 |
|
126 |
/**
|
@@ -149,5 +123,4 @@ class GFCPTAddon {
|
|
149 |
else
|
150 |
return true;
|
151 |
}
|
152 |
-
}
|
153 |
-
?>
|
1 |
<?php
|
2 |
/*
|
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.17
|
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 |
|
16 |
|
17 |
private static $name = 'Gravity Forms + Custom Post Types';
|
18 |
private static $slug = 'GFCPTAddon';
|
19 |
+
private static $version = '3.1.17';
|
20 |
+
private static $min_gravityforms_version = '1.9.3';
|
21 |
|
22 |
//Plugin starting point. Will load appropriate files
|
23 |
public static function init(){
|
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 |
/**
|
123 |
else
|
124 |
return true;
|
125 |
}
|
126 |
+
}
|
|
gfcptaddon_1-5.php
CHANGED
@@ -16,6 +16,7 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
16 |
|
17 |
//then add these for 1.5...
|
18 |
//add our advanced options to the form builder
|
|
|
19 |
add_action('gform_field_advanced_settings', array(&$this, 'render_field_advanced_settings'), 10, 2);
|
20 |
|
21 |
//include javascript for the form builder
|
@@ -28,26 +29,26 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
28 |
/*
|
29 |
* Override. Gets the post type from our new field value
|
30 |
*/
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
/*
|
40 |
* Override. Gets the taxonomy from our new field value
|
41 |
*/
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
|
52 |
/*
|
53 |
* Override. Gets the custom post type from the post title field value
|
@@ -77,12 +78,31 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
77 |
$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.";
|
78 |
$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";
|
79 |
$tooltips["form_field_custom_taxonomy"] = "<h6>Populate with a Taxonomy</h6>Check this box to populate this field from a custom taxonomy.";
|
80 |
-
$tooltips["form_field_custom_post_type"] =
|
81 |
$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.";
|
82 |
$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.";
|
83 |
return $tooltips;
|
84 |
}
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
/*
|
87 |
* Add some advanced settings to the fields
|
88 |
*/
|
@@ -97,15 +117,9 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
97 |
<?php gform_tooltip("form_field_custom_taxonomy") ?><br />
|
98 |
<select id="field_populate_taxonomy" onchange="SetFieldProperty('populateTaxonomy', jQuery(this).val());" style="margin-top:10px; display:none;">
|
99 |
<option value="" style="color:#999;">Select a Taxonomy</option>
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
'_builtin' => false
|
104 |
-
);
|
105 |
-
$taxonomies = get_taxonomies($args, 'objects');
|
106 |
-
foreach($taxonomies as $taxonomy): ?>
|
107 |
-
<option value="<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->label; ?></option>
|
108 |
-
<?php endforeach; ?>
|
109 |
</select>
|
110 |
</li>
|
111 |
<li class="populate_with_post_type_field_setting field_setting" style="display:list-item;">
|
@@ -118,11 +132,7 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
118 |
<select id="field_populate_post_type" onchange="SetFieldProperty('populatePostType', jQuery(this).val());">
|
119 |
<option value="" style="color:#999;">Select a Post Type</option>
|
120 |
<?php
|
121 |
-
$
|
122 |
-
'public' => true
|
123 |
-
);
|
124 |
-
$post_types = get_post_types($args, 'objects');
|
125 |
-
foreach($post_types as $post_type): ?>
|
126 |
<option value="<?php echo $post_type->name; ?>"><?php echo $post_type->label; ?></option>
|
127 |
<?php endforeach; ?>
|
128 |
</select>
|
@@ -133,24 +143,6 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
133 |
<?php gform_tooltip("form_field_set_parent_post") ?>
|
134 |
</div>
|
135 |
</li>
|
136 |
-
<li class="custom_post_type_field_setting field_setting" style="display:list-item;">
|
137 |
-
<input type="checkbox" id="field_enable_custom_post_type" />
|
138 |
-
<label for="field_enable_custom_post_type" class="inline">
|
139 |
-
<?php _e("Save As Post Type", "gravityforms"); ?>
|
140 |
-
</label>
|
141 |
-
<?php gform_tooltip("form_field_custom_post_type") ?><br />
|
142 |
-
<select id="field_populate_custom_post_type" onchange="SetFieldProperty('saveAsCPT', jQuery(this).val());" style="margin-top:10px; display:none;">
|
143 |
-
<option value="" style="color:#999;">Select a Post Type</option>
|
144 |
-
<?php
|
145 |
-
$args=array(
|
146 |
-
'public' => true
|
147 |
-
);
|
148 |
-
$post_types = get_post_types($args, 'objects');
|
149 |
-
foreach($post_types as $post_type): ?>
|
150 |
-
<option value="<?php echo $post_type->name; ?>"><?php echo $post_type->label; ?></option>
|
151 |
-
<?php endforeach; ?>
|
152 |
-
</select>
|
153 |
-
</li>
|
154 |
<li class="save_to_taxonomy_field_setting field_setting" style="display:list-item;">
|
155 |
<input type="checkbox" class="toggle_setting" id="field_enable_save_to_taxonomy" />
|
156 |
<label for="field_enable_save_to_taxonomy" class="inline">
|
@@ -160,17 +152,12 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
160 |
<div style="margin-top:10px; display:none;">
|
161 |
<select id="field_save_to_taxonomy" onchange="SetFieldProperty('saveToTaxonomy', jQuery(this).val());">
|
162 |
<option value="" style="color:#999;">Select a Taxonomy</option>
|
163 |
-
<?php
|
164 |
-
|
165 |
-
'public' => true,
|
166 |
-
'_builtin' => false
|
167 |
-
);
|
168 |
-
$taxonomies = get_taxonomies($args, 'objects');
|
169 |
-
foreach($taxonomies as $taxonomy):
|
170 |
-
if ($taxonomy->hierarchical === false) {?>
|
171 |
<option value="<?php echo $taxonomy->name; ?>"><?php echo $taxonomy->label; ?></option>
|
172 |
-
<?php
|
173 |
<?php endforeach; ?>
|
|
|
174 |
</select>
|
175 |
<input type="checkbox" class="check_tax_enhanced" onclick="SetFieldProperty('taxonomyEnhanced', this.checked);" id="field_tax_enhanced" />
|
176 |
<label for="field_tax_enhanced" class="inline">
|
@@ -239,28 +226,22 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
239 |
$populate_post_type_container.find(".check_parent").removeAttr("checked");
|
240 |
}
|
241 |
} else {
|
242 |
-
|
243 |
-
$taxonomy_setting_container.find("select").val('')
|
|
|
|
|
244 |
}
|
245 |
|
246 |
}
|
247 |
|
248 |
} else if (field['type'] == 'post_title') {
|
249 |
-
var $cpt_setting_container = jQuery(".custom_post_type_field_setting");
|
250 |
|
251 |
-
$cpt_setting_container.
|
|
|
252 |
|
253 |
-
|
|
|
254 |
|
255 |
-
if (saveAsCPT != false) {
|
256 |
-
//check the checkbox if previously checked
|
257 |
-
$cpt_setting_container.find("input:checkbox").attr("checked", "checked");
|
258 |
-
//set the select and show
|
259 |
-
$cpt_setting_container.find("select").val(saveAsCPT).show();
|
260 |
-
} else {
|
261 |
-
$cpt_setting_container.find("input:checkbox").removeAttr("checked");
|
262 |
-
$cpt_setting_container.find("select").val('').hide();
|
263 |
-
}
|
264 |
} else if (field['type'] == 'text') {
|
265 |
var $tax_setting_container = jQuery('.save_to_taxonomy_field_setting');
|
266 |
|
@@ -317,17 +298,6 @@ if (!class_exists('GFCPTAddon1_5')) {
|
|
317 |
}
|
318 |
});
|
319 |
|
320 |
-
jQuery(".custom_post_type_field_setting input:checkbox").click(function() {
|
321 |
-
var checked = jQuery(this).is(":checked");
|
322 |
-
var $select = jQuery(this).parent(".custom_post_type_field_setting:first").find("select");
|
323 |
-
if(checked){
|
324 |
-
$select.slideDown();
|
325 |
-
} else {
|
326 |
-
SetFieldProperty('saveAsCPT','');
|
327 |
-
$select.slideUp();
|
328 |
-
}
|
329 |
-
});
|
330 |
-
|
331 |
jQuery(".populate_with_post_type_field_setting .toggle_setting").click(function() {
|
332 |
var checked = jQuery(this).is(":checked");
|
333 |
var $div = jQuery(this).parent(".populate_with_post_type_field_setting:first").find("div");
|
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
|
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
|
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 |
*/
|
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;">
|
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>
|
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">
|
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">
|
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 |
|
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");
|
gfcptaddonbase.php
CHANGED
@@ -2,424 +2,586 @@
|
|
2 |
|
3 |
if (!class_exists('GFCPTAddonBase')) {
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
/*
|
18 |
+
* Main initilize method for wiring up all the hooks
|
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 |
+
}
|
58 |
+
|
59 |
+
/*
|
60 |
+
* Setup the form with any taxonomies etc
|
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 |
+
|
97 |
+
return $form;
|
98 |
+
}
|
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 |
+
|
122 |
+
$script = '
|
123 |
+
if( typeof gfcpt_tag_inputs == "undefined" ) { window.gfcpt_tag_inputs = { "tag_inputs" : [] }; }
|
124 |
+
if( typeof gfcpt_tag_taxonomies == "undefined" ) { window.gfcpt_tag_taxonomies = {}; }
|
125 |
+
var gfcptCurrentInputs = ' . json_encode( $inputs ) . ';
|
126 |
+
for ( input in gfcptCurrentInputs ) {
|
127 |
+
if( gfcptCurrentInputs.hasOwnProperty( input ) ) {
|
128 |
+
gfcpt_tag_inputs.tag_inputs.push( gfcptCurrentInputs[ input ] );
|
129 |
+
}
|
130 |
+
}
|
131 |
+
var gfcptCurrentTaxonomies = ' . json_encode( $taxonomies ) . ';
|
132 |
+
for ( taxonomy in gfcptCurrentTaxonomies ) {
|
133 |
+
if( gfcptCurrentTaxonomies.hasOwnProperty( taxonomy ) ) {
|
134 |
+
gfcpt_tag_taxonomies[ taxonomy ] = gfcptCurrentTaxonomies[ taxonomy ];
|
135 |
+
}
|
136 |
+
}';
|
137 |
+
|
138 |
+
|
139 |
+
GFFormDisplay::add_init_script( $form['id'], 'gfcpt_tagit', GFFormDisplay::ON_PAGE_RENDER, $script );
|
140 |
+
|
141 |
+
}
|
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 |
+
}
|
179 |
+
}
|
180 |
+
|
181 |
+
return false;
|
182 |
+
}
|
183 |
+
|
184 |
+
|
185 |
+
function preview_print_styles( $styles, $form ) {
|
186 |
+
return array_merge( $styles, array( 'gfcpt_jquery_ui_theme', 'gfcpt_tagit_css' ) );
|
187 |
+
}
|
188 |
+
|
189 |
+
/*
|
190 |
+
* Set the post values (if neccessary)
|
191 |
+
*/
|
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 |
+
}
|
211 |
+
|
212 |
+
/*
|
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 |
+
|
225 |
+
/*
|
226 |
+
* override this to get the post type for a form
|
227 |
+
*/
|
228 |
+
function get_form_post_type( $form ) {
|
229 |
+
return null;
|
230 |
+
}
|
231 |
+
|
232 |
+
/*
|
233 |
+
* override this to get the taxonomy for a field
|
234 |
+
*/
|
235 |
+
function get_field_taxonomy( $field ) {
|
236 |
+
return null;
|
237 |
+
}
|
238 |
+
|
239 |
+
/*
|
240 |
+
* override this to get the post type for a field
|
241 |
+
*/
|
242 |
+
function get_field_post_type( $field ) {
|
243 |
+
return null;
|
244 |
+
}
|
245 |
+
|
246 |
+
/*
|
247 |
+
* override this to get the parent Id for a form
|
248 |
+
*/
|
249 |
+
function get_form_parent_post_id( $form ) {
|
250 |
+
return 0;
|
251 |
+
}
|
252 |
+
|
253 |
+
function get_taxonomies( $form_id, $args = array() ) {
|
254 |
+
|
255 |
+
$args = wp_parse_args( $args, array(
|
256 |
+
'public' => true,
|
257 |
+
'_builtin' => false
|
258 |
+
) );
|
259 |
+
|
260 |
+
$args = gf_apply_filters( 'gfcpt_tax_args', array( $form_id ), $args, $form_id );
|
261 |
+
$taxonomies = get_taxonomies( $args, 'objects' );
|
262 |
+
|
263 |
+
return $taxonomies;
|
264 |
+
}
|
265 |
+
|
266 |
+
function get_post_types( $form_id, $args = array() ) {
|
267 |
+
|
268 |
+
$args = wp_parse_args( $args, array(
|
269 |
+
'public' => true
|
270 |
+
) );
|
271 |
+
|
272 |
+
$args = gf_apply_filters( 'gfcpt_post_type_args', array( $form_id ), $args, $form_id );
|
273 |
+
$post_types = get_post_types( $args, 'objects' );
|
274 |
+
|
275 |
+
return $post_types;
|
276 |
+
}
|
277 |
+
|
278 |
+
/*
|
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;
|
302 |
+
}
|
303 |
+
|
304 |
+
/*
|
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 |
+
|
333 |
+
/*
|
334 |
+
* setup a field if it is linked to a taxonomy
|
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
|
343 |
+
if ( $field['type'] == 'checkbox' ) {
|
344 |
+
|
345 |
+
$inputs = array();
|
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 |
+
|
361 |
+
$field['inputs'] = $inputs;
|
362 |
+
|
363 |
+
}
|
364 |
+
}
|
365 |
+
|
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;
|
395 |
+
}
|
396 |
+
|
397 |
+
/*
|
398 |
+
* Get a hierarchical list of taxonomies
|
399 |
+
*/
|
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 |
+
|
418 |
+
}
|
419 |
+
|
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 |
+
|
434 |
+
/*
|
435 |
+
* Loop through all fields and save any linked taxonomies
|
436 |
+
*/
|
437 |
+
function save_taxonomies( $post_id, $entry, $form ) {
|
438 |
+
|
439 |
+
// Check if the submission contains a WordPress post
|
440 |
+
if ( isset ( $entry['post_id'] ) ) {
|
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 |
+
}
|
452 |
+
}
|
453 |
+
}
|
454 |
+
|
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 |
+
}
|
477 |
+
}
|
478 |
+
|
479 |
+
/*
|
480 |
+
* Save linked taxonomies for a sinle field
|
481 |
+
*/
|
482 |
+
function save_taxonomy_field( &$field, $entry, $taxonomy ) {
|
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 |
+
|
496 |
+
$terms = array_map( 'intval', $terms );
|
497 |
+
|
498 |
+
break;
|
499 |
+
|
500 |
+
case 'checkbox':
|
501 |
+
|
502 |
+
foreach ( $field['inputs'] as $input ) {
|
503 |
+
$term = (int) $entry[ (string) $input['id'] ];
|
504 |
+
if ( $term ) {
|
505 |
+
$terms[] = $term;
|
506 |
+
}
|
507 |
+
}
|
508 |
+
|
509 |
+
break;
|
510 |
+
case 'text':
|
511 |
+
$terms = array_filter( explode( ',', $entry[ $field->id ] ) );
|
512 |
+
break;
|
513 |
+
default:
|
514 |
+
$terms = (int) $entry[ $field->id ];
|
515 |
+
}
|
516 |
+
|
517 |
+
if ( ! empty ( $terms ) ) {
|
518 |
+
$append_terms = (bool) apply_filters( 'gfcpt_append_terms', true, $field, $entry, $taxonomy );
|
519 |
+
$append_terms = (bool) apply_filters( sprintf( 'gfcpt_append_terms_%d', $field->formId ), $append_terms, $field, $entry, $taxonomy );
|
520 |
+
$append_terms = (bool) apply_filters( sprintf( 'gfcpt_append_terms_%d_%d', $field->formId, $field->id ), $append_terms, $field, $entry, $taxonomy );
|
521 |
+
wp_set_object_terms( $entry['post_id'], $terms, $taxonomy, $append_terms );
|
522 |
+
}
|
523 |
+
|
524 |
+
}
|
525 |
+
|
526 |
+
function get_term_name( $term_id, $field ) {
|
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 |
+
}
|
536 |
+
|
537 |
+
return $return;
|
538 |
+
}
|
539 |
+
|
540 |
+
function display_term_name_on_entry_detail( $value, $field, $entry, $form ) {
|
541 |
+
return $this->get_term_name( $value, $field );
|
542 |
+
}
|
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 |
+
}
|
550 |
+
|
551 |
+
return $value;
|
552 |
+
}
|
553 |
+
|
554 |
+
function display_term_name_on_export( $value, $form_id, $field_id ) {
|
555 |
+
return $this->display_term_name_on_entry_list( $value, $form_id, $field_id );
|
556 |
+
}
|
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 |
+
|
565 |
+
return $post_id;
|
566 |
+
}
|
567 |
+
|
568 |
+
function display_post_title_on_entry_detail( $value, $field, $entry, $form ) {
|
569 |
+
return $this->get_post_title( $value, $field );
|
570 |
+
}
|
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 |
+
}
|
578 |
+
|
579 |
+
return $value;
|
580 |
+
}
|
581 |
+
|
582 |
+
function display_post_title_on_export( $value, $form_id, $field_id ) {
|
583 |
+
return $this->display_post_title_on_entry_list( $value, $form_id, $field_id );
|
584 |
+
}
|
585 |
+
|
586 |
+
}
|
587 |
+
}
|
js/tag-it.init.js
CHANGED
@@ -1,16 +1,23 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
|
3 |
+
|
4 |
+
( function( $ ) {
|
5 |
+
|
6 |
+
$( document ).bind( 'gform_post_render', function() {
|
7 |
+
|
8 |
+
/* Temporary fix due to jQuery version issue */
|
9 |
+
jQuery.curCSS = jQuery.css;
|
10 |
+
|
11 |
+
$.each( gfcpt_tag_inputs.tag_inputs, function() {
|
12 |
+
$( this.input ).tagit( {
|
13 |
+
availableTags: gfcpt_tag_taxonomies[ this.taxonomy ],
|
14 |
+
removeConfirmation: true,
|
15 |
+
allowSpaces: true,
|
16 |
+
animate: false
|
17 |
+
} );
|
18 |
+
} );
|
19 |
+
|
20 |
+
} );
|
21 |
+
|
22 |
+
} )( jQuery );
|
23 |
+
|
js/tag-it.js
CHANGED
@@ -51,7 +51,7 @@
|
|
51 |
//
|
52 |
// The easiest way to use singleField is to just instantiate tag-it
|
53 |
// on an INPUT element, in which case singleField is automatically
|
54 |
-
// set to true, and singleFieldNode is set to that element. This
|
55 |
// way, you don't need to fiddle with these options.
|
56 |
singleField: false,
|
57 |
|
@@ -63,7 +63,7 @@
|
|
63 |
// delimited by singleFieldDelimiter.
|
64 |
//
|
65 |
// If this is not set, we create an input node for it,
|
66 |
-
// with the name given in settings.fieldName,
|
67 |
// ignoring settings.itemName.
|
68 |
singleFieldNode: null,
|
69 |
|
@@ -92,11 +92,11 @@
|
|
92 |
this.options.singleField = true;
|
93 |
this.options.singleFieldNode = this.element;
|
94 |
this.element.css('display', 'none');
|
95 |
-
|
96 |
if (!this.options.tabIndex) {
|
97 |
this.options.tabIndex = this.element.attr('tabindex');
|
98 |
}
|
99 |
-
|
100 |
} else {
|
101 |
this.tagList = this.element.find('ul, ol').andSelf().last();
|
102 |
}
|
@@ -212,7 +212,7 @@
|
|
212 |
// Create a tag when the element loses focus (unless it's empty).
|
213 |
that.createTag(that._cleanedInput());
|
214 |
});
|
215 |
-
|
216 |
|
217 |
// Autocomplete.
|
218 |
if (this.options.availableTags || this.options.tagSource) {
|
@@ -352,7 +352,7 @@
|
|
352 |
// insert tag
|
353 |
this._tagInput.parent().before(tag);
|
354 |
},
|
355 |
-
|
356 |
removeTag: function(tag, animate) {
|
357 |
animate = animate || this.options.animate;
|
358 |
|
51 |
//
|
52 |
// The easiest way to use singleField is to just instantiate tag-it
|
53 |
// on an INPUT element, in which case singleField is automatically
|
54 |
+
// set to true, and singleFieldNode is set to that element. This
|
55 |
// way, you don't need to fiddle with these options.
|
56 |
singleField: false,
|
57 |
|
63 |
// delimited by singleFieldDelimiter.
|
64 |
//
|
65 |
// If this is not set, we create an input node for it,
|
66 |
+
// with the name given in settings.fieldName,
|
67 |
// ignoring settings.itemName.
|
68 |
singleFieldNode: null,
|
69 |
|
92 |
this.options.singleField = true;
|
93 |
this.options.singleFieldNode = this.element;
|
94 |
this.element.css('display', 'none');
|
95 |
+
|
96 |
if (!this.options.tabIndex) {
|
97 |
this.options.tabIndex = this.element.attr('tabindex');
|
98 |
}
|
99 |
+
|
100 |
} else {
|
101 |
this.tagList = this.element.find('ul, ol').andSelf().last();
|
102 |
}
|
212 |
// Create a tag when the element loses focus (unless it's empty).
|
213 |
that.createTag(that._cleanedInput());
|
214 |
});
|
215 |
+
|
216 |
|
217 |
// Autocomplete.
|
218 |
if (this.options.availableTags || this.options.tagSource) {
|
352 |
// insert tag
|
353 |
this._tagInput.parent().before(tag);
|
354 |
},
|
355 |
+
|
356 |
removeTag: function(tag, animate) {
|
357 |
animate = animate || this.options.animate;
|
358 |
|
readme.txt
CHANGED
@@ -1,49 +1,67 @@
|
|
1 |
=== Gravity Forms + Custom Post Types ===
|
2 |
-
Contributors: bradvin,wpsmith
|
3 |
-
Donate link: http://
|
4 |
Tags: form,forms,gravity,gravity form,gravity forms,CPT,custom post types,custom post type,taxonomy,taxonomies
|
5 |
Requires at least: 3.0.1
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 3.
|
8 |
|
9 |
-
|
10 |
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
> Check out my other free [Add-ons for Gravity Forms](http://themergency.com/gravity-forms-addon-plugins/)
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
* Map fields (Drop Downs, Multiple Choice or Checkboxes) to a custom taxonomy
|
24 |
-
* Supports Gravity Forms v1.5 and over (including v1.6)
|
25 |
-
* Ability to have more than 1 taxonomy linked in a form (see screenshots)
|
26 |
-
* Hierarchical dropdowns for hierarchical taxonomies (see screenshots)
|
27 |
-
* Populate a dropdown with posts
|
28 |
-
* Ability to set a parent post using the dropdown control
|
29 |
-
* Single line text field can link to taxonomies by entering a comma seperated list
|
30 |
-
* Enhanced UI on single line text fields to show a "tag input" styled control (see screenshots)
|
31 |
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
|
36 |
-
|
|
|
|
|
37 |
|
38 |
-
|
39 |
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
|
44 |
-
|
45 |
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
== Installation ==
|
49 |
|
@@ -53,16 +71,112 @@ You can now link the dropdown field to a post type and try to make it set the pa
|
|
53 |
|
54 |
== Screenshots ==
|
55 |
|
56 |
-
1.
|
57 |
-
2.
|
58 |
-
3.
|
59 |
-
4.
|
60 |
-
5.
|
61 |
-
6. Single Line Text field with
|
62 |
-
7.
|
63 |
|
64 |
== Changelog ==
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
= 3.0.1 =
|
67 |
* Fixed minor bug causing a PHP warning (_FILE_)
|
68 |
* removed the restriction of not including scripts when a call is ajax
|
@@ -92,8 +206,42 @@ You can now link the dropdown field to a post type and try to make it set the pa
|
|
92 |
== Frequently Asked Questions ==
|
93 |
|
94 |
= Does this plugin rely on anything? =
|
95 |
-
Yes, you need to install the [Gravity Forms
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
== Upgrade Notice ==
|
98 |
|
99 |
-
Please
|
1 |
=== Gravity Forms + Custom Post Types ===
|
2 |
+
Contributors: spivurno,claygriffiths,bradvin,wpsmith
|
3 |
+
Donate link: http://gravitywiz.com/
|
4 |
Tags: form,forms,gravity,gravity form,gravity forms,CPT,custom post types,custom post type,taxonomy,taxonomies
|
5 |
Requires at least: 3.0.1
|
6 |
+
Tested up to: 5.7
|
7 |
+
Stable tag: 3.1.16
|
8 |
|
9 |
+
Map your Gravity-Forms-generated posts to a custom post type and/or custom taxonomies.
|
10 |
|
11 |
+
= Introduction =
|
12 |
|
13 |
+
This plugin is an add-on for [Gravity Forms](http://gravityforms.com). Make sure you visit [GravityWiz.com](http://gravitywiz.com/blog/) for more **free** Gravity Forms resources. And if you're looking to the largest collection of Gravity Forms plugins, check out [Gravity Perks](http://gravityperks.com).
|
|
|
14 |
|
15 |
+
= Description =
|
16 |
|
17 |
+
Gravity Forms allows you to create posts from a form submission using special Post Fields. By default, the submitted form will be created as a standard WordPress post. This plugin allows you to change the post type of the generated post. **No code required!** This plugin also provides the ability to assign the generated post to a custom taxonomy.
|
18 |
|
19 |
+
Need to update posts? Learn [how to update posts with Gravity Forms](https://gravitywiz.com/how-to-update-posts-with-gravity-forms/).
|
20 |
|
21 |
+
= Features =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
- Map posts to a custom post type
|
24 |
+
- Map posts to a custom taxonomy (via Drop Down, Multi-select, Radio Button or Checkbox field)
|
25 |
+
- Map posts to multiple taxonomies
|
26 |
+
- Visual hierarchy support for hierarchical taxonomies (Drop Down field only)
|
27 |
+
- Populate a Drop Down with posts
|
28 |
+
- Assign parent post for generated post (Drop Down field only)
|
29 |
+
- Single Line Text field support for taxonomies (enter as a comma-delimited list: term a, term b, term c)
|
30 |
+
- Enhanced UI support for Single Line Text fields (see screenshots)
|
31 |
|
32 |
+
= How to map a form to a custom post type =
|
33 |
|
34 |
+
1. Add a Post Title field to your form and click on it to open the field settings.
|
35 |
+
2. Below the "Description" field setting, you will find the "Post Type" setting.
|
36 |
+
3. Select the desired post type from the drop down (default is "Posts").
|
37 |
|
38 |
+
= How to link a field to a custom taxonomy =
|
39 |
|
40 |
+
1. Add the desired field to which the custom taxonomy should be mapped. Drop Down, Multi Select, Radio Buttons and Checkboxes fields are current supported.
|
41 |
+
2. Open the field settings by clicking on the field and click on the "Advanced" tab.
|
42 |
+
3. Check the "Populate with a Taxonomy" checkbox.
|
43 |
+
4. Select the desired taxonomy from the drop down that appears.
|
44 |
|
45 |
+
= How to link the saved post to taxonomies using a single line text field =
|
46 |
|
47 |
+
Single Line Text fields are a great way to allow users to select existing taxonomy terms and to also add new terms.
|
48 |
|
49 |
+
1. Add a Single Line Text field to your form.
|
50 |
+
2. Open the field settings by clicking on the field and click on the "Advanced" tab.
|
51 |
+
3. Check the "Save to Taxonomy" checkbox.
|
52 |
+
4. Select the desired taxonomy from the drop down that appears.
|
53 |
+
5. (optional) Check the "Enable Enhanced UI" checkbox to enable an awesome tag-input style UI (see screenshots).
|
54 |
+
|
55 |
+
Note: If the user inputs exising term names, the generated post will be assigned these terms. If the user inputs term names that do not exist, these terms will be added to the selected taxonomy and the generated post will also be assigned these terms.
|
56 |
+
|
57 |
+
= How to set a parent post with the drop down field =
|
58 |
+
|
59 |
+
When populating a Drop Down field with a post type, you may wish to set the selected post as the parent post for the generated post.
|
60 |
+
|
61 |
+
1. Add A Drop Down field to your form.
|
62 |
+
2. Click on the field to open the field settings. Then click on the "Advanced" tab.
|
63 |
+
3. Check the "Populate with Post Type" checkbox.
|
64 |
+
4. Select the desired post type from the drop down that appears. Be sure to select the **same post type** for which the post is being generated.
|
65 |
|
66 |
== Installation ==
|
67 |
|
71 |
|
72 |
== Screenshots ==
|
73 |
|
74 |
+
1. Frontend: Example of mapping to a custom post type and multiple taxonomies
|
75 |
+
2. Frontend: Example of hierarchical taxonomy support
|
76 |
+
3. Setting: Mapping to a custom post type
|
77 |
+
4. Setting: Mapping a field to a custom taxonomy
|
78 |
+
5. Setting: Assigning generated post to selected parent post
|
79 |
+
6. Frontend: Example of Single Line Text field with Enhanced UI enabled
|
80 |
+
7. Setting: Mapping a Single Line Text field to a taxonomy (and enabling Enhanced UI)
|
81 |
|
82 |
== Changelog ==
|
83 |
|
84 |
+
= 3.1.18 =
|
85 |
+
|
86 |
+
* Fixed issue with "Save To Taxonomy" setting not properly saving the entered taxonomy.
|
87 |
+
|
88 |
+
= 3.1.17 =
|
89 |
+
|
90 |
+
* Readme updates.
|
91 |
+
|
92 |
+
= 3.1.16 =
|
93 |
+
|
94 |
+
* Readme updates.
|
95 |
+
|
96 |
+
= 3.1.15 =
|
97 |
+
|
98 |
+
* Fixed issue when exporting taxonomy-and-post-type-populated Checkbox fields.
|
99 |
+
* Updated how scripts are enqueued.
|
100 |
+
* Tested with 5.5.1.
|
101 |
+
|
102 |
+
= 3.1.14 =
|
103 |
+
|
104 |
+
* Updated how taxonomy enhanced UI script and data were loaded.
|
105 |
+
|
106 |
+
= 3.1.13 =
|
107 |
+
|
108 |
+
* Added 'gfcpt_hierarchical_display' filter to allow filtering whether to display choices hierarchically.
|
109 |
+
|
110 |
+
= 3.1.12 =
|
111 |
+
|
112 |
+
* Fixed issue with GF 2.3 where taxonomies were not correctly saved on submission.
|
113 |
+
|
114 |
+
= 3.1.11 =
|
115 |
+
|
116 |
+
* Fixed issue where dynamic placeholder was duplicated in some instances.
|
117 |
+
|
118 |
+
= 3.1.10 =
|
119 |
+
|
120 |
+
* Fixed issue where dynamic placeholder was added even when default placeholder was specified.
|
121 |
+
|
122 |
+
= 3.1.9 =
|
123 |
+
|
124 |
+
* Added support for displaying Post Title on entry list, detail and export for fields populated with a post type.
|
125 |
+
* Updated default sort order for pages to "menu_order".
|
126 |
+
|
127 |
+
= 3.1.8 =
|
128 |
+
|
129 |
+
* Fixed issue mapping taxonomies for Single Line Text fiela and Multi Select fields. Thanks, Cameron!
|
130 |
+
|
131 |
+
= 3.1.7 =
|
132 |
+
|
133 |
+
* Added support for displaying term label on Entry List and Export views (rather than term ID; does not work with Checkbox and Multi-select on Entry List).
|
134 |
+
|
135 |
+
= 3.1.6 =
|
136 |
+
|
137 |
+
* Added support for displaying term label on Entry Detail view (rather than term ID)
|
138 |
+
|
139 |
+
= 3.1.5 =
|
140 |
+
|
141 |
+
* Fixed issue with populating Drop Down & Multi Selects
|
142 |
+
* Fixed issue when saving Multi Select taxonomies
|
143 |
+
|
144 |
+
= 3.1.4 =
|
145 |
+
|
146 |
+
* Updated plugin header information.
|
147 |
+
|
148 |
+
= 3.1.3 =
|
149 |
+
|
150 |
+
* Fixed compatibility issue with Gravity Forms: Post Updates plugin; custom taxonomies were not being saved.
|
151 |
+
|
152 |
+
= 3.1.2 =
|
153 |
+
|
154 |
+
* Fixed issue where setting first option was not possible due to typo in property name
|
155 |
+
* Updated how GFCPTAddon::get_base_path() method retrieves the base path
|
156 |
+
|
157 |
+
= 3.1.1 =
|
158 |
+
* Updated all calls to get_post_types() to use plugin-specific version which applies the 'gfcpt_post_type_args' filter. Props: mgratch
|
159 |
+
* Updated all calls to get_taxonomies() to use plugin-specific version which applies the 'gfcpt_tax_args' filter. Props: mgratch
|
160 |
+
* Fixed issue where missing script dependency caused tag-style entry of terms was not working. Props: mgratch
|
161 |
+
* Fixed issue where plugin's registration of GF preview styles was overwriting all other preview styles
|
162 |
+
* Fixed issue where taxonomies were not saved for delayed payment entries
|
163 |
+
* Updated Tag init JS to be bound to the 'gform_post_render' JS event which better supports other plugin integrations
|
164 |
+
* Updated Tag init JS file to be loaded in the footer
|
165 |
+
* Added 'gfcpt_get_posts_args' filter to allow modifying the posts that are populated into a field
|
166 |
+
|
167 |
+
= 3.1 =
|
168 |
+
* Added "gfcpt_taxonomy_args" filter to allow modifying the arguments used to retrieve taxonomy terms
|
169 |
+
* Added "gfcpt_post_type_args" filter to allow modifying the arguments used to retrive post types for selection in field settings
|
170 |
+
* Updated verbiage throughout plugin and readme.txt file
|
171 |
+
* Updated minimum required version of Gravity Forms to 1.9.3
|
172 |
+
* Updated "Save As Post Type" to be "Post Type" and moved location to standard settings tab
|
173 |
+
* Updated jQuery UI enqueue to use version from WP core
|
174 |
+
* Updated GFCPTAddonBase::load_taxonomy_hierarchical() method to support only displaying children of a parent term (requires "gfcpt_taxonomy_args" filter)
|
175 |
+
* Fixed styling issues with Enhanced-UI-enabled Single Line Text fields
|
176 |
+
* Fixed notice where get_base_path() was called statically by changing function to be static
|
177 |
+
* Fixed issue where taxonomy select on Drop Down field settings would not populate the selected taxonomy correctly
|
178 |
+
* Fixed issue with GF 1.9 where indirect modfiication of $field['inputs'] property had no effect; resolves issues using custom taxonomies with Checkbox fields
|
179 |
+
|
180 |
= 3.0.1 =
|
181 |
* Fixed minor bug causing a PHP warning (_FILE_)
|
182 |
* removed the restriction of not including scripts when a call is ajax
|
206 |
== Frequently Asked Questions ==
|
207 |
|
208 |
= Does this plugin rely on anything? =
|
209 |
+
Yes, you need to install the [Gravity Forms plugin](http://gwiz.io/gravityforms) for this plugin to work.
|
210 |
+
|
211 |
+
= How do I map a form to a custom post type? =
|
212 |
+
|
213 |
+
1. Add a Post Title field to your form and click on it to open the field settings.
|
214 |
+
2. Below the "Description" field setting, you will find the "Post Type" setting.
|
215 |
+
3. Select the desired post type from the drop down (default is "Posts").
|
216 |
+
|
217 |
+
= How do I link a field to a custom taxonomy? =
|
218 |
+
|
219 |
+
1. Add the desired field to which the custom taxonomy should be mapped. Drop Down, Multi Select, Radio Buttons and Checkboxes fields are current supported.
|
220 |
+
2. Open the field settings by clicking on the field and click on the "Advanced" tab.
|
221 |
+
3. Check the "Populate with a Taxonomy" checkbox.
|
222 |
+
4. Select the desired taxonomy from the drop down that appears.
|
223 |
+
|
224 |
+
= How do I link the saved post to taxonomies using a single line text field? =
|
225 |
+
|
226 |
+
Single Line Text fields are a great way to allow users to select existing taxonomy terms and to also add new terms.
|
227 |
+
|
228 |
+
1. Add a Single Line Text field to your form.
|
229 |
+
2. Open the field settings by clicking on the field and click on the "Advanced" tab.
|
230 |
+
3. Check the "Save to Taxonomy" checkbox.
|
231 |
+
4. Select the desired taxonomy from the drop down that appears.
|
232 |
+
5. (optional) Check the "Enable Enhanced UI" checkbox to enable an awesome tag-input style UI (see screenshots).
|
233 |
+
|
234 |
+
Note: If the user inputs exising term names, the generated post will be assigned these terms. If the user inputs term names that do not exist, these terms will be added to the selected taxonomy and the generated post will also be assigned these terms.
|
235 |
+
|
236 |
+
= How do I set a parent post with the drop down field? =
|
237 |
+
|
238 |
+
When populating a Drop Down field with a post type, you may wish to set the selected post as the parent post for the generated post.
|
239 |
+
|
240 |
+
1. Add A Drop Down field to your form.
|
241 |
+
2. Click on the field to open the field settings. Then click on the "Advanced" tab.
|
242 |
+
3. Check the "Populate with Post Type" checkbox.
|
243 |
+
4. Select the desired post type from the drop down that appears. Be sure to select the **same post type** for which the post is being generated.
|
244 |
|
245 |
== Upgrade Notice ==
|
246 |
|
247 |
+
Please note, Gravity Forms 1.9.3 is now required.
|
screenshot-1.png
CHANGED
Binary file
|
screenshot-2.png
CHANGED
Binary file
|
screenshot-3.png
CHANGED
Binary file
|
screenshot-4.png
CHANGED
Binary file
|
screenshot-5.png
CHANGED
Binary file
|
screenshot-6.png
CHANGED
Binary file
|
screenshot-7.png
CHANGED
Binary file
|