Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev - Compatibility for AI. #1147

Merged
merged 9 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions assets/js/admin/evf-admin-email.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@
cloned_email.find('.everest-forms-csv-file-email-attachments input[type="checkbox"]').prop('checked', false);
cloned_email.find('.everest-forms-show-header-in-attachment-pdf-file input[type="checkbox"]').prop('checked', false);
cloned_email.find('.everest-forms-file-email-attachments input[type="checkbox"]').prop('checked', false);
cloned_email.find('.everest-forms-enable-email-prompt input[type="checkbox"]').prop('checked', false);
cloned_email.find('.evf-email-message-prompt textarea').val('');
cloned_email.find('.everest-forms-email-name input').val(name);

cloned_email.find('.everest-forms-show-header-in-attachment-pdf-file').hide();
cloned_email.find('.evf-email-message-prompt').hide();
cloned_email.find('.everest-forms-show-pdf-file-name').hide();
cloned_email.find('.evf-field-conditional-container').hide();
cloned_email.find('.evf-field-conditional-wrapper li:not(:first)').remove();
Expand Down Expand Up @@ -175,6 +179,7 @@
cloned_email.find('#everest_forms_panel_field_email_connection_1_evf_email_message').attr('name', 'settings[email]['+response.data.connection_id+'][evf_email_message]');
cloned_email.find('#everest_forms_panel_field_email_connection_1_evf_email_message').val( '{all_fields}' );


cloned_email.find('#everest-forms-panel-field-settingsemailconnection_1-file-email-attachments').attr('name', 'settings[email]['+response.data.connection_id+'][file-email-attachments]');
cloned_email.find('#everest-forms-panel-field-settingsemailconnection_1-file-email-attachments').val(1);
cloned_email.find('#everest-forms-panel-field-settingsemailconnection_1-file-email-attachments').attr('id', 'everest-forms-panel-field-settingsemail'+response.data.connection_id+'-file-email-attachments');
Expand All @@ -193,6 +198,15 @@
cloned_email.find('label[for="everest-forms-panel-field-settingsemailconnection_1-csv-file-email-attachments"]').attr('for', 'everest-forms-panel-field-settingsemail'+response.data.connection_id+'-csv-file-email-attachments');
cloned_email.find('input[name="settings[email][connection_1][csv-file-email-attachments]"]').remove();

cloned_email.find('#everest-forms-panel-field-email-connection_1-enable_ai_email_prompt').attr('name', 'settings[email]['+response.data.connection_id+'][enable_ai_email_prompt]');
cloned_email.find('#everest-forms-panel-field-email-connection_1-enable_ai_email_prompt').val(1);
cloned_email.find('#everest-forms-panel-field-email-connection_1-enable_ai_email_prompt').attr('id', 'everest-forms-panel-field-settingsemail'+response.data.connection_id+'-enable_ai_email_prompt');
cloned_email.find('label[for="everest-forms-panel-field-email-connection_1-enable_ai_email_prompt"]').attr('for', 'everest-forms-panel-field-settingsemail'+response.data.connection_id+'-enable_ai_email_prompt');
cloned_email.find('input[name="settings[email][connection_1][enable_ai_email_prompt]"]').remove();

cloned_email.find('#everest-forms-panel-field-email-connection_1-evf_email_message_prompt').attr('name', 'settings[email]['+response.data.connection_id+'][evf_email_message_prompt]');


