';
// Create form settings table rows and put them into an array.
// Form title.
$tr_form_title = '
' .
__( 'Form title', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_title', '', true ) .
'
';
// Form description.
$tr_form_description = '
' .
__( 'Form description', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_description', '', true ) .
'
';
// Form label placement.
$alignment_options = array(
'top_label' => __( 'Top aligned', 'gravityforms' ),
'left_label' => __( 'Left aligned', 'gravityforms' ),
'right_label' => __( 'Right aligned', 'gravityforms' )
);
$label_dd = '';
foreach ( $alignment_options as $value => $label ) {
$selected = $form['labelPlacement'] == $value ? 'selected="selected"' : '';
$label_dd .= '' . $label . ' ';
}
$tr_form_label_placement = '
' .
__( 'Label placement', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_label_placement', '', true ) .
'
' .
$label_dd .
'
';
// Form description placement.
$style = $form['labelPlacement'] != 'top_label' ? 'display:none;' : '';
$description_dd = '';
$description_options = array(
'below' => __( 'Below inputs', 'gravityforms' ),
'above' => __( 'Above inputs', 'gravityforms' )
);
foreach ( $description_options as $value => $label ) {
$selected = rgar( $form, 'descriptionPlacement' ) == $value ? 'selected="selected"' : '';
$description_dd .= '' . $label . ' ';
}
$tr_form_description_placement = '
' .
__( 'Description placement', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_description_placement', '', true ) .
'
' .
$description_dd .
'
';
// Sub-label placement.
$sub_label_placement_dd = '';
$sub_label_placement_options = array(
'below' => __( 'Below inputs', 'gravityforms' ),
'above' => __( 'Above inputs', 'gravityforms' )
);
foreach ( $sub_label_placement_options as $value => $label ) {
$selected = rgar( $form, 'subLabelPlacement' ) == $value ? 'selected="selected"' : '';
$sub_label_placement_dd .= '' . $label . ' ';
}
$tr_sub_label_placement = '
' .
__( 'Sub-Label Placement', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_sub_label_placement', '', true ) .
'
' .
$sub_label_placement_dd .
'
';
//css class name.
$tr_css_class_name = '
' .
__( 'CSS Class Name', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_css_class', '', true ) .
'
';
// Create form advanced settings table rows.
// Create form button rows.
$form_button_type = rgars( $form, 'button/type' );
$text_button_checked = '';
$image_button_checked = '';
$text_style_display = '';
$image_style_display = '';
if ( $form_button_type == 'text' ) {
$text_button_checked = 'checked="checked"';
$image_style_display = 'display:none;';
} else if ( $form_button_type == 'image' ) {
$image_button_checked = 'checked="checked"';
$text_style_display = 'display:none;';
}
// Form button.
$tr_form_button = '
' . __( 'Input type', 'gravityforms' ) . '
' .
__( 'Text', 'gravityforms' ) .
'
' .
__( 'Image', 'gravityforms' ) . '
';
// Form button text.
$tr_form_button_text = $subsetting_open . '
' .
__( 'Button text', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_button_text', '', true ) .
'
';
// Form button image path.
$tr_form_button_image_path = '
' .
__( 'Button image path', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_button_image', '', true ) .
'
' . $subsetting_close;
// Form button conditional logic.
$button_conditional_checked = '';
if ( rgars( $form, 'button/conditionalLogic' ) ) {
$button_conditional_checked = 'checked="checked"';
}
$tr_form_button_conditional = '
' . __( 'Button conditional logic', 'gravityforms' ) . ' ' . gform_tooltip( 'form_button_conditional_logic', '', true ) . '
' . ' ' . __( 'Enable Conditional Logic', 'gravityforms' ) . '
';
// Create save and continue rows.
$save_enabled_checked = '';
$save_enabled_style = '';
if ( rgars( $form, 'save/enabled' ) ) {
$save_enabled_checked = 'checked="checked"';
} else {
$save_enabled_style = 'style="display:none;"';
}
$save_button_text = isset( $form['save']['button']['text'] ) ? esc_attr( rgars( $form, 'save/button/text' ) ) : __( 'Save and Continue Later', 'gravityforms' );
$tr_enable_save = '
' . __( 'Save and Continue', 'gravityforms' ) . ' ' . gform_tooltip( 'form_enable_save', '', true ) . '
' . __( 'Enable Save and Continue', 'gravityforms' ) . '
';
// Warning.
$tr_save_warning = '
' . $subsetting_open . '
';
// Save button text.
$tr_save_button_text = '
' .
__( 'Link text', 'gravityforms' ) . ' ' .
gform_tooltip( 'form_save_button_text', '', true ) .
'
' . $subsetting_close . '
';
// Limit entries.
$limit_entry_checked = '';
$limit_entry_style = '';
$limit_entries_dd = '';
if ( rgar( $form, 'limitEntries' ) ) {
$limit_entry_checked = 'checked="checked"';
} else {
$limit_entry_style = 'display:none';
}
$limit_periods = array(
'' => __( 'total entries', 'gravityforms' ),
'day' => __( 'per day', 'gravityforms' ),
'week' => __( 'per week', 'gravityforms' ),
'month' => __( 'per month', 'gravityforms' ),
'year' => __( 'per year', 'gravityforms' )
);
foreach ( $limit_periods as $value => $label ) {
$selected = rgar( $form, 'limitEntriesPeriod' ) == $value ? 'selected="selected"' : '';
$limit_entries_dd .= '' . $label . ' ';
}
$tr_limit_entries = '
' . __( 'Limit number of entries', 'gravityforms' ) . ' ' . gform_tooltip( 'form_limit_entries', '', true ) . '
' . __( 'Enable entry limit', 'gravityforms' ) . '
';
// Limit entries count.
$tr_limit_entries_count = '
' . $subsetting_open . '
' .
__( 'Number of Entries', 'gravityforms' ) .
'
' .
$limit_entries_dd .
'
' . $subsetting_close . '
';
// Limit entries message.
$tr_limit_entries_message = '
' . $subsetting_open . '
' .
__( 'Entry Limit Reached Message', 'gravityforms' ) .
'
' . $subsetting_close . '
';
// Schedule form.
$schedule_form_checked = '';
$schedule_form_style = '';
$start_hour_dd = '';
$start_minute_dd = '';
$start_am_selected = '';
$start_pm_selected = '';
$end_hour_dd = '';
$end_minute_dd = '';
$end_am_selected = '';
$end_pm_selected = '';
if ( rgar( $form, 'scheduleForm' ) ) {
$schedule_form_checked = 'checked="checked"';
} else {
$schedule_form_style = 'display:none';
}
// Create start hour dd options.
for ( $i = 1; $i <= 12; $i ++ ) {
$selected = rgar( $form, 'scheduleStartHour' ) == $i ? 'selected="selected"' : '';
$start_hour_dd .= '' . $i . ' ';
}
// Create start minute dd options.
foreach ( array( '00', '15', '30', '45' ) as $value ) {
$selected = rgar( $form, 'scheduleStartMinute' ) == $value ? 'selected="selected"' : '';
$start_minute_dd .= '' . $value . ' ';
}
// Set start am/pm.
if ( rgar( $form, 'scheduleStartAmpm' ) == 'am' ) {
$start_am_selected = 'selected="selected"';
} elseif ( rgar( $form, 'scheduleStartAmpm' ) == 'pm' ) {
$start_pm_selected = 'selected="selected"';
}
// Create end hour dd options.
for ( $i = 1; $i <= 12; $i ++ ) {
$selected = rgar( $form, 'scheduleEndHour' ) == $i ? 'selected="selected"' : '';
$end_hour_dd .= '' . $i . ' ';
}
// Create end minute dd options.
foreach ( array( '00', '15', '30', '45' ) as $value ) {
$selected = rgar( $form, 'scheduleEndMinute' ) == $value ? 'selected="selected"' : '';
$end_minute_dd .= '' . $value . ' ';
}
// Set end am/pm.
if ( rgar( $form, 'scheduleEndAmpm' ) == 'am' ) {
$end_am_selected = 'selected="selected"';
} elseif ( rgar( $form, 'scheduleEndAmpm' ) == 'pm' ) {
$end_pm_selected = 'selected="selected"';
}
// Schedule form.
$tr_schedule_form = '
' . __( 'Schedule form', 'gravityforms' ) . ' ' . gform_tooltip( 'form_schedule_form', '', true ) . '
' . __( 'Schedule form', 'gravityforms' ) . '
';
// Schedule start.
$tr_schedule_start = '
' . $subsetting_open . '
' . __( 'Schedule Start Date/Time', 'gravityforms' ) . '
' .
$start_hour_dd .
'
:
' .
$start_minute_dd .
'
AM
PM
' . $subsetting_close . '
';
// Schedule end.
$tr_schedule_end = '
' . $subsetting_open . '
' . __( 'Schedule Form End Date/Time', 'gravityforms' ) . '
' .
$end_hour_dd .
'
:
' .
$end_minute_dd .
'
AM
PM
' . $subsetting_close . '
';
// Schedule message.
$tr_schedule_pending_message = '
' . $subsetting_open . '
' . __( 'Form Pending Message', 'gravityforms' ) . '
' . $subsetting_close . '
';
// Schedule message.
$tr_schedule_message = '
' . $subsetting_open . '
' . __( 'Form Expired Message', 'gravityforms' ) . '
' . $subsetting_close . '
';
// Honey pot.
$honey_pot_checked = '';
if ( rgar( $form, 'enableHoneypot' ) ) {
$honey_pot_checked = 'checked="checked"';
}
$tr_honey_pot = '
' . __( 'Anti-spam honeypot', 'gravityforms' ) . ' ' . gform_tooltip( 'form_honeypot', '', true ) . '
' . __( 'Enable anti-spam honeypot', 'gravityforms' ) . '
';
// Enable animation.
$enable_animation_checked = '';
if ( rgar( $form, 'enableAnimation' ) ) {
$enable_animation_checked = 'checked="checked"';
}
$tr_enable_animation = '
' . __( 'Animated transitions', 'gravityforms' ) . ' ' . gform_tooltip( 'form_animation', '', true ) . '
' . __( 'Enable animations', 'gravityforms' ) . '
';
// Require login.
$require_login_checked = '';
$require_login_style = '';
if ( rgar( $form, 'requireLogin' ) ) {
$require_login_checked = 'checked="checked"';
} else {
$require_login_style = 'display:none';
}
$tr_requires_login = '
' . __( 'Require user to be logged in', 'gravityforms' ) . ' ' . gform_tooltip( 'form_require_login', '', true ) . '
' . __( 'Require user to be logged in', 'gravityforms' ) . '
';
// Require login message.
$tr_requires_login_message = '
' . $subsetting_open . '
' . __( 'Require Login Message', 'gravityforms' ) . ' ' . gform_tooltip( 'form_require_login_message', '', true ) . '
' . $subsetting_close . '
';
// Populate arrays with table rows
$form_basics = array( 'form_title' => $tr_form_title, 'form_description' => $tr_form_description );
$form_layout = array( 'form_label_placement' => $tr_form_label_placement, 'form_description_placement' => $tr_form_description_placement, 'form_sub_label_placement' => $tr_sub_label_placement, 'css_class_name' => $tr_css_class_name );
$form_button = array( 'form_button_type' => $tr_form_button, 'form_button_text' => $tr_form_button_text, 'form_button_image_path' => $tr_form_button_image_path, 'form_button_conditional' => $tr_form_button_conditional );
$save_button = array( 'save_enabled' => $tr_enable_save, 'save_warning' => $tr_save_warning, 'save_button_text' => $tr_save_button_text );
$form_restrictions = array( 'limit_entries' => $tr_limit_entries, 'number_of_entries' => $tr_limit_entries_count, 'entry_limit_message' => $tr_limit_entries_message, 'schedule_form' => $tr_schedule_form, 'schedule_start' => $tr_schedule_start, 'schedule_end' => $tr_schedule_end, 'schedule_pending_message' => $tr_schedule_pending_message, 'schedule_message' => $tr_schedule_message, 'requires_login' => $tr_requires_login, 'requires_login_message' => $tr_requires_login_message );
$form_options = array( 'honey_pot' => $tr_honey_pot, 'enable_animation' => $tr_enable_animation );
$form_settings = array(
__( 'Form Basics', 'gravityforms' ) => $form_basics,
__( 'Form Layout', 'gravityforms' ) => $form_layout,
__( 'Form Button', 'gravityforms' ) => $form_button,
__( 'Save and Continue', 'gravityforms' ) => $save_button,
__( 'Restrictions', 'gravityforms' ) => $form_restrictions,
__( 'Form Options', 'gravityforms' ) => $form_options,
);
/**
* Filters the form settings before they are displayed.
*
* @since 1.7
*
* @param array $form_settings The form settings.
* @param array $form The Form Object.
*/
$form_settings = apply_filters( 'gform_form_settings', $form_settings, $form );
?>
0 ) );
?>
prepare_items();
?>
', '' );
GFCommon::add_dismissible_message( $dismissible_message, 'confirmation_unsafe_' . $form_id );
}
self::page_header( __( 'Confirmations', 'gravityforms' ) );
?>
';
$ui_settings = array();
$confirmation_type = rgar( $confirmation, 'type' ) ? rgar( $confirmation, 'type' ) : 'message';
$is_valid = ! empty( GFCommon::$errors );
$is_default = rgar( $confirmation, 'isDefault' );
$form_id = rgget( 'id' );
$form = RGFormsModel::get_form_meta( $form_id );
ob_start(); ?>
class="">
value="message" onclick="ToggleConfirmation();" onkeypress="ToggleConfirmation();" />
value="page" onclick="ToggleConfirmation();" onkeypress="ToggleConfirmation();" />
value="redirect" onclick="ToggleConfirmation();" onkeypress="ToggleConfirmation();" />
>
false, 'editor_class' => 'merge-tag-support mt-wp_editor mt-manual_position mt-position-right' ) );
?>
/>
class="">
'form_confirmation_page', 'selected' => rgar( $confirmation, 'pageId' ), 'show_option_none' => __( 'Select a page', 'gravityforms' ) ) ); ?>
class="">
onclick="TogglePageQueryString()" onkeypress="TogglePageQueryString()" />
>
>
onclick="ToggleQueryString()" onkeypress="ToggleQueryString()" />
>
array(
'name' => 'settings',
'label' => __( 'Form Settings', 'gravityforms' ),
'capabilities' => array( 'gravityforms_edit_forms' ),
),
'20' => array(
'name' => 'confirmation',
'label' => __( 'Confirmations', 'gravityforms' ),
'query' => array( 'cid' => null, 'duplicatedcid' => null ),
'capabilities' => array( 'gravityforms_edit_forms' ),
),
'30' => array(
'name' => 'notification',
'label' => __( 'Notifications', 'gravityforms' ),
'query' => array( 'nid' => null ),
'capabilities' => array( 'gravityforms_edit_forms' ),
),
'40' => array(
'name' => 'personal-data',
'label' => __( 'Personal Data', 'gravityforms' ),
'query' => array( 'nid' => null ),
'capabilities' => array( 'gravityforms_edit_forms' ),
),
);
/**
* Filters the settings tabs before they are returned.
*
* Tabs are not sorted yet, and will be sorted numerically.
*
* @since Unknown
*
* @param array $setting_tabs The settings tabs.
* @param int $form_id The ID of the form being accessed.
*/
$setting_tabs = apply_filters( 'gform_form_settings_menu', $setting_tabs, $form_id );
ksort( $setting_tabs, SORT_NUMERIC );
return $setting_tabs;
}
/**
* Handles the submission of confirmations page edits.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::confirmations_edit_page()
* @uses GFFormSettings::maybe_wp_kses()
* @uses GFFormsModel::sanitize_conditional_logic()
* @uses GFCommon::add_error_message()
* @uses GFCommon::is_valid_url()
* @uses GFCommon::has_merge_tag()
* @uses GFFormsModel::trim_conditional_logic_values_from_element()
* @uses GFFormsModel::save_form_confirmations()
* @uses GFCommon::add_message()
*
* @param array $confirmation The confirmation details.
* @param array $form The Form Object.
*
* @return array $confirmation The Confirmation that was submitted.
*/
public static function handle_confirmation_edit_submission( $confirmation, $form ) {
if ( empty( $_POST ) || ! check_admin_referer( 'gform_confirmation_edit', 'gform_confirmation_edit' ) ) {
return $confirmation;
}
$is_new_confirmation = ! $confirmation;
if ( $is_new_confirmation ) {
$confirmation['id'] = uniqid();
}
$name = sanitize_text_field( rgpost( 'form_confirmation_name' ) );
$confirmation['name'] = $name;
$type = rgpost( 'form_confirmation' );
if ( ! in_array( $type, array( 'message', 'page', 'redirect' ) ) ) {
$type = 'message';
}
$confirmation['type'] = $type;
// Filter HTML for users without the unfiltered_html capability
$confirmation_message = self::maybe_wp_kses( rgpost( 'form_confirmation_message' ) );
$failed_validation = false;
$confirmation['message'] = $confirmation_message;
$confirmation['disableAutoformat'] = (bool) rgpost( 'form_disable_autoformatting' );
$confirmation['pageId'] = absint( rgpost( 'form_confirmation_page' ) );
$confirmation['url'] = rgpost( 'form_confirmation_url' );
$query_string = '' != rgpost( 'form_redirect_querystring' ) ? rgpost( 'form_redirect_querystring' ) : rgpost( 'form_page_querystring' );
$confirmation['queryString'] = wp_strip_all_tags( $query_string );
$confirmation['isDefault'] = (bool) rgpost( 'is_default' );
// if is default confirmation, override any submitted conditional logic with empty array
$confirmation['conditionalLogic'] = $confirmation['isDefault'] ? array() : json_decode( rgpost( 'conditional_logic' ), ARRAY_A );
$confirmation['conditionalLogic'] = GFFormsModel::sanitize_conditional_logic( $confirmation['conditionalLogic'] );
if ( ! $confirmation['name'] ) {
$failed_validation = true;
GFCommon::add_error_message( __( 'You must specify a Confirmation Name.', 'gravityforms' ) );
}
switch ( $type ) {
case 'page':
if ( empty( $confirmation['pageId'] ) ) {
$failed_validation = true;
GFCommon::add_error_message( __( 'You must select a Confirmation Page.', 'gravityforms' ) );
}
break;
case 'redirect':
if ( ( empty( $confirmation['url'] ) || ! GFCommon::is_valid_url( $confirmation['url'] ) ) && ! GFCommon::has_merge_tag( $confirmation['url'] ) ) {
$failed_validation = true;
GFCommon::add_error_message( __( 'You must specify a valid Redirect URL.', 'gravityforms' ) );
}
break;
}
if ( $failed_validation ) {
return $confirmation;
}
/**
* Filters the confirmation before it is saved.
*
* @since Unknown
*
* @param array $confirmation The confirmation details.
* @param array $form The Form Object.
* @param bool $is_new_confirmation True if this is a new confirmation. False if editing existing.
*/
$confirmation = gf_apply_filters( array( 'gform_pre_confirmation_save', $form['id'] ), $confirmation, $form, $is_new_confirmation );
// trim values
$confirmation = GFFormsModel::trim_conditional_logic_values_from_element( $confirmation, $form );
// add current confirmation to confirmations array
$form['confirmations'][ $confirmation['id'] ] = $confirmation;
// save updated confirmations array
$result = GFFormsModel::save_form_confirmations( $form['id'], $form['confirmations'] );
if ( $result !== false ) {
$url = remove_query_arg( array( 'cid', 'duplicatedcid' ) );
GFCommon::add_message( sprintf( __( 'Confirmation saved successfully. %sBack to confirmations.%s', 'gravityforms' ), '', ' ' ) );
} else {
GFCommon::add_error_message( __( 'There was an issue saving this confirmation.', 'gravityforms' ) );
}
return $confirmation;
}
/**
* Processes actions made from the Confirmations List page.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::confirmations_list_page()
* @uses GFFormSettings::delete_confirmation()
* @uses GFCommon::add_message()
* @uses GFCommon::add_error_message()
*
* @return void
*/
public static function maybe_process_confirmation_list_action() {
if ( empty( $_POST ) || ! check_admin_referer( 'gform_confirmation_list_action', 'gform_confirmation_list_action' ) )
return;
$action = rgpost( 'action' );
$object_id = rgpost( 'action_argument' );
switch ( $action ) {
case 'delete':
$confirmation_deleted = self::delete_confirmation( $object_id, rgget( 'id' ) );
if ( $confirmation_deleted ) {
GFCommon::add_message( __( 'Confirmation deleted.', 'gravityforms' ) );
} else {
GFCommon::add_error_message( __( 'There was an issue deleting this confirmation.', 'gravityforms' ) );
}
break;
}
}
/**
* Delete a form confirmation by ID.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::maybe_process_confirmation_list_action()
* @used-by GFForms::delete_confirmation()
* @uses GFFormsModel::get_form_meta()
* @uses GFFormsModel::flush_current_forms()
* @uses GFFormsModel::save_form_confirmations()
*
* @param array $confirmation_id The confirmation to be deleted.
* @param int|array $form_id The form ID or Form Object form the confirmation being deleted.
*
* @return mixed The result of the database operation.
*/
public static function delete_confirmation( $confirmation_id, $form_id ) {
if ( ! $form_id )
return false;
$form = ! is_array( $form_id ) ? RGFormsModel::get_form_meta( $form_id ) : $form_id;
/**
* Fires right before a confirmation is deleted.
*
* @since 1.9
*
* @param int $form['confirmations'][$confirmation_id] The ID of the confirmation being deleted.
* @param array $form The Form object.
*/
do_action( 'gform_pre_confirmation_deleted', $form['confirmations'][ $confirmation_id ], $form );
unset( $form['confirmations'][ $confirmation_id ] );
// clear form cache so next retrieval of form meta will reflect deleted notification
RGFormsModel::flush_current_forms();
return RGFormsModel::save_form_confirmations( $form['id'], $form['confirmations'] );
}
/**
* Echos a variable.
*
* @since Unknown
* @access public
*
* @used-by GFNotification::notification_edit_page()
*
* @param string $a Thing to echo.
*
* @return void
*/
public static function output( $a ) {
echo $a;
}
/**
* Checks if a confirmation name is unique.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::confirmations_edit_page()
*
* @param string $name The confirmation name to check for.
* @param array $confirmations The confirmations to check through.
*
* @return bool True if unique. False otherwise.
*/
public static function is_unique_name( $name, $confirmations ) {
foreach ( $confirmations as $confirmation ) {
if ( strtolower( rgar( $confirmation, 'name' ) ) == strtolower( $name ) )
return false;
}
return true;
}
/**
* Outputs scripts for conditional logic fields.
*
* @since Unknown
* @access public
*
* @uses GF_Fields::get_all()
* @uses GF_Field::is_conditional_logic_supported()
*
* @param bool $echo If the scripts should be echoed. Defaults to true.
*
* @return string $script_str The scripts to be output.
*/
public static function output_field_scripts( $echo = true ) {
$script_str = '';
$conditional_logic_fields = array();
foreach ( GF_Fields::get_all() as $gf_field ) {
if ( $gf_field->is_conditional_logic_supported() ) {
$conditional_logic_fields[] = $gf_field->type;
}
}
$script_str .= sprintf( 'function GetConditionalLogicFields(){return %s;}', json_encode( $conditional_logic_fields ) ) . PHP_EOL;
if ( ! empty( $script_str ) && $echo ) {
echo $script_str;
}
return $script_str;
}
/**
* Handles the saving of notifications and confirmations when activated.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::form_settings_ui()
* @uses GFFormsModel::save_form_notifications()
* @uses GFFormsModel::save_form_confirmations()
*
* @param array $form The Form Object to be saved.
*
* @return array $form The Form Object.
*/
public static function activate_save( $form ) {
$form_id = $form['id'];
$has_save_notification = false;
foreach ( $form['notifications'] as $notification ) {
if ( rgar( $notification, 'event' ) == 'form_save_email_requested' ) {
$has_save_notification = true;
break;
}
}
if ( ! $has_save_notification ) {
$notification_id = uniqid();
$form['notifications'][ $notification_id ] = array(
'id' => $notification_id,
'isDefault' => true,
'name' => __( 'Save and Continue Email', 'gravityforms' ),
'event' => 'form_save_email_requested',
'toType' => 'hidden',
'from' => '{admin_email}',
'subject' => __( 'Link to continue {form_title}' ),
'message' => __( 'Thank you for saving {form_title}. Please use the unique link below to return to the form from any computer. {save_link} Remember that the link will expire after 30 days so please return via the provided link to complete your form submission.', 'gravityforms' ),
);
GFFormsModel::save_form_notifications( $form_id, $form['notifications'] );
}
$has_save_confirmation = false;
foreach ( $form['confirmations'] as $confirmation ) {
if ( rgar( $confirmation, 'event' ) == 'form_saved' ) {
$has_save_confirmation = true;
break;
}
}
if ( ! $has_save_confirmation ) {
$confirmation_1 = GFFormsModel::get_default_confirmation( 'form_saved' );
$confirmation_2 = GFFormsModel::get_default_confirmation( 'form_save_email_sent' );
$form['confirmations'][ $confirmation_1['id'] ] = $confirmation_1;
$form['confirmations'][ $confirmation_2['id'] ] = $confirmation_2;
GFFormsModel::save_form_confirmations( $form_id, $form['confirmations'] );
}
return $form;
}
/**
* Handles the saving of confirmation and notifications when deactivating.
*
* @since Unknown
* @access public
*
* @uses GFFormsModel::save_form_notifications()
* @uses GFFormsModel::save_form_confirmations()
*
* @param array $form The Form Object.
*
* @return array $form The Form Object.
*/
public static function deactivate_save( $form ) {
$form_id = $form['id'];
foreach ( $form['notifications'] as $notification_id => $notification ) {
if ( rgar( $notification, 'isDefault' ) && rgar( $notification, 'event' ) == 'form_save_email_requested' ) {
unset( $form['notifications'][ $notification_id ] );
GFFormsModel::save_form_notifications( $form_id, $form['notifications'] );
break;
}
}
$changed = false;
foreach ( $form['confirmations'] as $confirmation_id => $confirmation ) {
$event = rgar( $confirmation, 'event' );
if ( rgar( $confirmation, 'isDefault' ) && ( $event == 'form_saved' || $event == 'form_save_email_sent' ) ) {
unset( $form['confirmations'][ $confirmation_id ] );
$changed = true;
}
}
if ( $changed ) {
GFFormsModel::save_form_confirmations( $form_id, $form['confirmations'] );
}
return $form;
}
/**
* Alias for GFCommon::maybe_wp_kses()
*
* @since Unknown
* @access private
*
* @used-by GFFormSettings::handle_confirmation_edit_submission()
* @uses GFCommon::maybe_wp_kses()
*
* @param string $html The HTML markup to sanitize.
* @param string $allowed_html The allowed HTML content. Defaults to 'post'.
* @param array $allowed_protocols Allowed protocols. Defaults to empty array.
*
* @return string The sanitized HTML markup.
*/
private static function maybe_wp_kses( $html, $allowed_html = 'post', $allowed_protocols = array() ) {
if ( ! current_user_can( 'unfiltered_html' ) ) {
$html = self::remove_unsafe_merge_tags( $html );
}
return GFCommon::maybe_wp_kses( $html, $allowed_html, $allowed_protocols );
}
/**
* Removes merge tags used as HTML attributes.
*
* @since 2.0.7.8
* @access public
*
* @param string $text The confirmation text to check.
*
* @return bool True if unsafe. False if all is good in the world.
*/
public static function remove_unsafe_merge_tags( $text ) {
preg_match_all( '/(\S+)\s*=\s*["|\']({[^{]*?:(\d+(\.\d+)?)(:(.*?))?})["|\']/mi', $text, $matches, PREG_SET_ORDER );
if ( is_array( $matches ) && count( $matches ) > 0 ) {
foreach ( $matches as $match ) {
// Ignore conditional shortcodes
if ( strtolower( $match[1] ) !== 'merge_tag' ) {
// Remove the merge tag
$text = str_replace( $match[0], $match[1] . '=""', $text );
}
}
}
return $text;
}
/**
* Checks the text for merge tags as attribute values.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::confirmations_edit_page()
*
* @param string $text The confirmation text to check.
*
* @return bool True if unsafe. False if all is good in the world.
*/
public static function confirmation_looks_unsafe( $text ) {
$unsafe = false;
preg_match_all( '/[\<^]*.(\S+)\s*=\s*["|\']({[^{]*?:(\d+(\.\d+)?)(:(.*?))?})["|\']/mi', $text, $matches, PREG_SET_ORDER );
if ( is_array( $matches ) && count( $matches ) > 0 ) {
foreach ( $matches as $match ) {
if ( strtolower( $match[1] ) !== 'merge_tag' ) {
$unsafe = true;
}
}
}
return $unsafe;
}
/**
* Handles the saving of form titles.
*
* @since Unknown
* @access public
*
* @uses GFAPI::get_form()
* @uses GFAPI::update_form()
*
* @return void
*/
public static function save_form_title() {
check_admin_referer( 'gf_save_title', 'gf_save_title' );
$form_title = json_decode( rgpost( 'title' ) );
$form_id = rgpost( 'formId' );
$result = array( 'isValid' => true, 'message' => '' );
if ( empty( $form_title ) ) {
$result['isValid'] = false;
$result['message'] = __( 'Please enter a form title.', 'gravityforms' );
} elseif ( ! GFFormsModel::is_unique_title( $form_title, $form_id ) ) {
$result['isValid'] = false;
$result['message'] = __( 'Please enter a unique form title.', 'gravityforms' );
} else {
$form = GFAPI::get_form( $form_id );
$form['title'] = $form_title;
GFAPI::update_form( $form, $form_id );
}
die( json_encode( $result ) );
}
}
// Include WP_List_Table.
require_once( ABSPATH . '/wp-admin/includes/class-wp-list-table.php' );
/**
* Class GFConfirmationTable
*
* Handles the creation of a list table for displaying the confirmations listing.
*
* @since Unknown
*
* @used-by GFFormSettings::confirmations_list_page()
* @uses WP_List_Table
*
* @param array $form The form to display the confirmation listing for.
*/
class GFConfirmationTable extends WP_List_Table {
/**
* @since Unknown
* @access public
*
* @var array The Form Object to get confirmations from.
*/
public $form;
/**
* GFConfirmationTable constructor.
*
* @since Unknown
* @access public
*
* @uses GFConfirmationTable::$form
* @uses WP_List_Table::$_column_headers
* @uses WP_List_Table::__construct()
*
* @param array $form The Form Object to display the confirmation listing for.
*/
function __construct( $form ) {
$this->form = $form;
$this->_column_headers = array(
array(
'cb' => '',
'name' => __( 'Name', 'gravityforms' ),
'type' => __( 'Type', 'gravityforms' ),
'content' => __( 'Content', 'gravityforms' )
),
array(),
array( 'name' => array( 'name', false ) ),
'name',
);
parent::__construct();
}
/**
* Prepares the confirmation items.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::confirmations_list_page()
* @uses WP_List_Table::$items
* @uses GFConfirmationTable::$form
*
* @return void
*/
function prepare_items() {
$this->items = $this->form['confirmations'];
switch ( rgget( 'orderby' ) ) {
case 'name':
// Sort confirmations alphabetically.
usort( $this->items, array( $this, 'sort_confirmations' ) );
// Reverse sort.
if ( 'desc' === rgget( 'order' ) ) {
$this->items = array_reverse( $this->items );
}
break;
default:
break;
}
}
/**
* Sort confirmations alphabetically.
*
* @since 2.4
* @access public
*
* @param array $a First confirmation to compare.
* @param array $b Second confirmation to compare.
*
* @return int
*/
function sort_confirmations( $a = array(), $b = array() ) {
return strcasecmp( $a['name'], $b['name'] );
}
/**
* Displays the list table.
*
* @since Unknown
* @access public
*
* @used-by GFFormSettings::confirmations_list_page()
* @uses WP_List_Table::get_table_classes()
* @uses WP_List_Table::print_column_headers()
* @uses WP_List_Table::display_rows_or_placeholder()
*
* @return void
*/
function display() {
$singular = rgar( $this->_args, 'singular' );
?>
print_column_headers(); ?>
print_column_headers( false ); ?>
>
display_rows_or_placeholder(); ?>
';
echo $this->single_row_columns( $item );
echo '';
}
/**
* Gets the list table column headers.
*
* @since Unknown
* @access public
*
* @used-by WP_List_Table::get_default_primary_column_name()
* @uses WP_List_Table::$_column_headers
*
* @return string The primary column header.
*/
function get_columns() {
return $this->_column_headers[0];
}
/**
* Gets the column content.
*
* @since Unknown
* @access public
*
* @uses GFConfirmationTable::get_column_content()
*
* @param array $item The column item to process.
*
* @return string The column content HTML markup.
*/
function column_content( $item ) {
return self::get_column_content( $item );
}
/**
* Sets the default column data.
*
* @since Unknown
* @access public
*
* @used-by WP_List_Table::single_row_columns()
*
* @param object $item The column item.
* @param string $column The column name.
*
* @return void
*/
function column_default( $item, $column ) {
echo rgar( $item, $column );
}
/**
* Sets the column type.
*
* @since Unknown
* @access public
*
* @uses GFConfirmationTable::get_column_type()
*
* @param object $item The column item.
*
* @return string The column type.
*/
function column_type( $item ) {
return self::get_column_type( $item );
}
/**
* Handles the activation/deactivation button on confirmation list table items.
*
* @since Unknown
* @access public
*
* @used-by WP_List_Table::single_row_columns()
* @uses GFCommon::get_base_url()
*
* @param object $item The list table item.
*
* @return void
*/
function column_cb( $item ) {
if ( isset( $item['isDefault'] ) && $item['isDefault'] )
return;
$is_active = isset( $item['isActive'] ) ? $item['isActive'] : true;
?>
$item['id'] ) );
$duplicate_url = add_query_arg( array( 'cid' => 0, 'duplicatedcid' => $item['id'] ) );
$actions = apply_filters(
'gform_confirmation_actions', array(
'edit' => '' . __( 'Edit', 'gravityforms' ) . ' ',
'duplicate' => '' . __( 'Duplicate', 'gravityforms' ) . ' ',
'delete' => '' . __( 'Delete', 'gravityforms' ) . ' '
)
);
if ( isset( $item['isDefault'] ) && $item['isDefault'] ){
unset( $actions['delete'] );
}
?>
$html ) {
$divider = $key == $last_key ? '' : ' | ';
?>
' . wp_kses_post( $item['message'] ) . '';
case 'page':
$page = get_post( $item['pageId'] );
if ( empty( $page ) ) {
return __( 'This page does not exist. ', 'gravityforms' );
}
return '' . esc_html( $page->post_title ) . ' ';
case 'redirect':
$url_pieces = parse_url( $item['url'] );
$url_connector = rgar( $url_pieces, 'query' ) ? '&' : '?';
$url = rgar( $item, 'queryString' ) ? "{$item['url']}{$url_connector}{$item['queryString']}" : $item['url'];
$url = esc_url( $url );
return '' . $url . ' ';
}
return '';
}
/**
* Gets the column type.
*
* @since Unknwon
* @access public
*
* @used-by GFConfirmationTable::column_type()
*
* @param object $item The column item.
*
* @return string The column item type. If none found, empty string. Escaped.
*/
public static function get_column_type( $item ) {
switch ( rgar( $item, 'type' ) ) {
case 'message':
return __( 'Text', 'gravityforms' );
case 'page':
return __( 'Page', 'gravityforms' );
case 'redirect':
return __( 'Redirect', 'gravityforms' );
}
return '';
}
}