{admin_ajax_url} Merge Tag

{admin_ajax_url} Merge Tag

SummaryUsageNotes

Summary
Returns the Admin Ajax URL (e.g. https://your.domain/wp-admin/admin-ajax.php).
Usage
Use {admin_ajax_url} in the Webhooks Add-On Request URL setting to populate that setting with the Admin Ajax URL when the feed is processed.
Notes
Available with the Webhooks Add-On (v1.1.5+).

上次修改 2021.12.28

WP Config Options

WP Config Options

General OptionsGF_THEME_IMPORT_FILEGF_LICENSE_KEYMulti-Site Specific OptionsGF_RECAPTCHA_PRIVATE_KEYGF_RECAPTCHA_PUBLIC_KEYGF_IMPORT_FILECreating a Form Import JSON File

General Options
The following options are available for general use.
GF_THEME_IMPORT_FILE
Setting this option allows you to specify a Form JSON file from which a set of default forms can be pre-generated when a theme containing this option is activated. This option should be specified in your theme’s functions.php file. Follow these steps to create a Form JSON file for use with this option.
1define( ‘GF_THEME_IMPORT_FILE’, ‘path/to/gf_import.json’ );
Note: The path is relative to your theme root.
GF_LICENSE_KEY
Setting this option before installing Gravity Forms on a single site WP installation or before creating new sites on a multisite install will automatically pre-populate your Gravity Forms license key for those new installations.
1define( ‘GF_LICENSE_KEY’, ‘YOUR-LICENSE-KEY-HERE’ );
Multi-Site Specific Options
The following options are available when using WordPress Multi-Site. All of the options below should be defined in your wp-config.php.
GF_RECAPTCHA_PRIVATE_KEY
GF_RECAPTCHA_PUBLIC_KEY
Setting these options will automatically pre-populate your ReCAPTCHA public and private keys when a new site is created on your Multi-Site install.
12define( ‘GF_RECAPTCHA_PUBLIC_KEY’, ‘YOUR-KEY-HERE’ );define( ‘GF_RECAPTCHA_PRIVATE_KEY’, ‘YOUR-KEY-HERE’ );
GF_IMPORT_FILE
Setting this option allows you to specify a Form JSON file from which a set of default forms can be pre-generated when a new site is created on your Multi-Site install. Follow these steps to create a Form JSON file for use with this option.
1define( ‘GF_IMPORT_FILE’, ‘http://www.domain.com/path/to/gf_import.json’ );
Creating a Form Import JSON File
The following steps explain how to create a Form JSON file from which a set of default forms can be pre-generated when used with the GF_IMPORT_FILE or GF_THEME_IMPORT_FILE option.

Create the initial set of forms you want to replicate.
Navigate to the Import/Export tool and select “Export Forms”.
Select the forms you want to auto-replicate when a new site is created.
Click “Export” to export them to an JSON file.
Place the JSON file somewhere on your web server, such as your wp-content/uploads/ folder, or somewhere easily accessible.
Replace the URL in the example code above with the URL to your Form JSON file.

上次修改 2021.12.28

Advanced Tab

Advanced Tab

IntroductionSettingsSource Code

Introduction
The following settings are available for use on a field’s Advanced tab. The gform_field_advanced_settings hook can also be used to add custom settings at the positions indicated below.
Settings can be enabled for a field which extends the GF_Field class by overriding the get_form_editor_field_settings() method.
Settings

Position: 0

admin_label_setting
The Admin Field Label setting allows the user to define an admin label for the field.

Position: 25

Position: 35

Position: 50

Position: 100

Position: 125

default_value_setting
The Default Value setting allows a default value to be defined for the field using a text input.

Position: 150

default_value_textarea_setting
The Default Value setting allows a default value to be defined for the field using a textarea.

Position: 155

name_prefix_choices_setting
The Prefix Choices setting allows the choices for the Name field prefix input to be customized.

Position: 175

default_input_values_setting
The Default Value setting allowing default values of the field inputs to be defined.

Position: 185

copy_values_option
This setting provides the ability to allow the user to use the values they entered into another address field to populate the current field during form submission. Example: Copying Billing Address to the Mailing Address field.

Position: 200

Position: 225

Position: 250

captcha_language_setting
The Language setting provides a drop down allowing the reCaptcha language to be set.

Position: 300

Position: 325

add_icon_url_setting
The Add Icon URL setting allows an image URL to be defined for use with the List field add row button.

Position: 337

delete_icon_url_setting
The Delete Icon URL setting allows an image URL to be defined for use with the List field delete row button.

Position: 350

password_field_setting
The Enable Password Input setting configures the field to use a password type input.

Position: 375

force_ssl_field_setting
Includes a Force SSL setting which allows the page containing the form to be forced to be secure when this field exists.

Position: 400

visibility_setting
The Visibility settings allow the field to be displayed on the front-end form or only on the entry detail page when editing the entry.

Position: 425

rich_text_editor_setting
Provides a Use the Rich Text Editor setting allowing the RTE to be enabled for the Paragraph and Post Body fields.

Position: 450

prepopulate_field_setting
This setting allows dynamic population to be enabled for the field and parameter names to be configured for the relevant field inputs.

Position: 500

conditional_logic_field_setting
This setting allows conditional logic to be enabled for the field and the individual rules to be defined.

Position: 525

conditional_logic_page_setting
This setting allows conditional logic to be enabled for the page and the individual rules to be defined.

Position: 550

conditional_logic_nextbutton_setting
This setting allows conditional logic to be enabled for the next button and the individual rules to be defined.

Position: -1

Source Code
The above settings are located in GFFormDetail::forms_page() in form_detail.php.

上次修改 2021.12.28

Advanced Post Creation Add-On Using Third-Party Post Types

Advanced Post Creation Add-On Using Third-Party Post Types

IntroductionCreating Products for WooCommerceCreate the FormCreate the Advanced Post Creation FeedHandling Fields Unable to be MappedPriceCategoryPopulating Drop Down with Product CategoriesCreating Events for The Events CalendarCreate the FormCreate the Advanced Post Creation FeedHandling Fields Unable to be MappedPopulating Drop Down with Event CategoriesMatching up Images with Advanced Custom Fields (ACF) or other Custom FieldsMake sure the Field is copied to the Media LibraryMap the Image Field to the Custom Field

Introduction

One of the features of the Advanced Post Creation Add-On allows posts to be created upon form submission for third-party post types. This articles provides a guide on how to use Advanced Post Creation with the plugins WooCommerce, to create Products, and The Events Calendar, to create Events.

Note: This article assumes you have installed and activated the required plugins. If not, you will need to do so before any of the functionality in this article can be used.

Creating Products for WooCommerce

Create the Form

Several pieces of information need to be captured to create a Product. Below captures some basic information.

Field TypeLabelOther SettingsDrop DownCategorySee Populating Drop Down with Product Categories below for details.Single Line TextProduct Name ParagraphDescription NumberPriceSet the number format to currencyFile UploadProduct Image 

Create the Advanced Post Creation Feed

For more details about how to create the feed, review the Creating A Feed For The Advanced Post Creation Add-On article.

Expand the drop down for Type in the Post Settings section and select Product.

Scroll to the Post Content section and map the Title to the Product Name field.Map the Content to the Description field.Map the Featured Image to a File Upload field labeled Image. If the File Upload field is not present on your form this field will not appear in Post Creation settings.

Click Save Settings.

Note: The Price and Category will be handled separately because they cannot be directly mapped.

Handling Fields Unable to be Mapped

Not all fields needed for the product can directly be mapped in the feed. The gform_advancedpostcreation_post_after_creation action hook will be used to update the Price and Category for the product. Below are examples for two of the Product fields which need to be handled specially.

For more details about the hook parameters, placement, and usage, see the article mentioned above.

Price

The price information is stored in the wp_post_meta table and the update_post_meta() function will be used to save this information.

Category

The product category utilizes multiple WordPress taxonomy and term database tables and the wp_set_object_terms() function will be used to save this information.

The example below updates the Price using the value stored in field 7 of the entry. The Category is updated using the value stored in field 6 of the entry.

add_action( ‘gform_advancedpostcreation_post_after_creation’, ‘update_product_information’, 10, 4 );
function update_product_information( $post_id, $feed, $entry, $form ){

//update the prices set for the product
update_post_meta( $post_id, ‘_regular_price’, $entry[‘7’] );
update_post_meta( $post_id, ‘_price’, $entry[‘7’] );

//update the category
wp_set_object_terms( $post_id, $entry[‘6’], ‘product_cat’ );

}

Populating Drop Down with Product Categories

Note: This example expects the product categories to not have children. If there are child categories, the example will need to be modified as needed.

Several filters are needed to populate the drop down. The article Dynamically Populating Drop Down Or Radio Buttons Fields has more information. The filters used are:

gform_pre_rendergform_pre_submission_filtergform_admin_pre_rendergform_pre_validation

add_filter( ‘gform_pre_render_83’, ‘populate_dropdown_with_product_categories’ );
add_filter( ‘gform_pre_submission_filter_83’, ‘populate_dropdown_with_product_categories’ );
add_filter( ‘gform_admin_pre_render_83’, ‘populate_dropdown_with_product_categories’ );
add_filter( ‘gform_pre_validation_83’, ‘populate_dropdown_with_product_categories’ );
function populate_dropdown_with_product_categories( $form ) {
//product_cat is the taxonomy for WooCommerce’s products
//get the terms for the product_cat taxonomy
$product_categories = get_terms( ‘product_cat’ );

//Creating drop down item array.
$items = array();

//Adding initial blank value.
$items[] = array( ‘text’ => ”, ‘value’ => ” );

//Adding product category terms to the items array
foreach ( $product_categories as $product_category ) {
$items[] = array( ‘value’ => $product_category->name, ‘text’ => $product_category->name );
}

//Adding items to field id 6. Replace 6 with your actual field id. You can get the field id by looking at the input name in the markup.
foreach ( $form[‘fields’] as &$field ) {
if ( $field->id == 6 ) {
$field->choices = $items;
}
}

return $form;
}

Creating Events for The Events Calendar

Create the Form

Several pieces of information need to be captured to create an Event. Below captures some basic information.

Create a new form and add the following fields.

TypeLabelOther SettingsDrop DownCategorySee Populating Drop Down with Event Categories below for details.Single Line TextEvent Title ParagraphEvent Description CheckboxesEvent OptionsChoices: All Day, Hide From Event Listings, Sticky in Month View, Feature EventDateStart Date TimeStart TimeConditional Logic: Show field if Event Options is not All DayDateEnd Date TimeEnd TimeConditional Logic: Show field if Event Options is not All Day

Create the Advanced Post Creation Feed

For more details about how to create the feed, review the Creating A Feed For The Advanced Post Creation Add-On article.

Expand the drop down for Type in the Post Settings section and select Event.

Scroll to the Post Content section and map the Title to the Event Title field.Map the Content to the Event Description field.Scroll to the Taxonomies section and map the Event Categories to Field Value and Category field.

Click Save Settings.

Handling Fields Unable to be Mapped

Not all fields needed for the event can directly be mapped in the feed. The gform_advancedpostcreation_post_after_creation action hook will be used to update these fields. Below are examples for several fields which need to be handled specially.

For more details about the hook parameters, placement, and usage, see the article mentioned above.

add_action( ‘gform_advancedpostcreation_post_after_creation’, ‘update_event_information’, 10, 4 );
function update_event_information( $post_id, $feed, $entry, $form ){
//update the All Day setting
$all_day = $entry[‘9.1’];
if ( $all_day == ‘All Day’ ){
update_post_meta( $post_id, ‘_EventAllDay’, ‘yes’);
}

//update the Hide From Monthly View Setting
$hide = $entry[‘9.2’];
if ( $hide == ‘Hide From Event Listings’) {
update_post_meta( $post_id, ‘_EventHideFromUpcoming’, ‘yes’ );
}

//update the Sticky in Month View setting
$sticky = $entry[‘9.3’];
if ( $sticky == ‘Sticky in Month View’ ){
wp_update_post(array( ‘ID’ => $post_id, ‘menu_order’ => ‘-1’ ) );
}
else{
wp_update_post(array( ‘ID’ => $post_id, ‘menu_order’ => ‘0’ ) );
}

//update the Feature Event setting
$feature = $entry[‘9.4’];
if ( $feature == ‘Feature Event’){
update_post_meta( $post_id, ‘_tribe_featured’, ‘1’);
}
else{
update_post_meta( $post_id, ‘_tribe_featured’, ‘0’);
}
}

Populating Drop Down with Event Categories

Several filters are needed to populate the drop down. The article Dynamically Populating Drop Down Or Radio Buttons Fields has more information. The filters used are:

gform_pre_rendergform_pre_submission_filtergform_admin_pre_rendergform_pre_validation

//target form 80 (change to your form id)
add_filter( ‘gform_pre_render_80’, ‘populate_dropdown_with_event_categories’ );
add_filter( ‘gform_pre_submission_filter_80’, ‘populate_dropdown_with_event_categories’ );
add_filter( ‘gform_admin_pre_render_80’, ‘populate_dropdown_with_event_categories’ );
add_filter( ‘gform_pre_validation_80’, ‘populate_dropdown_with_event_categories’ );
function populate_dropdown_with_event_categories( $form ) {

$event_categories = get_terms( array(‘taxonomy’=>’tribe_events_cat’,’hide_empty’=>0 ) );
//Creating drop down item array.
$items = array();

//Adding initial blank value.
$items[] = array( ‘text’ => ”, ‘value’ => ” );

//Adding product category terms to the items array
foreach ( $event_categories as $event_category ) {
$items[] = array( ‘value’ => $event_category->name, ‘text’ => $event_category->name );
}

//Adding items to field id 10. Replace 10 with your actual field id. You can get the field id by looking at the input name in the markup.
foreach ( $form[‘fields’] as &$field ) {
if ( $field->id == 10 ) {
$field->choices = $items;
}
}

return $form;
}

Matching up Images with Advanced Custom Fields (ACF) or other Custom Fields

When images are stored to Custom Fields, they are written into Custom Post Meta with a value of the ID (or an array of id’s) that link to the Image in the Media Library. In order to properly map an Image Custom Field to an Upload Field added from Gravity Forms, you need to use the {apc_media} merge tag in the Custom Field Mapping for the Advanced Post Creation Feed.

Make sure the Field is copied to the Media Library

The file will not be available to be mapped properly to the Custom Meta if you don’t also copy that file to the Media Library. As long as you have added your image field as a File Upload Field, it will be available to copy the field to the Media Library. This will make sure that the field has a Post ID that is the ‘Image ID’ in ACF and other Custom Field plugins.

Map the Image Field to the Custom Field

You will need to perform this step for each image field you’re adding.

Under Custom Fields, Add a field mapping for your Image field. Select the ‘name’ of the field under Name.Under Value, Select “Add a Custom Value”Use the Merge Tag Tool to select your Image Field to place it’s merge tag in the ValueReplace the “Field Name” in the Merge tag with the apc_media merge tag actionAdd ids or urls as the return type to the end of your image tag

上次修改 2021.12.28

Advanced Post Creation Change Log

Advanced Post Creation Change Log

1.11.0 | 2021-07-211.0-beta-7.51.0-beta-7.41.0-beta-7.31.0-beta-7.21.0-beta-7.11.0-beta-7 | 2020-09-281.0-beta-6 | 2020-09-241.0-beta-5 | 2020-08-051.0-beta-4 | 2020-05-071.0-beta-3 | 2019-08-071.0-beta-2 | 2019-03-201.0-beta-1 | 2019-01-10

1.1

Fix a fatal error that occurs when a form is submitted with the date mapped to “Date & Time Fields” or “Custom Date & Time”.

1.0 | 2021-07-21

Official release.

1.0-beta-7.5

Fixed UI issues in the feed settings page where the post date setting don’t show options for the value selected.
API: Added gf_advancedpostcreation()->update_post( $post_id, $feed, $entry, $form ) to enable programmatic updating of posts.

1.0-beta-7.4

Fixed a compatibility issue with Gravity Forms 2.5 by updating the postExcerpt field to explicitly allow HTML.
Fixed an issue that causes custom dates and times entered into the feed settings to use UTC instead of the local time.

1.0-beta-7.3

Updated the post content field in the feed settings to use the text editor to enable easier markup entry.

1.0-beta-7.2

Added a custom icon for Gravity Forms 2.5.

1.0-beta-7.1

Updated the Swedish translations.

1.0-beta-7 | 2020-09-28

Fixed an issue with the feed settings.

1.0-beta-6 | 2020-09-24

Added support for Gravity Forms 2.5

1.0-beta-5 | 2020-08-05

Added support for WordPress 5.5.
Updated Post Format labels to be translatable.
Fixed a JavaScript error with WordPress 5.5 which prevents the taxonomy settings rendering correctly.
Fixed an issue where pending and draft posts created via the add-on do not have the correct post creation date when the date mappings are used in the post creation feed.
Fixed an issue where merge tags used in the custom value inputs of the categories and tags feed settings are not processed.

1.0-beta-4 | 2020-05-07

Added translations for Hebrew, Hindi, Japanese, and Turkish.
Added the {apc_media} merge tag to insert IDs or URLs of files uploaded to media library.
Updated Javascript files, stylesheets to use minified versions.
Fixed an issue where a taxonomy mapping which is removed on the feed configuration page can still be processed.
Fixed an issue where the wrong user could be assigned as the media author.
Fixed an issue attaching uploaded images as a featured image for a post when the image file has uppercase characters in the file extension.

1.0-beta-3 | 2019-08-07

Added security enhancements.
Added support for delaying feed processing until after payment has been successfully completed using the PayPal Standard Add-On.
Added the gform_advancedpostcreation_args_pre_get_custom_post_types filter enabling the arguments used to get the custom post types for inclusion in the types setting to be overridden.
Added the gform_advancedpostcreation_file_fields_choices filter enabling the available choices for the media settings to be overridden on the feed configuration page.
Added the gform_advancedpostcreation_term_separator filter enabling the ability to override the default comma separator with another string when terms are being assigned from the value of a field on a form with a post creation feed set up.
Added additional logging statements.
Updated + and – icons so that they are consistent across all settings.

1.0-beta-2 | 2019-03-20

Added support for {post_id} and {post_edit_url} merge tags.
Added support for setting post author when user is registered with User Registration Add-On.
Fixed an issue getting the default merge tags for the title, content, and excerpt settings when creating a new feed.
Fixed an issue where files could fail to be added to the media library on servers where allow_url_fopen is disabled.
Updated feed processing to store the uploaded media IDs in the entry meta along with the post and feed IDs.

1.0-beta-1 | 2019-01-10

It’s all new!

上次修改 2021.12.28

Advanced Post Creation vs Post Fields

Advanced Post Creation vs Post Fields

SummaryReference MaterialPost FieldsAdvantagesAdvanced Post CreationAdvantages

Summary

Each of these methods allow you to set up a form that upon submission automatically creates a new post with the data from the form.

The official Gravity Forms Advanced Post Creation Add-On (summarized here as “APC”) has some useful features that are not included in the standard Post Fields, and they do function differently. APC is created in the form settings while post fields are dragged and dropped directly on the form.

Reference Material

Post fields documentation.Advanced Post Creation Add-On documentation.

Post Fields

Post Fields are added to the form directly, and provide input fields for each of the major components of a post. In this way, you control the content of your post directly from the form fields themselves.

When the user submits a form that contains any post fields a standard post will be created with content from the post fields that were included.

Advantages

Simple to setup.Quickest method to create a simplistic standard post. Easy to manage for anyone who understands the form editor.

Advanced Post Creation

The Advanced Post Creation Add-On can utilize any fields on your form that match the required type, and the creation of the post is managed by the feed you set-up from within the Form Settings → Post Creation.

Note that forms to be used to initiate Advanced Post Creation feeds cannot use the standard Post fields.

Refer to this help guide for details on how to create an APC feed.

Advantages

Can be used with an existing form, and does not require (and cannot use) Post fields. Has the ability to create standard and custom posts. For example: Product, Event, Team Member postings.Offers additional post settings.Allows more control over the post content, using merge tags and static text. Allows you to utilize conditional logic, to have branching feed choices based on form data submitted.

上次修改 2021.12.28