Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/wpforms-.../src/Integrat.../AI/Admin/Builder
File: Forms.php
<?php
[0] Fix | Delete
[1] Fix | Delete
// phpcs:disable Generic.Commenting.DocComment.MissingShort
[2] Fix | Delete
/** @noinspection PhpIllegalPsrClassPathInspection */
[3] Fix | Delete
/** @noinspection AutoloadingIssuesInspection */
[4] Fix | Delete
// phpcs:enable Generic.Commenting.DocComment.MissingShort
[5] Fix | Delete
[6] Fix | Delete
namespace WPForms\Integrations\AI\Admin\Builder;
[7] Fix | Delete
[8] Fix | Delete
use WP_Post;
[9] Fix | Delete
use WPForms\Integrations\AI\Admin\Ajax\Forms as FormsAjax;
[10] Fix | Delete
use WPForms\Integrations\AI\Helpers;
[11] Fix | Delete
use WPForms\Integrations\LiteConnect\LiteConnect;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Enqueue assets on the Form Builder screen in Pro.
[15] Fix | Delete
*
[16] Fix | Delete
* @since 1.9.2
[17] Fix | Delete
* @since 1.9.4 Moved to the Lite plugin namespace.
[18] Fix | Delete
*/
[19] Fix | Delete
class Forms {
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Initialize.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 1.9.2
[25] Fix | Delete
*/
[26] Fix | Delete
public function init(): void {
[27] Fix | Delete
[28] Fix | Delete
$this->hooks();
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Register hooks.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 1.9.2
[35] Fix | Delete
*/
[36] Fix | Delete
private function hooks(): void {
[37] Fix | Delete
[38] Fix | Delete
add_action( 'wpforms_builder_enqueues', [ $this, 'enqueues' ] );
[39] Fix | Delete
add_filter( 'wpforms_integrations_ai_admin_builder_enqueues_localize_chat_strings', [ $this, 'add_localize_chat_data' ] );
[40] Fix | Delete
add_filter( 'wpforms_builder_template_active', [ $this, 'template_active' ], 10, 2 );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Enqueue styles and scripts.
[45] Fix | Delete
*
[46] Fix | Delete
* @since 1.9.2
[47] Fix | Delete
*
[48] Fix | Delete
* @param string|null $view Current view (panel).
[49] Fix | Delete
*
[50] Fix | Delete
* @noinspection PhpMissingParamTypeInspection
[51] Fix | Delete
* @noinspection PhpUnusedParameterInspection
[52] Fix | Delete
*/
[53] Fix | Delete
public function enqueues( $view ): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
[54] Fix | Delete
[55] Fix | Delete
$this->enqueue_styles();
[56] Fix | Delete
$this->enqueue_scripts();
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Enqueue styles.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 1.9.2
[63] Fix | Delete
*/
[64] Fix | Delete
private function enqueue_styles(): void {
[65] Fix | Delete
[66] Fix | Delete
$min = wpforms_get_min_suffix();
[67] Fix | Delete
[68] Fix | Delete
wp_enqueue_style(
[69] Fix | Delete
'wpforms-ai-forms',
[70] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/css/integrations/ai/ai-forms{$min}.css",
[71] Fix | Delete
[],
[72] Fix | Delete
WPFORMS_VERSION
[73] Fix | Delete
);
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Enqueue scripts.
[78] Fix | Delete
*
[79] Fix | Delete
* @since 1.9.2
[80] Fix | Delete
*/
[81] Fix | Delete
private function enqueue_scripts(): void {
[82] Fix | Delete
[83] Fix | Delete
$min = wpforms_get_min_suffix();
[84] Fix | Delete
[85] Fix | Delete
wp_enqueue_script(
[86] Fix | Delete
'wpforms-ai-form-generator',
[87] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/js/integrations/ai/form-generator/form-generator{$min}.js",
[88] Fix | Delete
[],
[89] Fix | Delete
WPFORMS_VERSION,
[90] Fix | Delete
true
[91] Fix | Delete
);
[92] Fix | Delete
[93] Fix | Delete
wp_localize_script(
[94] Fix | Delete
'wpforms-ai-form-generator',
[95] Fix | Delete
'wpforms_ai_form_generator',
[96] Fix | Delete
$this->get_localize_form_generator_data()
[97] Fix | Delete
);
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Set an active form template.
[102] Fix | Delete
*
[103] Fix | Delete
* @since 1.9.2
[104] Fix | Delete
*
[105] Fix | Delete
* @param array|mixed $details Details.
[106] Fix | Delete
* @param WP_Post|false $form Form data.
[107] Fix | Delete
*
[108] Fix | Delete
* @return array
[109] Fix | Delete
*/
[110] Fix | Delete
public function template_active( $details, $form ): array {
[111] Fix | Delete
[112] Fix | Delete
$details = (array) $details;
[113] Fix | Delete
[114] Fix | Delete
if ( empty( $form ) ) {
[115] Fix | Delete
return [];
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
$form_data = wpforms_decode( $form->post_content );
[119] Fix | Delete
[120] Fix | Delete
if ( empty( $form_data['meta']['template'] ) || $form_data['meta']['template'] !== 'generate' ) {
[121] Fix | Delete
return $details;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
return [
[125] Fix | Delete
'name' => esc_html__( 'Generate With AI', 'wpforms-lite' ),
[126] Fix | Delete
'slug' => 'generate',
[127] Fix | Delete
'description' => '',
[128] Fix | Delete
'includes' => '',
[129] Fix | Delete
'icon' => '',
[130] Fix | Delete
'modal' => '',
[131] Fix | Delete
'modal_display' => false,
[132] Fix | Delete
];
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Get form generator localize data.
[137] Fix | Delete
*
[138] Fix | Delete
* @since 1.9.2
[139] Fix | Delete
*
[140] Fix | Delete
* @return array
[141] Fix | Delete
* @noinspection HtmlUnknownTarget
[142] Fix | Delete
*/
[143] Fix | Delete
private function get_localize_form_generator_data(): array {
[144] Fix | Delete
[145] Fix | Delete
$min = wpforms_get_min_suffix();
[146] Fix | Delete
$addons_data = $this->get_required_addons_data();
[147] Fix | Delete
$modules_path = './modules/';
[148] Fix | Delete
[149] Fix | Delete
return [
[150] Fix | Delete
'nonce' => wp_create_nonce( 'wpforms-ai-nonce' ),
[151] Fix | Delete
'adminNonce' => wp_create_nonce( 'wpforms-admin' ),
[152] Fix | Delete
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
[153] Fix | Delete
'addonsData' => $addons_data,
[154] Fix | Delete
'addonsAction' => $this->get_required_addons_action( $addons_data ),
[155] Fix | Delete
'addonFields' => FormsAjax::FORM_GENERATOR_ADDON_FIELDS,
[156] Fix | Delete
'dismissed' => $this->get_dismissed_elements(),
[157] Fix | Delete
'isPro' => wpforms()->is_pro(),
[158] Fix | Delete
'isLicenseActive' => Helpers::is_license_active(),
[159] Fix | Delete
'licenseType' => Helpers::get_license_type(),
[160] Fix | Delete
'liteConnectEnabled' => LiteConnect::is_enabled(),
[161] Fix | Delete
'liteConnectAllowed' => LiteConnect::is_allowed(),
[162] Fix | Delete
'modules' => [
[163] Fix | Delete
'main' => $modules_path . "main{$min}.js?ver=" . WPFORMS_VERSION,
[164] Fix | Delete
'preview' => $modules_path . "preview{$min}.js?ver=" . WPFORMS_VERSION,
[165] Fix | Delete
'modals' => $modules_path . "modals{$min}.js?ver=" . WPFORMS_VERSION,
[166] Fix | Delete
],
[167] Fix | Delete
'templateCard' => [
[168] Fix | Delete
'imageSrc' => WPFORMS_PLUGIN_URL . 'assets/images/integrations/ai/ai-feature-icon.svg',
[169] Fix | Delete
'name' => esc_html__( 'Generate With AI', 'wpforms-lite' ),
[170] Fix | Delete
'desc' => esc_html__( 'Write simple prompts to create complex forms catered to your specific needs.', 'wpforms-lite' ),
[171] Fix | Delete
'buttonTextInit' => esc_html__( 'Generate Form', 'wpforms-lite' ),
[172] Fix | Delete
'buttonTextContinue' => esc_html__( 'Continue Generating', 'wpforms-lite' ),
[173] Fix | Delete
'new' => esc_html__( 'NEW!', 'wpforms-lite' ),
[174] Fix | Delete
'liteConnectNotAllowed' => esc_html__( 'WPForms AI is not available on local sites.', 'wpforms-lite' ),
[175] Fix | Delete
],
[176] Fix | Delete
'panel' => [
[177] Fix | Delete
'backToTemplates' => esc_html__( 'Back to Templates', 'wpforms-lite' ),
[178] Fix | Delete
'emptyStateTitle' => esc_html__( 'Build Your Form Fast With the Help of AI', 'wpforms-lite' ),
[179] Fix | Delete
'emptyStateDesc' => esc_html__( 'Not sure where to begin? Use our Generative AI tool to get started or take your pick from our wide variety of fields and start building out your form!', 'wpforms-lite' ),
[180] Fix | Delete
'submitButton' => esc_html__( 'Submit', 'wpforms-lite' ),
[181] Fix | Delete
'tooltipTitle' => esc_html__( 'This is just a preview of your form.', 'wpforms-lite' ),
[182] Fix | Delete
'tooltipText' => esc_html__( 'Click "Use This Form" to start editing.', 'wpforms-lite' ),
[183] Fix | Delete
],
[184] Fix | Delete
'addons' => [
[185] Fix | Delete
'installTitle' => esc_html__( 'Before We Proceed', 'wpforms-lite' ),
[186] Fix | Delete
'installContent' => esc_html__( 'In order to build the best forms possible, we need to install some addons. Would you like to install the recommended addons?', 'wpforms-lite' ),
[187] Fix | Delete
'activateContent' => esc_html__( 'In order to build the best forms possible, we need to activate some addons. Would you like to activate the recommended addons?', 'wpforms-lite' ),
[188] Fix | Delete
'installConfirmButton' => esc_html__( 'Yes, Install', 'wpforms-lite' ),
[189] Fix | Delete
'activateConfirmButton' => esc_html__( 'Yes, Activate', 'wpforms-lite' ),
[190] Fix | Delete
'cancelButton' => esc_html__( 'No, Thanks', 'wpforms-lite' ),
[191] Fix | Delete
'dontShow' => esc_html__( 'Don\'t show this again', 'wpforms-lite' ),
[192] Fix | Delete
'okay' => esc_html__( 'Okay', 'wpforms-lite' ),
[193] Fix | Delete
'installing' => esc_html__( 'Installing...', 'wpforms-lite' ),
[194] Fix | Delete
'activating' => esc_html__( 'Activating...', 'wpforms-lite' ),
[195] Fix | Delete
'addonsInstalledTitle' => esc_html__( 'Addons Installed', 'wpforms-lite' ),
[196] Fix | Delete
'addonsActivatedTitle' => esc_html__( 'Addons Activated', 'wpforms-lite' ),
[197] Fix | Delete
'addonsInstalledContent' => esc_html__( 'You’re all set. We’re going to reload the builder and you can start building your form.', 'wpforms-lite' ),
[198] Fix | Delete
'addonsInstallErrorTitle' => esc_html__( 'Addons Installation Error', 'wpforms-lite' ),
[199] Fix | Delete
'addonsActivateErrorTitle' => esc_html__( 'Addons Activation Error', 'wpforms-lite' ),
[200] Fix | Delete
'addonsInstallError' => esc_html__( 'Can\'t install or activate the required addons.', 'wpforms-lite' ),
[201] Fix | Delete
'addonsInstallErrorNetwork' => esc_html__( 'There appears to be a network error.', 'wpforms-lite' ),
[202] Fix | Delete
'dismissErrorTitle' => esc_html__( 'Error', 'wpforms-lite' ),
[203] Fix | Delete
'dismissError' => esc_html__( 'Can\'t dismiss the modal window.', 'wpforms-lite' ),
[204] Fix | Delete
'addon' => esc_html__( 'Addon', 'wpforms-lite' ),
[205] Fix | Delete
'and' => esc_html__( 'and', 'wpforms-lite' ),
[206] Fix | Delete
'addonInstalledTitle' => esc_html__( 'Addon Installed', 'wpforms-lite' ),
[207] Fix | Delete
'addonActivatedTitle' => esc_html__( 'Addon Activated', 'wpforms-lite' ),
[208] Fix | Delete
'addonInstalledContent' => esc_html__( 'You’re all set. We’re going to continue building your form.', 'wpforms-lite' ),
[209] Fix | Delete
],
[210] Fix | Delete
'quiz' => [
[211] Fix | Delete
'modalTitle' => esc_html__( 'Quiz Detected', 'wpforms-lite' ),
[212] Fix | Delete
'modalContent' => sprintf(
[213] Fix | Delete
wp_kses( /* translators: %1$s - Quiz addon doc link. */
[214] Fix | Delete
__( 'It looks like you\'re trying to create a quiz. Would you like to activate the <a href="%1$s" target="_blank" rel="noopener noreferrer">Quiz Addon</a> and easily create graded, personality, and weighted quizzes?', 'wpforms-lite' ),
[215] Fix | Delete
[
[216] Fix | Delete
'a' => [
[217] Fix | Delete
'href' => [],
[218] Fix | Delete
'rel' => [],
[219] Fix | Delete
'target' => [],
[220] Fix | Delete
],
[221] Fix | Delete
]
[222] Fix | Delete
),
[223] Fix | Delete
// @TODO: Confirm the URL.
[224] Fix | Delete
esc_url( wpforms_utm_link( 'https://wpforms.com/docs/quiz-addon/', 'builder-modal', 'Quiz Addon Documentation' ) )
[225] Fix | Delete
),
[226] Fix | Delete
],
[227] Fix | Delete
'previewNotice' => [
[228] Fix | Delete
'title' => esc_html__( 'This Form Would Be Even Better With Fields From', 'wpforms-lite' ),
[229] Fix | Delete
'msgUpgrade' => wp_kses( /* translators: %1$s - Upgrade to Pro link attributes. */
[230] Fix | Delete
__( '<a href="#">Upgrade to Pro</a> and gain access to all fields and create the best possible forms.', 'wpforms-lite' ),
[231] Fix | Delete
[
[232] Fix | Delete
'a' => [
[233] Fix | Delete
'href' => [],
[234] Fix | Delete
],
[235] Fix | Delete
]
[236] Fix | Delete
),
[237] Fix | Delete
'btnUpgrade' => esc_html__( 'Upgrade to Pro', 'wpforms-lite' ),
[238] Fix | Delete
'addons' => esc_html__( 'Addons', 'wpforms-lite' ),
[239] Fix | Delete
'dismiss' => esc_html__( 'Dismiss this notice', 'wpforms-lite' ),
[240] Fix | Delete
],
[241] Fix | Delete
'misc' => [
[242] Fix | Delete
'warningExistingForm' => esc_html__( 'You’re about to overwrite your existing form. This will delete all fields and reset external connections. Are you sure you want to continue?', 'wpforms-lite' ),
[243] Fix | Delete
'frozenChallengeTooltip' => esc_html__( 'The challenge will continue once AI form generation is complete', 'wpforms-lite' ),
[244] Fix | Delete
],
[245] Fix | Delete
];
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
/**
[249] Fix | Delete
* Add chat element localize data.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 1.9.2
[252] Fix | Delete
*
[253] Fix | Delete
* @param array $strings Strings.
[254] Fix | Delete
*
[255] Fix | Delete
* @return array
[256] Fix | Delete
* @noinspection PhpMissingParamTypeInspection
[257] Fix | Delete
* @noinspection HtmlUnknownTarget
[258] Fix | Delete
*/
[259] Fix | Delete
public function add_localize_chat_data( $strings ): array {
[260] Fix | Delete
[261] Fix | Delete
$for_lite = wpforms()->is_pro() ? '' : ' for Lite';
[262] Fix | Delete
[263] Fix | Delete
$strings['forms'] = [
[264] Fix | Delete
'title' => esc_html__( 'Generate a Form', 'wpforms-lite' ),
[265] Fix | Delete
'description' => esc_html__( 'Describe the form you would like to create or use one of the example prompts below to get started.', 'wpforms-lite' ),
[266] Fix | Delete
'descrEndDot' => '',
[267] Fix | Delete
'learnMore' => esc_html__( 'Learn More About WPForms AI', 'wpforms-lite' ),
[268] Fix | Delete
'learnMoreUrl' => wpforms_utm_link( 'https://wpforms.com/features/wpforms-ai/', 'Builder - Settings', 'Learn more - AI Forms' . $for_lite ),
[269] Fix | Delete
'inactiveAnswerTitle' => esc_html__( 'Go back to this version of the form', 'wpforms-lite' ),
[270] Fix | Delete
'useForm' => esc_html__( 'Use This Form', 'wpforms-lite' ),
[271] Fix | Delete
'placeholder' => esc_html__( 'What would you like to create?', 'wpforms-lite' ),
[272] Fix | Delete
'waiting' => esc_html__( 'Just a minute...', 'wpforms-lite' ),
[273] Fix | Delete
'errors' => [
[274] Fix | Delete
'default' => esc_html__( 'An error occurred while generating form.', 'wpforms-lite' ),
[275] Fix | Delete
'rate_limit' => esc_html__( 'Sorry, you\'ve reached your daily limit for generating forms.', 'wpforms-lite' ),
[276] Fix | Delete
],
[277] Fix | Delete
'footer' => [
[278] Fix | Delete
esc_html__( 'What do you think of the form I created for you? If you’re happy with it, you can use this form. Otherwise, make changes by entering additional prompts.', 'wpforms-lite' ),
[279] Fix | Delete
esc_html__( 'How’s that? Are you ready to use this form?', 'wpforms-lite' ),
[280] Fix | Delete
esc_html__( 'Does this look good? Are you ready to implement this form?', 'wpforms-lite' ),
[281] Fix | Delete
esc_html__( 'Is this what you had in mind? Are you satisfied with the results?', 'wpforms-lite' ),
[282] Fix | Delete
esc_html__( 'Happy with the form? Ready to move forward?', 'wpforms-lite' ),
[283] Fix | Delete
esc_html__( 'Is this form a good fit for your needs? Can we proceed?', 'wpforms-lite' ),
[284] Fix | Delete
esc_html__( 'Are you pleased with the outcome? Ready to use this form?', 'wpforms-lite' ),
[285] Fix | Delete
esc_html__( 'Does this form meet your expectations? Can we move on to the next step?', 'wpforms-lite' ),
[286] Fix | Delete
esc_html__( 'Is this form what you were envisioning? Are you ready to use it?', 'wpforms-lite' ),
[287] Fix | Delete
esc_html__( 'Satisfied with the form? Let\'s use it!', 'wpforms-lite' ),
[288] Fix | Delete
esc_html__( 'Does this form align with your goals? Are you ready to implement it?', 'wpforms-lite' ),
[289] Fix | Delete
esc_html__( 'Happy with the results? Let\'s put this form to work!', 'wpforms-lite' ),
[290] Fix | Delete
],
[291] Fix | Delete
'reasons' => [
[292] Fix | Delete
'default' => sprintf(
[293] Fix | Delete
wp_kses( /* translators: %1$s - Reload link class. */
[294] Fix | Delete
__( '<a href="#" class="%1$s">Reload this window</a> and try again.', 'wpforms-lite' ),
[295] Fix | Delete
[
[296] Fix | Delete
'a' => [
[297] Fix | Delete
'href' => [],
[298] Fix | Delete
'class' => [],
[299] Fix | Delete
],
[300] Fix | Delete
]
[301] Fix | Delete
),
[302] Fix | Delete
'wpforms-ai-chat-reload-link'
[303] Fix | Delete
),
[304] Fix | Delete
'rate_limit' => sprintf(
[305] Fix | Delete
wp_kses( /* translators: %s - WPForms contact support link. */
[306] Fix | Delete
__( 'You may only generate forms 50 times per day. If you believe this is an error, <a href="%s" target="_blank" rel="noopener noreferrer">please contact WPForms support</a>.', 'wpforms-lite' ),
[307] Fix | Delete
[
[308] Fix | Delete
'a' => [
[309] Fix | Delete
'href' => [],
[310] Fix | Delete
'target' => [],
[311] Fix | Delete
'rel' => [],
[312] Fix | Delete
],
[313] Fix | Delete
]
[314] Fix | Delete
),
[315] Fix | Delete
wpforms_utm_link( 'https://wpforms.com/account/support/', 'AI Feature' )
[316] Fix | Delete
),
[317] Fix | Delete
],
[318] Fix | Delete
'samplePrompts' => [
[319] Fix | Delete
[
[320] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-restaurant',
[321] Fix | Delete
'title' => esc_html__( 'Restaurant customer satisfaction survey', 'wpforms-lite' ),
[322] Fix | Delete
],
[323] Fix | Delete
[
[324] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-ticket',
[325] Fix | Delete
'title' => esc_html__( 'Online event registration', 'wpforms-lite' ),
[326] Fix | Delete
],
[327] Fix | Delete
[
[328] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-design',
[329] Fix | Delete
'title' => esc_html__( 'Job application for a web designer', 'wpforms-lite' ),
[330] Fix | Delete
],
[331] Fix | Delete
[
[332] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-stop',
[333] Fix | Delete
'title' => esc_html__( 'Cancellation survey for a subscription', 'wpforms-lite' ),
[334] Fix | Delete
],
[335] Fix | Delete
[
[336] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-pizza',
[337] Fix | Delete
'title' => esc_html__( 'Takeout order for a pizza store', 'wpforms-lite' ),
[338] Fix | Delete
],
[339] Fix | Delete
[
[340] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-market',
[341] Fix | Delete
'title' => esc_html__( 'Market vendor application', 'wpforms-lite' ),
[342] Fix | Delete
],
[343] Fix | Delete
[
[344] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-quiz-capitals',
[345] Fix | Delete
'title' => esc_html__( 'How well do you know world capitals?', 'wpforms-lite' ),
[346] Fix | Delete
'prompt' => esc_html__( 'Create a graded quiz on the topic of "How well do you know world capitals?" with 10 questions and 3 answers each. Randomize the choices. Collect the user\'s name and email address. Create 4 outcomes set to Graded Quiz type with appropriate text for each grade and utilize the available smart tags. The graded outcomes should be if Quiz Grade is A, if Quiz Grade is B, if Quiz Grade is C, if Quiz Grade is D, and if Quiz Grade is F.', 'wpforms-lite' ),
[347] Fix | Delete
],
[348] Fix | Delete
[
[349] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-quiz-learn',
[350] Fix | Delete
'title' => esc_html__( 'What is your ideal learning style?', 'wpforms-lite' ),
[351] Fix | Delete
'prompt' => esc_html__( 'Create a personality quiz on the topic of "What is your ideal learning style?" with 10 questions and 4 answers each. The personalities are Visual, Auditory, Reading/Writing, and Kinesthetic. Collect the user\'s name and email address. Create 4 outcomes set to Personality Quiz type with neutral text and utilize the available smart tags.', 'wpforms-lite' ),
[352] Fix | Delete
],
[353] Fix | Delete
[
[354] Fix | Delete
'icon' => 'wpforms-ai-chat-sample-quiz-business',
[355] Fix | Delete
'title' => esc_html__( 'How prepared are you to start a business?', 'wpforms-lite' ),
[356] Fix | Delete
'prompt' => esc_html__( 'Create a weighted quiz on the topic of "How prepared are you to start a business?" with 10 questions and 3 answers each. Collect the user\'s name and email address. Create 3 outcomes set to Weighted Quiz type for greater than 74%, less than 75% and greater than 49%, and less than 50%.', 'wpforms-lite' ),
[357] Fix | Delete
],
[358] Fix | Delete
],
[359] Fix | Delete
];
[360] Fix | Delete
[361] Fix | Delete
$user_id = get_current_user_id();
[362] Fix | Delete
[363] Fix | Delete
// Get the chat session stored in user meta.
[364] Fix | Delete
// phpcs:disable WordPress.Security.NonceVerification.Recommended
[365] Fix | Delete
if ( ! empty( $_GET['session'] ) ) {
[366] Fix | Delete
$session_id = sanitize_text_field( wp_unslash( $_GET['session'] ) );
[367] Fix | Delete
$meta = get_user_meta( $user_id, 'wpforms_builder_ai_form_chat_' . $session_id, true );
[368] Fix | Delete
}
[369] Fix | Delete
// phpcs:enable WordPress.Security.NonceVerification.Recommended
[370] Fix | Delete
[371] Fix | Delete
// If we have the meta-data, add it to the strings.
[372] Fix | Delete
if ( ! empty( $meta ) ) {
[373] Fix | Delete
// Remove user meta after using it.
[374] Fix | Delete
delete_user_meta( $user_id, 'wpforms_builder_ai_form_chat_' . ( $session_id ?? '' ) );
[375] Fix | Delete
[376] Fix | Delete
$strings['forms']['chatHtml'] = $meta['chatHtml'];
[377] Fix | Delete
$strings['forms']['responseHistory'] = $meta['responseHistory'];
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
return $strings;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Get required addons' data.
[385] Fix | Delete
*
[386] Fix | Delete
* @since 1.9.2
[387] Fix | Delete
*
[388] Fix | Delete
* @return array
[389] Fix | Delete
*/
[390] Fix | Delete
private function get_required_addons_data(): array {
[391] Fix | Delete
[392] Fix | Delete
// The addon installation procedure has floating issues in PHP < 7.4.
[393] Fix | Delete
// It's better to skip the installation in this case to avoid addon installation errors.
[394] Fix | Delete
if ( PHP_VERSION_ID < 70400 ) {
[395] Fix | Delete
return [];
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
$addons_obj = wpforms()->obj( 'addons' );
[399] Fix | Delete
[400] Fix | Delete
if ( ! $addons_obj ) {
[401] Fix | Delete
return [];
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
$data = [];
[405] Fix | Delete
[406] Fix | Delete
// Get the URLs for the required addons.
[407] Fix | Delete
foreach ( FormsAjax::FORM_GENERATOR_REQUIRED_ADDONS as $slug ) {
[408] Fix | Delete
$addon = $addons_obj->get_addon( $slug );
[409] Fix | Delete
$data[ $slug ] = $this->get_required_addon_data( $addon );
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
return array_filter( $data );
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
/**
[416] Fix | Delete
* Get required addon data.
[417] Fix | Delete
*
[418] Fix | Delete
* @since 1.9.9
[419] Fix | Delete
*
[420] Fix | Delete
* @param array|mixed $addon Addon data.
[421] Fix | Delete
*
[422] Fix | Delete
* @return array|null
[423] Fix | Delete
*/
[424] Fix | Delete
private function get_required_addon_data( $addon ): ?array {
[425] Fix | Delete
[426] Fix | Delete
if (
[427] Fix | Delete
empty( $addon ) || // Exceptional case when `addons.json` is not loaded.
[428] Fix | Delete
[429] Fix | Delete
// This means that addon is already installed and active.
[430] Fix | Delete
( isset( $addon['status'] ) && $addon['status'] === 'active' ) ||
[431] Fix | Delete
[432] Fix | Delete
// This means that addon is not available in the current license.
[433] Fix | Delete
// We should skip in this case as it is impossible to install or activate the addon.
[434] Fix | Delete
( isset( $addon['action'] ) && $addon['action'] === 'upgrade' )
[435] Fix | Delete
) {
[436] Fix | Delete
return null;
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
return [
[440] Fix | Delete
'url' => $addon['url'] ?? '',
[441] Fix | Delete
'path' => $addon['path'] ?? '',
[442] Fix | Delete
];
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
/**
[446] Fix | Delete
* Get required addons action.
[447] Fix | Delete
*
[448] Fix | Delete
* @since 1.9.2
[449] Fix | Delete
*
[450] Fix | Delete
* @param array $addons_data Addons data.
[451] Fix | Delete
*
[452] Fix | Delete
* @return string
[453] Fix | Delete
*/
[454] Fix | Delete
private function get_required_addons_action( array $addons_data ): string {
[455] Fix | Delete
[456] Fix | Delete
if ( empty( $addons_data ) ) {
[457] Fix | Delete
return '';
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
foreach ( $addons_data as $data ) {
[461] Fix | Delete
if ( ! empty( $data['url'] ) ) {
[462] Fix | Delete
return 'install';
[463] Fix | Delete
}
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
return 'activate';
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
/**
[470] Fix | Delete
* Get dismissed elements data.
[471] Fix | Delete
*
[472] Fix | Delete
* @since 1.9.2
[473] Fix | Delete
*
[474] Fix | Delete
* @return array
[475] Fix | Delete
*/
[476] Fix | Delete
private function get_dismissed_elements(): array {
[477] Fix | Delete
[478] Fix | Delete
$user_id = get_current_user_id();
[479] Fix | Delete
[480] Fix | Delete
// Dismissed elements.
[481] Fix | Delete
$dismissed = get_user_meta( $user_id, 'wpforms_dismissed', true );
[482] Fix | Delete
[483] Fix | Delete
return [
[484] Fix | Delete
'installAddons' => ! empty( $dismissed['edu-ai-forms-install-addons-modal'] ),
[485] Fix | Delete
'previewNotice' => ! empty( $dismissed['edu-ai-forms-preview-addons-notice'] ),
[486] Fix | Delete
];
[487] Fix | Delete
}
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function