rmdir( $dir, true ); } } function velischat_get_plugin_version(){ static $version = null; if( null === $version ){ $data = get_file_data( VELISCHAT_FILE, array( 'Version' => 'Version' ) ); $version = (string) $data[ 'Version' ]; } return $version; } function velischat_get_site_domain(){ // This site's host: lowercase, no scheme, www, port or path $host = strtolower( (string) wp_parse_url( home_url(), PHP_URL_HOST ) ); $host = rtrim( $host, '.' ); return 0 === strpos( $host, 'www.' ) ? substr( $host, 4 ) : $host; } function velischat_should_show_branding(){ // The "VelisChat is the AI chatbot for WordPress" line below the text field: only when the site owner turned it on return get_option( 'velischat_show_branding', '' ) === '1'; } function velischat_get_ai_tools(){ // Functions the AI can call, added by the add-ons: groups with a "functionDeclarations" list, each one with name, // description and parameters (JSON schema), as in the "tools" field of Gemini's generateContent return (array) apply_filters( 'velischat_ai_tools', array() ); } function velischat_run_ai_function( $name, $args ){ // Run a function called by the AI and return what it gets back: the add-on that owns it answers return apply_filters( 'velischat_ai_function_result', array( 'ok' => false, 'errors' => array( 'Unknown function.' ) ), $name, is_array( $args ) ? $args : array() ); } function velischat_ai_fallback_reply(){ // Line shown when the AI called a function but wrote no text: empty unless an add-on has something to show return (string) apply_filters( 'velischat_ai_fallback_reply', '' ); } function velischat_summary_error_text( $cause ){ // Why a text asked to the AI wasn't generated: shown to the site owner. Add-ons that ask for other kinds of text // can word it their own way /* translators: %s: cause, often the error message of the AI service, in English */ return (string) apply_filters( 'velischat_generate_text_error', sprintf( __( 'Summary not generated: %s', 'velischat' ), $cause ), $cause ); } function velischat_summary_cut_text( $reason ){ // Cause of a summary the AI service stopped before the end, with the reason it gave (e.g. "max_tokens") return $reason !== '' /* translators: %s: reason given by the AI service, e.g. "max_tokens" */ ? sprintf( __( 'the answer was cut off (%s).', 'velischat' ), $reason ) : __( 'the answer was cut off.', 'velischat' ); } function velischat_get_addon_name( $feature ){ // Name of the add-on that offers a feature, shown in the boxes that present it return (string) apply_filters( 'velischat_addon_name', 'ecommerce' === $feature ? 'Ecommerce' : 'Pro', $feature ); } function velischat_render_addon_note( $feature, $title, $text ){ // A box that tells about a feature of the VelisChat Pro add-on, with a link to its page $addon = velischat_get_addon_name( $feature ); ?>
'Pro', 'preview' => 'questions', 'title' => __( 'Do more with VelisChat Pro.', 'velischat' ), 'text' => __( 'Your chatbot already answers your visitors with your pages and posts. The Pro add-on, sold separately, makes it look exactly like your brand and tells you what visitors ask.', 'velischat' ), 'features' => array( array( 'dashicons-art', __( 'Your logo and your colors', 'velischat' ), __( 'Your own logo and icons, background, header and border colors, and more ready-made styles.', 'velischat' ) ), array( 'dashicons-backup', __( 'History and statistics', 'velischat' ), __( 'Reread every conversation and see what visitors ask the most.', 'velischat' ) ), array( 'dashicons-email-alt', __( 'Summary in the contact emails', 'velischat' ), __( 'Every contact request comes with a summary of the conversation.', 'velischat' ) ), array( 'dashicons-editor-contract', __( 'Automatic content summary', 'velischat' ), __( 'Shorter content for the assistant: faster and cheaper answers.', 'velischat' ) ), array( 'dashicons-pdf', __( 'PDF documents', 'velischat' ), __( 'Menus, price lists and brochures from the Media Library, scans too: the assistant answers with what they say.', 'velischat' ) ), array( 'dashicons-translation', __( 'Multilingual texts and events', 'velischat' ), __( 'Texts for every WPML or Polylang language, and the events of The Events Calendar.', 'velischat' ) ), ), 'note' => __( 'Need a shop assistant? The Ecommerce version of the add-on adds your WooCommerce catalog and the cart.', 'velischat' ), ); return apply_filters( 'velischat_upgrade_offer', $offer ); } define( 'VELISCHAT_UPGRADE_BANNER_PAUSE', 30 * DAY_IN_SECONDS ); function velischat_upgrade_banner_hidden(){ // The current user closed the banner less than 30 days ago (saved per user and per site) return (int) get_user_option( 'velischat_upgrade_hidden' ) > time(); } function velischat_hide_upgrade_banner(){ // The banner's ✕: hidden for 30 days for this user. By AJAX from admin.js, or as a plain link without JavaScript check_admin_referer( 'velischat_hide_upgrade_banner' ); if( ! current_user_can( 'manage_options' ) ){ wp_die( esc_html__( 'You don\'t have permission to do that.', 'velischat' ), 403 ); } update_user_option( get_current_user_id(), 'velischat_upgrade_hidden', time() + VELISCHAT_UPGRADE_BANNER_PAUSE ); if( wp_doing_ajax() ){ wp_send_json_success(); } wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'admin.php?page=velischat' ) ); exit; } add_action( 'admin_post_velischat_hide_upgrade_banner', 'velischat_hide_upgrade_banner' ); add_action( 'wp_ajax_velischat_hide_upgrade_banner', 'velischat_hide_upgrade_banner' ); function velischat_render_upgrade_banner(){ // Banner at the bottom of every plugin page: what the add-on adds, with a link to its page $offer = velischat_get_upgrade_offer(); if( null === $offer || velischat_upgrade_banner_hidden() ){ return; } $addon = $offer[ 'addon' ]; // A second link the add-on can add, e.g. to its own settings: array( url, text ) $link = (array) apply_filters( 'velischat_upgrade_banner_link', array() ); // Works without JavaScript too: the link saves the choice and comes back to this page $hide_url = wp_nonce_url( admin_url( 'admin-post.php?action=velischat_hide_upgrade_banner' ), 'velischat_hide_upgrade_banner' ); ?>
velischat