get_results( $wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- once, to rename the settings of old versions: no API lists options by prefix "SELECT option_name, autoload FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like( 'velislab_' ) . '%' ) ); foreach( $rows as $row ){ $new_name = 'velischat_' . substr( $row->option_name, strlen( 'velislab_' ) ); if( get_option( $new_name, null ) === null ){ $autoload = ! in_array( $row->autoload, array( 'no', 'off', 'auto-off' ), true ); add_option( $new_name, get_option( $row->option_name ), '', $autoload ); } delete_option( $row->option_name ); } update_option( 'velischat_legacy_migrated', 1 ); } add_action( 'plugins_loaded', 'velischat_migrate_legacy_options' ); /** * Scripts and styles */ function velischat_get_script_strings(){ // Texts written by the chatbot's script, translated here like the rest of the plugin return array( 'generic_error' => __( 'Something went wrong. Please contact the site owner for more information.', 'velischat' ), 'anything_else' => __( 'What else can I do for you?', 'velischat' ), 'pdf_user' => __( 'You —', 'velischat' ), 'pdf_assistant' => __( 'Assistant —', 'velischat' ), /* translators: %s: link "privacy policy" */ 'privacy_accept' => __( 'I accept the terms set out in the %s', 'velischat' ), 'privacy_link' => __( 'privacy policy', 'velischat' ), /* translators: 1: link "privacy policy", 2: site name */ 'privacy_read' => __( 'I accept the terms set out in the %1$s, and I accept that this whole conversation will be read by %2$s', 'velischat' ), 'site_owner' => __( 'the site owner', 'velischat' ), 'contact_intro' => __( 'Here is the contact form: fill it in below and we\'ll get back to you as soon as possible.', 'velischat' ), 'contact_title' => __( 'Write to us', 'velischat' ), 'contact_subtitle' => __( 'We\'ll reply as soon as possible', 'velischat' ), 'contact_submit' => __( 'Send request', 'velischat' ), 'contact_sending' => __( 'Sending...', 'velischat' ), 'contact_sent' => __( 'Message sent!', 'velischat' ), 'contact_back' => __( 'Back to the chat', 'velischat' ), 'contact_optional' => __( '(optional)', 'velischat' ), 'contact_select' => __( 'Select…', 'velischat' ), 'contact_message' => __( 'Briefly tell us what you need', 'velischat' ), 'contact_email' => __( 'name@example.com', 'velischat' ), 'contact_required' => __( 'Please fill in all the required fields.', 'velischat' ), 'contact_invalid' => __( 'Please enter a valid email address.', 'velischat' ), 'contact_privacy' => __( 'Please confirm that you have read the privacy policy.', 'velischat' ), 'contact_error' => __( 'The message could not be sent. Please try again later.', 'velischat' ), 'contact_thanks' => __( 'Thank you, your message has been sent! You will receive a reply as soon as possible.', 'velischat' ), ) + velischat_get_transcript_strings(); } function velischat_get_transcript_strings(){ // Labels of the conversation sent with the contact email: the site owner reads it, so in the site's main language $languages = velischat_get_languages(); $main = velischat_get_default_language(); $switched = $main !== '' && velischat_get_current_language() !== $main && $languages[ $main ][ 'locale' ] !== '' && switch_to_locale( $languages[ $main ][ 'locale' ] ); $strings = array( 'transcript_user' => __( 'USER', 'velischat' ), 'transcript_assistant' => __( 'ASSISTANT', 'velischat' ), ); if( $switched ){ restore_previous_locale(); } return $strings; } function velischat_enqueue_assets(){ // Enqueue frontend assets only for users allowed to see the chatbot if( ! velischat_can_use_chatbot() ){ return; } // Main assets wp_enqueue_style( 'velischat-style', VELISCHAT_URL . 'assets/css/style.css', array(), filemtime( VELISCHAT_PATH . 'assets/css/style.css' ) ); wp_enqueue_script( 'velischat-script', VELISCHAT_URL . 'assets/js/script.js', array( 'jquery' ), filemtime( VELISCHAT_PATH . 'assets/js/script.js' ), true ); // Add-ons add their own texts and settings for the script wp_localize_script( 'velischat-script', 'velischatData', apply_filters( 'velischat_script_data', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'velischat_nonce' ), // Language of the page, sent with every request: admin-ajax.php doesn't know it 'lang' => velischat_get_current_language(), 'contact_form' => velischat_get_contact_form_fields(), // What the visitor accepts before the first message 'consent' => velischat_get_consent(), // Who will read the conversation, named in the privacy checkbox 'site_name' => velischat_site_name(), // The privacy checkbox tells the user when the conversation will be summarized by the AI 'email_summary' => false, // The "VelisChat è il chatbot..." line is built by the script. Off until the site owner turns it on 'branding' => array( 'hidden' => ! velischat_should_show_branding(), /* translators: %s: "VelisChat", shown in bold blue like the logo */ 'text' => __( '%s is the AI chatbot for WordPress. Want it on your site?', 'velischat' ), 'link_text' => __( 'Learn more', 'velischat' ), 'url' => esc_url( VELISCHAT_BRANDING_URL ), ), 'i18n' => velischat_get_script_strings(), ) ) ); } add_action( 'wp_enqueue_scripts', 'velischat_enqueue_assets' ); // Everything is loaded: add-ons hook here to plug into the plugin's actions and filters do_action( 'velischat_loaded' );