Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/wpforms-.../src/Integrat.../AI/Admin/Builder
File: Enqueues.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
/**
[9] Fix | Delete
* Enqueue assets on the Form Builder screen.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 1.9.1
[12] Fix | Delete
*/
[13] Fix | Delete
class Enqueues {
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Initialize.
[17] Fix | Delete
*
[18] Fix | Delete
* @since 1.9.1
[19] Fix | Delete
*/
[20] Fix | Delete
public function init(): void {
[21] Fix | Delete
[22] Fix | Delete
$this->hooks();
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Register hooks.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 1.9.1
[29] Fix | Delete
*/
[30] Fix | Delete
private function hooks(): void {
[31] Fix | Delete
[32] Fix | Delete
add_action( 'wpforms_builder_enqueues', [ $this, 'enqueues' ] );
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Enqueue styles and scripts.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 1.9.1
[39] Fix | Delete
*
[40] Fix | Delete
* @param string|null $view Current view (panel).
[41] Fix | Delete
*
[42] Fix | Delete
* @noinspection PhpMissingParamTypeInspection
[43] Fix | Delete
* @noinspection PhpUnusedParameterInspection
[44] Fix | Delete
*/
[45] Fix | Delete
public function enqueues( $view ): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
[46] Fix | Delete
[47] Fix | Delete
$this->enqueue_styles();
[48] Fix | Delete
$this->enqueue_scripts();
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Enqueue styles.
[53] Fix | Delete
*
[54] Fix | Delete
* @since 1.9.1
[55] Fix | Delete
*/
[56] Fix | Delete
private function enqueue_styles(): void {
[57] Fix | Delete
[58] Fix | Delete
$min = wpforms_get_min_suffix();
[59] Fix | Delete
[60] Fix | Delete
wp_enqueue_style(
[61] Fix | Delete
'wpforms-ai-modal',
[62] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/css/integrations/ai/modal{$min}.css",
[63] Fix | Delete
[],
[64] Fix | Delete
WPFORMS_VERSION
[65] Fix | Delete
);
[66] Fix | Delete
[67] Fix | Delete
wp_enqueue_style(
[68] Fix | Delete
'wpforms-ai-chat-element',
[69] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/css/integrations/ai/chat-element{$min}.css",
[70] Fix | Delete
[],
[71] Fix | Delete
WPFORMS_VERSION
[72] Fix | Delete
);
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Enqueue scripts.
[77] Fix | Delete
*
[78] Fix | Delete
* @since 1.9.1
[79] Fix | Delete
*/
[80] Fix | Delete
private function enqueue_scripts(): void {
[81] Fix | Delete
[82] Fix | Delete
$min = wpforms_get_min_suffix();
[83] Fix | Delete
[84] Fix | Delete
wp_enqueue_script(
[85] Fix | Delete
'wpforms-ai-dock',
[86] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/js/integrations/ai/chat-element/wpforms-ai-dock{$min}.js",
[87] Fix | Delete
[],
[88] Fix | Delete
WPFORMS_VERSION,
[89] Fix | Delete
false
[90] Fix | Delete
);
[91] Fix | Delete
[92] Fix | Delete
wp_enqueue_script(
[93] Fix | Delete
'wpforms-ai-modal',
[94] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/js/integrations/ai/choices/wpforms-ai-modal{$min}.js",
[95] Fix | Delete
[ 'wpforms-ai-dock' ],
[96] Fix | Delete
WPFORMS_VERSION,
[97] Fix | Delete
false
[98] Fix | Delete
);
[99] Fix | Delete
[100] Fix | Delete
wp_enqueue_script(
[101] Fix | Delete
'wpforms-ai-chat-element',
[102] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/js/integrations/ai/chat-element/wpforms-ai-chat-element{$min}.js",
[103] Fix | Delete
[],
[104] Fix | Delete
WPFORMS_VERSION,
[105] Fix | Delete
false
[106] Fix | Delete
);
[107] Fix | Delete
[108] Fix | Delete
wp_localize_script(
[109] Fix | Delete
'wpforms-ai-chat-element',
[110] Fix | Delete
'wpforms_ai_chat_element',
[111] Fix | Delete
$this->get_localize_chat_data()
[112] Fix | Delete
);
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Get chat localize data.
[117] Fix | Delete
*
[118] Fix | Delete
* @since 1.9.1
[119] Fix | Delete
*
[120] Fix | Delete
* @return array
[121] Fix | Delete
*/
[122] Fix | Delete
private function get_localize_chat_data(): array {
[123] Fix | Delete
[124] Fix | Delete
$min = wpforms_get_min_suffix();
[125] Fix | Delete
[126] Fix | Delete
$strings = [
[127] Fix | Delete
'ajaxurl' => admin_url( 'admin-ajax.php' ),
[128] Fix | Delete
'nonce' => wp_create_nonce( 'wpforms-ai-nonce' ),
[129] Fix | Delete
'min' => wpforms_get_min_suffix(),
[130] Fix | Delete
'dislike' => esc_html__( 'Bad response', 'wpforms-lite' ),
[131] Fix | Delete
'refresh' => esc_html__( 'Clear chat history', 'wpforms-lite' ),
[132] Fix | Delete
'btnYes' => esc_html__( 'Yes, Continue', 'wpforms-lite' ),
[133] Fix | Delete
'btnCancel' => esc_html__( 'Cancel', 'wpforms-lite' ),
[134] Fix | Delete
'confirm' => [
[135] Fix | Delete
'refreshTitle' => esc_html__( 'Clear Chat History', 'wpforms-lite' ),
[136] Fix | Delete
'refreshMessage' => esc_html__( 'Are you sure you want to clear the AI chat history and start over?', 'wpforms-lite' ),
[137] Fix | Delete
],
[138] Fix | Delete
'errors' => [
[139] Fix | Delete
'default' => esc_html__( 'An error occurred.', 'wpforms-lite' ),
[140] Fix | Delete
'network' => esc_html__( 'There appears to be a network error.', 'wpforms-lite' ),
[141] Fix | Delete
'empty' => esc_html__( 'I\'m not sure what to do with that.', 'wpforms-lite' ),
[142] Fix | Delete
],
[143] Fix | Delete
'warnings' => [
[144] Fix | Delete
'prohibited_code' => esc_html__( 'Prohibited code has been removed.', 'wpforms-lite' ),
[145] Fix | Delete
],
[146] Fix | Delete
'reasons' => [
[147] Fix | Delete
'default' => esc_html__( 'Please try again.', 'wpforms-lite' ),
[148] Fix | Delete
'empty' => esc_html__( 'Please try a different prompt. You might need to be more descriptive.', 'wpforms-lite' ),
[149] Fix | Delete
'prohibited_code' => esc_html__( 'Only basic styling tags are permitted. All other code deemed unsafe has been removed.', 'wpforms-lite' ),
[150] Fix | Delete
],
[151] Fix | Delete
'choices' => $this->get_choices_chat_data(),
[152] Fix | Delete
'actions' => [], // Additional actions for js/integrations/ai/modules/api.js.
[153] Fix | Delete
'pinChat' => is_rtl() ? esc_html__( 'Dock to the Left', 'wpforms-lite' ) : esc_html__( 'Dock to the Right', 'wpforms-lite' ),
[154] Fix | Delete
'unpinChat' => esc_html__( 'Open in Popup', 'wpforms-lite' ),
[155] Fix | Delete
'close' => esc_html__( 'Close', 'wpforms-lite' ),
[156] Fix | Delete
];
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Allows loading additional modules from other addons.
[160] Fix | Delete
* See wpforms-calculations/src/Admin/Builder.php as example.
[161] Fix | Delete
* Used in js/integrations/ai/wpforms-ai-chat-element.js.
[162] Fix | Delete
*/
[163] Fix | Delete
$strings['modules'] = [
[164] Fix | Delete
[
[165] Fix | Delete
'name' => 'api',
[166] Fix | Delete
'path' => "./modules/api{$min}.js",
[167] Fix | Delete
],
[168] Fix | Delete
[
[169] Fix | Delete
'name' => 'text',
[170] Fix | Delete
'path' => "./modules/helpers-text{$min}.js",
[171] Fix | Delete
],
[172] Fix | Delete
[
[173] Fix | Delete
'name' => 'choices',
[174] Fix | Delete
'path' => "./modules/helpers-choices{$min}.js",
[175] Fix | Delete
],
[176] Fix | Delete
[
[177] Fix | Delete
'name' => 'forms',
[178] Fix | Delete
'path' => "./modules/helpers-forms{$min}.js",
[179] Fix | Delete
],
[180] Fix | Delete
];
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Filters the AI chat localize strings.
[184] Fix | Delete
*
[185] Fix | Delete
* @since 1.9.2
[186] Fix | Delete
*
[187] Fix | Delete
* @param array $strings Localize strings.
[188] Fix | Delete
*/
[189] Fix | Delete
return apply_filters( 'wpforms_integrations_ai_admin_builder_enqueues_localize_chat_strings', $strings );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Get choices chat data.
[194] Fix | Delete
*
[195] Fix | Delete
* @since 1.9.1
[196] Fix | Delete
*
[197] Fix | Delete
* @return array
[198] Fix | Delete
* @noinspection HtmlUnknownTarget
[199] Fix | Delete
* @noinspection PackedHashtableOptimizationInspection
[200] Fix | Delete
*/
[201] Fix | Delete
private function get_choices_chat_data(): array {
[202] Fix | Delete
[203] Fix | Delete
return [
[204] Fix | Delete
'title' => esc_html__( 'Generate Choices', 'wpforms-lite' ),
[205] Fix | Delete
'description' => esc_html__( 'Describe the choices you would like to create or use one of the examples below to get started.', 'wpforms-lite' ),
[206] Fix | Delete
'descrEndDot' => '.',
[207] Fix | Delete
'footer' => wp_kses(
[208] Fix | Delete
__( '<strong>What do you think of these choices?</strong> If you’re happy with them, you can insert these choices, or make changes by entering additional prompts.', 'wpforms-lite' ), // phpcs:ignore WordPress.WP.I18n.NoHtmlWrappedStrings
[209] Fix | Delete
[
[210] Fix | Delete
'strong' => [],
[211] Fix | Delete
]
[212] Fix | Delete
),
[213] Fix | Delete
'learnMore' => esc_html__( 'Learn More About WPForms AI', 'wpforms-lite' ),
[214] Fix | Delete
'warning' => esc_html__( 'It looks like you have some existing choices in this field. If you generate new choices, your existing choices will be overwritten. You can simply close this window if you’d like to keep your existing choices.', 'wpforms-lite' ),
[215] Fix | Delete
'placeholder' => esc_html__( 'What would you like to create?', 'wpforms-lite' ),
[216] Fix | Delete
'waiting' => esc_html__( 'Just a minute...', 'wpforms-lite' ),
[217] Fix | Delete
'insert' => esc_html__( 'Insert Choices', 'wpforms-lite' ),
[218] Fix | Delete
'learnMoreUrl' => wpforms_utm_link( 'https://wpforms.com/features/wpforms-ai/', 'Builder - Settings', 'Learn more - AI Choices modal' ),
[219] Fix | Delete
'errors' => [
[220] Fix | Delete
'default' => esc_html__( 'An error occurred while generating choices.', 'wpforms-lite' ),
[221] Fix | Delete
'rate_limit' => esc_html__( 'Sorry, you\'ve reached your daily limit for generating choices.', 'wpforms-lite' ),
[222] Fix | Delete
],
[223] Fix | Delete
'reasons' => [
[224] Fix | Delete
'rate_limit' => sprintf(
[225] Fix | Delete
wp_kses( /* translators: %s - WPForms contact support link. */
[226] Fix | Delete
__( 'You may only generate choices 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' ),
[227] Fix | Delete
[
[228] Fix | Delete
'a' => [
[229] Fix | Delete
'href' => [],
[230] Fix | Delete
'target' => [],
[231] Fix | Delete
'rel' => [],
[232] Fix | Delete
],
[233] Fix | Delete
]
[234] Fix | Delete
),
[235] Fix | Delete
wpforms_utm_link( 'https://wpforms.com/account/support/', 'AI Feature' )
[236] Fix | Delete
),
[237] Fix | Delete
],
[238] Fix | Delete
'warnings' => [
[239] Fix | Delete
'prohibited_code' => esc_html__( 'Prohibited code has been removed from your choices.', 'wpforms-lite' ),
[240] Fix | Delete
],
[241] Fix | Delete
'samplePrompts' => [
[242] Fix | Delete
[
[243] Fix | Delete
'icon' => 'wpforms-ai-chat-flag',
[244] Fix | Delete
'title' => esc_html__( 'american public holidays with dates in brackets', 'wpforms-lite' ),
[245] Fix | Delete
],
[246] Fix | Delete
[
[247] Fix | Delete
'icon' => 'wpforms-ai-chat-clover',
[248] Fix | Delete
'title' => esc_html__( 'provinces of canada ordered by population', 'wpforms-lite' ),
[249] Fix | Delete
],
[250] Fix | Delete
[
[251] Fix | Delete
'icon' => 'wpforms-ai-chat-thumbs-up',
[252] Fix | Delete
'title' => esc_html__( 'top 5 social networks in europe', 'wpforms-lite' ),
[253] Fix | Delete
],
[254] Fix | Delete
[
[255] Fix | Delete
'icon' => 'wpforms-ai-chat-globe',
[256] Fix | Delete
'title' => esc_html__( 'top 10 most spoken languages in the world', 'wpforms-lite' ),
[257] Fix | Delete
],
[258] Fix | Delete
[
[259] Fix | Delete
'icon' => 'wpforms-ai-chat-palm',
[260] Fix | Delete
'title' => esc_html__( 'top 20 most popular tropical travel destinations', 'wpforms-lite' ),
[261] Fix | Delete
],
[262] Fix | Delete
[
[263] Fix | Delete
'icon' => 'wpforms-ai-chat-shop',
[264] Fix | Delete
'title' => esc_html__( '30 household item categories for a marketplace', 'wpforms-lite' ),
[265] Fix | Delete
],
[266] Fix | Delete
],
[267] Fix | Delete
'defaults' => [
[268] Fix | Delete
'1' => esc_html__( 'First Choice', 'wpforms-lite' ),
[269] Fix | Delete
'2' => esc_html__( 'Second Choice', 'wpforms-lite' ),
[270] Fix | Delete
'3' => esc_html__( 'Third Choice', 'wpforms-lite' ),
[271] Fix | Delete
],
[272] Fix | Delete
];
[273] Fix | Delete
}
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function