Plugin Directory

Changeset 3777888


Ignore:
Timestamp:
11/01/2026 10:58:56 AM (6 hours ago)
Author:
easyagent
Message:

1.1.6: set the chat up from your site, Finish setting up box, sign-in fallback

Location:
eaforyou-ai-sales-chat
Files:
3 edited
6 copied

Legend:

Unmodified
Added
Removed
  • eaforyou-ai-sales-chat/tags/1.1.6/easyagent.php

    r3775250 r3777888  
    44 * Description:       An AI assistant trained on your site that answers visitors, captures leads and shows what it earned you, right inside wp-admin. Connect in one click, no API keys.
    55 * Plugin URI:        https://www.easyagentforyou.com/integrations/wordpress
    6  * Version:           1.1.5
     6 * Version:           1.1.6
    77 * Requires at least: 6.4
    88 * Requires PHP:      7.4
    … …  
    2121defined( 'ABSPATH' ) || exit;
    2222
    23 define( 'EASYAGENT_VERSION', '1.1.5' );
     23define( 'EASYAGENT_VERSION', '1.1.6' );
    2424define( 'EASYAGENT_FILE', __FILE__ );
    2525define( 'EASYAGENT_DIR', plugin_dir_path( __FILE__ ) );
  • eaforyou-ai-sales-chat/tags/1.1.6/includes/class-easyagent-admin.php

    r3775250 r3777888  
    3535                add_action( 'admin_post_easyagent_sso', array( $this, 'handle_sso' ) );
    3636                add_action( 'admin_post_easyagent_customize', array( $this, 'handle_customize' ) );
     37                add_action( 'admin_post_easyagent_setup', array( $this, 'handle_setup' ) );
    3738                add_action( 'admin_post_easyagent_refresh', array( $this, 'handle_refresh' ) );
    3839                add_action( 'admin_post_easyagent_woo_connect', array( $this, 'handle_woo_connect' ) );
    … …  
    252253
    253254        /**
     255         * "Finish setup in your dashboard": this site's page on the EAForYou
     256         * dashboard, where the setup checklist (train on your pages, add files) is.
     257         *
     258         * @return void
     259         */
     260        public function handle_setup() {
     261                $this->authorize( 'easyagent_setup' );
     262                $store_id = (string) EasyAgent_Options::embed()['store_id'];
     263                $this->open_dashboard( ctype_digit( $store_id ) ? '/dashboard/stores/' . $store_id : '/dashboard/stores' );
     264        }
     265
     266        /**
    254267         * Sign in to the dashboard and land on $next.
    255268         *
    … …  
    259272        private function open_dashboard( $next ) {
    260273                $result = EasyAgent_API::sso( $next );
    261                 if ( ! $result['ok'] && isset( $result['code'] ) && 'sso_disabled' === $result['code'] ) {
    262                         // Signing in from WordPress was not allowed when this site was connected:
    263                         // send the admin to the normal EasyAgent sign-in page instead. The
    264                         // sign-in page decodes `next` once more after the query string is read.
     274                if ( ! $result['ok'] && isset( $result['code'] ) && in_array( $result['code'], array( 'sso_disabled', 'sso_not_allowed' ), true ) ) {
     275                        // Signing in from WordPress was not allowed when this site was connected
     276                        // (or is never allowed for this account, such as a staff account): send
     277                        // the admin to the normal EAForYou sign-in page instead, which goes
     278                        // straight on to $next when they are already signed in. The sign-in
     279                        // page decodes `next` once more after the query string is read.
    265280                        $signin = EasyAgent_API::dashboard_url() . '/signin';
    266281                        if ( '' !== $next ) {
    … …  
    458473                $settings = EasyAgent_Options::settings();
    459474                $summary  = EasyAgent_API::summary();
    460                 if ( 'verifying' === $this->woo_state( $summary ) ) {
    461                         // The 10 minute cache must not hide the end of a connect that is in progress.
     475                if ( 'verifying' === $this->woo_state( $summary ) || $this->setup_in_progress( $summary ) ) {
     476                        // The 10 minute cache must not hide the end of a connect, or of the
     477                        // first read of the site, that is in progress.
    462478                        $summary = EasyAgent_API::summary( true );
    463479                }
    … …  
    505521                </div>
    506522                <?php
     523                $this->render_next_steps( $summary );
    507524                $this->render_woocommerce( $summary );
    508525                $this->render_results( $summary );
     526        }
     527
     528        /**
     529         * Whether EAForYou is still reading this site to set the chat up.
     530         *
     531         * @param array $summary Result of EasyAgent_API::summary().
     532         * @return bool
     533         */
     534        private function setup_in_progress( array $summary ) {
     535                $status = ( ! empty( $summary['ok'] ) && isset( $summary['data']['setup']['status'] ) ) ? $summary['data']['setup']['status'] : '';
     536                return in_array( $status, array( 'reading', 'not_started' ), true );
     537        }
     538
     539        /**
     540         * "Finish setting up": what EAForYou set up from this site, and the few
     541         * steps left (teach it the site's pages, add files, test it).
     542         *
     543         * @param array $summary Result of EasyAgent_API::summary().
     544         * @return void
     545         */
     546        private function render_next_steps( array $summary ) {
     547                $setup = ( ! empty( $summary['ok'] ) && isset( $summary['data']['setup'] ) && is_array( $summary['data']['setup'] ) ) ? $summary['data']['setup'] : null;
     548                if ( null === $setup ) {
     549                        return;
     550                }
     551                $status  = isset( $setup['status'] ) && is_string( $setup['status'] ) ? $setup['status'] : '';
     552                $label   = isset( $setup['business_label'] ) && is_string( $setup['business_label'] ) ? sanitize_text_field( $setup['business_label'] ) : '';
     553                $pages   = $this->int_value( $setup, 'page_count' );
     554                $trained = $this->int_value( $setup, 'trained_count' );
     555                $items   = array();
     556                if ( 'ready' === $status && ! empty( $setup['questions_set'] ) && '' !== $label ) {
     557                        /* translators: %s: kind of business, for example "Services business". */
     558                        $items[] = sprintf( __( 'Done: we read your site and set the chat\'s greeting and suggested questions for a %s.', 'eaforyou-ai-sales-chat' ), strtolower( $label ) );
     559                } elseif ( 'failed' === $status ) {
     560                        $items[] = __( 'We could not read your site, so the chat uses the standard questions. You can change them with Customize the chat.', 'eaforyou-ai-sales-chat' );
     561                } elseif ( 'ready' !== $status ) {
     562                        $items[] = __( 'We are reading your site to set up the chat\'s questions and colours. Check back in a minute.', 'eaforyou-ai-sales-chat' );
     563                }
     564                if ( $pages > 0 && $trained >= $pages ) {
     565                        /* translators: %d: number of pages. */
     566                        $items[] = sprintf( _n( 'Done: the chat has learned %d page of your site.', 'Done: the chat has learned %d pages of your site.', $trained, 'eaforyou-ai-sales-chat' ), $trained );
     567                } elseif ( $pages > 0 ) {
     568                        /* translators: %d: number of pages found on the site. */
     569                        $items[] = sprintf( _n( 'Teach it your site: we found %d page. Training it uses a few credits.', 'Teach it your site: we found %d pages. Training them uses a few credits.', $pages, 'eaforyou-ai-sales-chat' ), $pages );
     570                } else {
     571                        $items[] = __( 'Teach it your site, so it can answer from your pages.', 'eaforyou-ai-sales-chat' );
     572                }
     573                $items[] = __( 'Add files with your prices, FAQs or policies.', 'eaforyou-ai-sales-chat' );
     574                $items[] = __( 'Test it: open your site and ask the chat a question.', 'eaforyou-ai-sales-chat' );
     575                ?>
     576                <div class="easyagent-card">
     577                        <h2><?php esc_html_e( 'Finish setting up', 'eaforyou-ai-sales-chat' ); ?></h2>
     578                        <ul class="easyagent-list">
     579                                <?php foreach ( $items as $item ) : ?>
     580                                        <li><?php echo esc_html( $item ); ?></li>
     581                                <?php endforeach; ?>
     582                        </ul>
     583                        <div class="easyagent-actions">
     584                                <?php $this->action_form( 'easyagent_setup', __( 'Finish setup in your dashboard', 'eaforyou-ai-sales-chat' ), 'button button-primary', true ); ?>
     585                                <a class="button" href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Open your site', 'eaforyou-ai-sales-chat' ); ?></a>
     586                        </div>
     587                </div>
     588                <?php
    509589        }
    510590
  • eaforyou-ai-sales-chat/tags/1.1.6/readme.txt

    r3775250 r3777888  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.1.5
     7Stable tag: 1.1.6
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    147147== Changelog ==
    148148
     149= 1.1.6 =
     150* New: when you connect, EAForYou reads your site and sets the chat's greeting, suggested questions and colour for your kind of business. Anything you have already changed is kept.
     151* New: a *Finish setting up* box with the steps left: teach the chat your pages, add files with your prices or FAQs, and test it.
     152* Fixed: *Open full dashboard* and *Customize the chat* now open the EAForYou sign-in page when one-click sign-in is not available for your account, instead of staying on this page.
     153
    149154= 1.1.5 =
    150155* New: a *Customize the chat* button that opens this site's chat settings (colours, button, greeting) in your EAForYou dashboard.
    … …  
    176181== Upgrade Notice ==
    177182
     183= 1.1.6 =
     184Sets the chat up for your kind of business and adds a Finish setting up box. Your settings are kept.
     185
    178186= 1.1.5 =
    179187Adds a Customize the chat button. Nothing else changes.
  • eaforyou-ai-sales-chat/trunk/easyagent.php

    r3775250 r3777888  
    44 * Description:       An AI assistant trained on your site that answers visitors, captures leads and shows what it earned you, right inside wp-admin. Connect in one click, no API keys.
    55 * Plugin URI:        https://www.easyagentforyou.com/integrations/wordpress
    6  * Version:           1.1.5
     6 * Version:           1.1.6
    77 * Requires at least: 6.4
    88 * Requires PHP:      7.4
    … …  
    2121defined( 'ABSPATH' ) || exit;
    2222
    23 define( 'EASYAGENT_VERSION', '1.1.5' );
     23define( 'EASYAGENT_VERSION', '1.1.6' );
    2424define( 'EASYAGENT_FILE', __FILE__ );
    2525define( 'EASYAGENT_DIR', plugin_dir_path( __FILE__ ) );
  • eaforyou-ai-sales-chat/trunk/includes/class-easyagent-admin.php

    r3775250 r3777888  
    3535                add_action( 'admin_post_easyagent_sso', array( $this, 'handle_sso' ) );
    3636                add_action( 'admin_post_easyagent_customize', array( $this, 'handle_customize' ) );
     37                add_action( 'admin_post_easyagent_setup', array( $this, 'handle_setup' ) );
    3738                add_action( 'admin_post_easyagent_refresh', array( $this, 'handle_refresh' ) );
    3839                add_action( 'admin_post_easyagent_woo_connect', array( $this, 'handle_woo_connect' ) );
    … …  
    252253
    253254        /**
     255         * "Finish setup in your dashboard": this site's page on the EAForYou
     256         * dashboard, where the setup checklist (train on your pages, add files) is.
     257         *
     258         * @return void
     259         */
     260        public function handle_setup() {
     261                $this->authorize( 'easyagent_setup' );
     262                $store_id = (string) EasyAgent_Options::embed()['store_id'];
     263                $this->open_dashboard( ctype_digit( $store_id ) ? '/dashboard/stores/' . $store_id : '/dashboard/stores' );
     264        }
     265
     266        /**
    254267         * Sign in to the dashboard and land on $next.
    255268         *
    … …  
    259272        private function open_dashboard( $next ) {
    260273                $result = EasyAgent_API::sso( $next );
    261                 if ( ! $result['ok'] && isset( $result['code'] ) && 'sso_disabled' === $result['code'] ) {
    262                         // Signing in from WordPress was not allowed when this site was connected:
    263                         // send the admin to the normal EasyAgent sign-in page instead. The
    264                         // sign-in page decodes `next` once more after the query string is read.
     274                if ( ! $result['ok'] && isset( $result['code'] ) && in_array( $result['code'], array( 'sso_disabled', 'sso_not_allowed' ), true ) ) {
     275                        // Signing in from WordPress was not allowed when this site was connected
     276                        // (or is never allowed for this account, such as a staff account): send
     277                        // the admin to the normal EAForYou sign-in page instead, which goes
     278                        // straight on to $next when they are already signed in. The sign-in
     279                        // page decodes `next` once more after the query string is read.
    265280                        $signin = EasyAgent_API::dashboard_url() . '/signin';
    266281                        if ( '' !== $next ) {
    … …  
    458473                $settings = EasyAgent_Options::settings();
    459474                $summary  = EasyAgent_API::summary();
    460                 if ( 'verifying' === $this->woo_state( $summary ) ) {
    461                         // The 10 minute cache must not hide the end of a connect that is in progress.
     475                if ( 'verifying' === $this->woo_state( $summary ) || $this->setup_in_progress( $summary ) ) {
     476                        // The 10 minute cache must not hide the end of a connect, or of the
     477                        // first read of the site, that is in progress.
    462478                        $summary = EasyAgent_API::summary( true );
    463479                }
    … …  
    505521                </div>
    506522                <?php
     523                $this->render_next_steps( $summary );
    507524                $this->render_woocommerce( $summary );
    508525                $this->render_results( $summary );
     526        }
     527
     528        /**
     529         * Whether EAForYou is still reading this site to set the chat up.
     530         *
     531         * @param array $summary Result of EasyAgent_API::summary().
     532         * @return bool
     533         */
     534        private function setup_in_progress( array $summary ) {
     535                $status = ( ! empty( $summary['ok'] ) && isset( $summary['data']['setup']['status'] ) ) ? $summary['data']['setup']['status'] : '';
     536                return in_array( $status, array( 'reading', 'not_started' ), true );
     537        }
     538
     539        /**
     540         * "Finish setting up": what EAForYou set up from this site, and the few
     541         * steps left (teach it the site's pages, add files, test it).
     542         *
     543         * @param array $summary Result of EasyAgent_API::summary().
     544         * @return void
     545         */
     546        private function render_next_steps( array $summary ) {
     547                $setup = ( ! empty( $summary['ok'] ) && isset( $summary['data']['setup'] ) && is_array( $summary['data']['setup'] ) ) ? $summary['data']['setup'] : null;
     548                if ( null === $setup ) {
     549                        return;
     550                }
     551                $status  = isset( $setup['status'] ) && is_string( $setup['status'] ) ? $setup['status'] : '';
     552                $label   = isset( $setup['business_label'] ) && is_string( $setup['business_label'] ) ? sanitize_text_field( $setup['business_label'] ) : '';
     553                $pages   = $this->int_value( $setup, 'page_count' );
     554                $trained = $this->int_value( $setup, 'trained_count' );
     555                $items   = array();
     556                if ( 'ready' === $status && ! empty( $setup['questions_set'] ) && '' !== $label ) {
     557                        /* translators: %s: kind of business, for example "Services business". */
     558                        $items[] = sprintf( __( 'Done: we read your site and set the chat\'s greeting and suggested questions for a %s.', 'eaforyou-ai-sales-chat' ), strtolower( $label ) );
     559                } elseif ( 'failed' === $status ) {
     560                        $items[] = __( 'We could not read your site, so the chat uses the standard questions. You can change them with Customize the chat.', 'eaforyou-ai-sales-chat' );
     561                } elseif ( 'ready' !== $status ) {
     562                        $items[] = __( 'We are reading your site to set up the chat\'s questions and colours. Check back in a minute.', 'eaforyou-ai-sales-chat' );
     563                }
     564                if ( $pages > 0 && $trained >= $pages ) {
     565                        /* translators: %d: number of pages. */
     566                        $items[] = sprintf( _n( 'Done: the chat has learned %d page of your site.', 'Done: the chat has learned %d pages of your site.', $trained, 'eaforyou-ai-sales-chat' ), $trained );
     567                } elseif ( $pages > 0 ) {
     568                        /* translators: %d: number of pages found on the site. */
     569                        $items[] = sprintf( _n( 'Teach it your site: we found %d page. Training it uses a few credits.', 'Teach it your site: we found %d pages. Training them uses a few credits.', $pages, 'eaforyou-ai-sales-chat' ), $pages );
     570                } else {
     571                        $items[] = __( 'Teach it your site, so it can answer from your pages.', 'eaforyou-ai-sales-chat' );
     572                }
     573                $items[] = __( 'Add files with your prices, FAQs or policies.', 'eaforyou-ai-sales-chat' );
     574                $items[] = __( 'Test it: open your site and ask the chat a question.', 'eaforyou-ai-sales-chat' );
     575                ?>
     576                <div class="easyagent-card">
     577                        <h2><?php esc_html_e( 'Finish setting up', 'eaforyou-ai-sales-chat' ); ?></h2>
     578                        <ul class="easyagent-list">
     579                                <?php foreach ( $items as $item ) : ?>
     580                                        <li><?php echo esc_html( $item ); ?></li>
     581                                <?php endforeach; ?>
     582                        </ul>
     583                        <div class="easyagent-actions">
     584                                <?php $this->action_form( 'easyagent_setup', __( 'Finish setup in your dashboard', 'eaforyou-ai-sales-chat' ), 'button button-primary', true ); ?>
     585                                <a class="button" href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Open your site', 'eaforyou-ai-sales-chat' ); ?></a>
     586                        </div>
     587                </div>
     588                <?php
    509589        }
    510590
  • eaforyou-ai-sales-chat/trunk/readme.txt

    r3775250 r3777888  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 1.1.5
     7Stable tag: 1.1.6
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    147147== Changelog ==
    148148
     149= 1.1.6 =
     150* New: when you connect, EAForYou reads your site and sets the chat's greeting, suggested questions and colour for your kind of business. Anything you have already changed is kept.
     151* New: a *Finish setting up* box with the steps left: teach the chat your pages, add files with your prices or FAQs, and test it.
     152* Fixed: *Open full dashboard* and *Customize the chat* now open the EAForYou sign-in page when one-click sign-in is not available for your account, instead of staying on this page.
     153
    149154= 1.1.5 =
    150155* New: a *Customize the chat* button that opens this site's chat settings (colours, button, greeting) in your EAForYou dashboard.
    … …  
    176181== Upgrade Notice ==
    177182
     183= 1.1.6 =
     184Sets the chat up for your kind of business and adds a Finish setting up box. Your settings are kept.
     185
    178186= 1.1.5 =
    179187Adds a Customize the chat button. Nothing else changes.
Note: See TracChangeset for help on using the changeset viewer.