cloned_email.find('#everest-forms-panel-field-settingsemailconnection_1-show_header_in_attachment_pdf_file').attr('name', 'settings[email]['+response.data.connection_id+'][show_header_in_attachment_pdf_file]');
cloned_email.find('#everest-forms-panel-field-settingsemailconnection_1-show_header_in_attachment_pdf_file').val(1);
cloned_email.find('#everest-forms-panel-field-settingsemailconnection_1-show_header_in_attachment_pdf_file').attr('id', 'everest-forms-panel-field-settingsemail'+response.data.connection_id+'-show_header_in_attachment_pdf_file');
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin/evf-admin-email.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions assets/js/admin/form-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3207,11 +3207,13 @@ jQuery( function ( $ ) {

if( 'other' === type || 'all' === type ){
var other_smart_tags = evf_data.smart_tags_other;
console.log($(el));
for( var key in other_smart_tags ) {
$(el).parent().find('.evf-smart-tag-lists .evf-others').append('<li class = "smart-tag-field" data-type="other" data-field_id="'+key+'">'+other_smart_tags[key]+'</li>');
}
}


if( 'regex' == type ){
var regex_lists = evf_data.regex_expression_lists;
regex_lists.forEach(function(key,value) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin/form-builder.min.js

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion includes/admin/builder/class-evf-builder-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,47 @@ public function output_content() {
'subsection' => $connection_id,
)
);
// --------------------------------------------------------------------//
// Everest Forms AI Setting Section Start
// --------------------------------------------------------------------//
if ( ! empty( get_option( 'everest_forms_ai_api_key' ) ) ) {
everest_forms_panel_field(
'checkbox',
'email',
'enable_ai_email_prompt',
$this->form_data,
esc_html__( 'Enable email prompt', 'everest-forms' ),
array(
'default' => ! empty( $settings['email'][ $connection_id ]['enable_ai_email_prompt'] ) ? $settings['email'][ $connection_id ]['enable_ai_email_prompt'] : '0',
'class' => 'everest-forms-enable-email-prompt',
'tooltip' => sprintf( 'Enable the email prompt', 'everest-forms' ),
'parent' => 'settings',
'subsection' => $connection_id,
)
);
everest_forms_panel_field(
'textarea',
'email',
'evf_email_message_prompt',
$this->form_data,
esc_html__( 'Email Message Prompt', 'everest-forms' ),
array(
'default' => isset( $settings['email'][ $connection_id ]['evf_email_message_prompt'] ) ? $settings['email'][ $connection_id ]['evf_email_message_prompt'] : '',
'class' => isset( $settings['email'][ $connection_id ]['enable_ai_email_prompt'] ) && '1' === $settings['email'][ $connection_id ]['enable_ai_email_prompt'] ? 'evf-email-message-prompt' : 'evf-email-message-prompt everest-forms-hidden',
/* translators: %1$s - general settings docs url */
'tooltip' => sprintf( esc_html__( 'Enter the message of the email. <a href="%1$s" target="_blank">Learn More</a>', 'everest-forms' ), esc_url( 'https://docs.wpeverest.com/docs/everest-forms/individual-form-settings/email-settings/#email-message' ) ),
'smarttags' => array(
'type' => 'all',
'form_fields' => 'all',
),
'parent' => 'settings',
'subsection' => $connection_id,
)
);
}
// --------------------------------------------------------------------//
// Everest Forms AI Setting Section End
// --------------------------------------------------------------------//
everest_forms_panel_field(
'tinymce',
'email',
Expand All @@ -572,7 +613,7 @@ public function output_content() {
'parent' => 'settings',
'subsection' => $connection_id,
/* translators: %s - all fields smart tag. */
'after' => '<p class="desc">' . sprintf( esc_html__( 'To display all form fields, use the %s Smart Tag.', 'everest-forms' ), '<code>{all_fields}</code>' ) . '</p>',
'after' => empty( get_option( 'everest_forms_ai_api_key' ) ) ? '<p class="desc">' . sprintf( esc_html__( 'To display all form fields, use the %s Smart Tag.', 'everest-forms' ), '<code>{all_fields}</code>' ) . '</p>' : '<p class="desc">' . sprintf( esc_html__( 'To display all form fields, use the %1$s Smart Tag. Use %2$s Smart Tag for AI-generated emails', 'everest-forms' ), '<code>{all_fields}</code>', '<code>{ai_email_response}</code>' ) . '</p>',
)
);

Expand Down
6 changes: 4 additions & 2 deletions includes/admin/class-evf-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public static function save() {
do_action( 'everest_forms_settings_save_' . $current_tab );
do_action( 'everest_forms_update_options_' . $current_tab );
do_action( 'everest_forms_update_options' );

self::add_message( esc_html__( 'Your settings have been saved.', 'everest-forms' ) );
$flag = apply_filters( 'show_everest_forms_setting_message', true );
if ( $flag ) {
self::add_message( esc_html__( 'Your settings have been saved.', 'everest-forms' ) );
}

// Clear any unwanted data and flush rules.
update_option( 'everest_forms_queue_flush_rewrite_rules', 'yes' );
Expand Down
12 changes: 8 additions & 4 deletions includes/class-evf-form-task.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ public function entry_email( $fields, $entry, $form_data, $entry_id, $context =
$form_data['settings']['email'] = array();
$form_data['settings']['email']['connection_1'] = array( 'connection_name' => __( 'Admin Notification', 'everest-forms' ) );

$email_settings = array( 'evf_to_email', 'evf_from_name', 'evf_from_email', 'evf_reply_to', 'evf_email_subject', 'evf_email_message', 'attach_pdf_to_admin_email', 'show_header_in_attachment_pdf_file', 'conditional_logic_status', 'conditional_option', 'conditionals' );
$email_settings = array( 'evf_to_email', 'evf_from_name', 'evf_from_email', 'evf_reply_to', 'evf_email_subject', 'enable-ai-email-prompt', 'evf_email_message_prompt', 'evf_email_message', 'attach_pdf_to_admin_email', 'show_header_in_attachment_pdf_file', 'conditional_logic_status', 'conditional_option', 'conditionals' );
foreach ( $email_settings as $email_setting ) {
$form_data['settings']['email']['connection_1'][ $email_setting ] = isset( $old_email_data[ $email_setting ] ) ? $old_email_data[ $email_setting ] : '';
}
Expand Down Expand Up @@ -877,9 +877,13 @@ public function entry_email( $fields, $entry, $form_data, $entry_id, $context =
$email['sender_name'] = ! empty( $notification['evf_from_name'] ) ? $notification['evf_from_name'] : get_bloginfo( 'name' );
$email['sender_address'] = ! empty( $notification['evf_from_email'] ) ? $notification['evf_from_email'] : get_option( 'admin_email' );
$email['reply_to'] = ! empty( $notification['evf_reply_to'] ) ? $notification['evf_reply_to'] : $email['sender_address'];
$email['message'] = ! empty( $notification['evf_email_message'] ) ? evf_string_translation( $form_data['id'], 'evf_email_message', $notification['evf_email_message'] ) : '{all_fields}';
$email = apply_filters( 'everest_forms_entry_email_atts', $email, $fields, $entry, $form_data );
$attachment = '';
if ( ! empty( get_option( 'everest_forms_ai_api_key' ) ) ) {
$email['message_ai_prompt'] = ! empty( $notification['evf_email_message_prompt'] ) ? $notification['evf_email_message_prompt'] : '';
$email['enable_ai_prompt'] = ! empty( $notification['enable_ai_email_prompt'] ) ? $notification['enable_ai_email_prompt'] : 0;
}
$email['message'] = ! empty( $notification['evf_email_message'] ) ? evf_string_translation( $form_data['id'], 'evf_email_message', $notification['evf_email_message'] ) : '{all_fields}';
$email = apply_filters( 'everest_forms_entry_email_atts', $email, $fields, $entry, $form_data );
$attachment = '';

// Create new email.
$emails = new EVF_Emails();
Expand Down
1 change: 1 addition & 0 deletions includes/class-evf-forms-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function form_fields( $fields ) {
'EVF_Field_Yes_No',
'EVF_Field_Color',
'EVF_Field_Reset',
'EVF_Field_AI',
);

return array_merge( $fields, $pro_fields );
Expand Down
1 change: 1 addition & 0 deletions includes/class-evf-smart-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public function regex_expression_lists() {
return $regex_lists;
}


/**
* Process and parse smart tags.
*
Expand Down
29 changes: 29 additions & 0 deletions includes/fields/class-evf-field-ai.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* AI field
*
* @package EverestForms\Fields
* @since 1.9.9
*/

defined( 'ABSPATH' ) || exit;

/**
* EVF_Field_AI Class.
*/
class EVF_Field_AI extends EVF_Form_Fields {

/**
* Constructor.
*/
public function __construct() {
$this->name = esc_html__( 'AI', 'everest-forms' );
$this->type = 'ai';
$this->icon = 'evf-icon evf-icon-ai';
$this->order = 240;
$this->group = 'advanced';
$this->is_pro = true;

parent::__construct();
}
}
Loading