[ label, help, done (bool), url, cta ] */ public static function steps() { global $wpdb; $a = Nodebook_Activities::table(); $contacts = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', Nodebook_Contacts::table() ) ); // Existence checks (LIMIT 1), never full counts: this runs on the Contacts screen of large sites. $captured = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT 1 FROM %i WHERE type IN ('form','order','booking','appointment','signup') LIMIT 1", $a ) ); $imported = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT 1 FROM %i WHERE type = 'import' LIMIT 1", $a ) ) || (int) get_option( 'nodebook_woo_backfilled', 0 ); $tracked = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT 1 FROM %i WHERE type IN ('visit','pageview') AND contact_id > 0 LIMIT 1", $a ) ); $niches = Nodebook_Niche::all(); $niche = $niches[ Nodebook_Niche::current() ]['label']; $sources = array(); foreach ( array_merge( Nodebook_Forms::integrations(), Nodebook_Bookings::integrations() ) as $key => $int ) { if ( 'nodebook' !== $key && call_user_func( $int[1] ) ) { $sources[] = $int[0]; } } if ( Nodebook_Woocommerce::active() ) { $sources[] = 'WooCommerce'; } $steps = array( 'team' => array( 'label' => __( 'Who uses Nodebook?', 'nodebook' ), 'help' => __( 'Just you, and Nodebook stays simple: no owners, assignees or “Mine / Everyone” switches. A team, and everyone gets their own list. You can change this any time under Settings → Team.', 'nodebook' ), 'done' => '' !== (string) Nodebook_Settings::get( 'team_size' ) || count( Nodebook_Team::users() ) > 1, 'url' => Nodebook_Admin::url( 'nodebook-settings' ) . '#nb-team', 'cta' => __( 'Settings', 'nodebook' ), 'setting' => 'team_size', 'choices' => array( 'solo' => __( 'Just me', 'nodebook' ), 'team' => __( 'Me and my team', 'nodebook' ), ), ), 'business' => array( 'label' => __( 'Set Nodebook up for your business', 'nodebook' ), /* translators: %s: business type */ 'help' => sprintf( __( 'Nodebook thinks you are: %s. Five quick questions, and you only see what you need: a shop gets customers and orders without a sales pipeline, a retreat organiser gets rosters and deposits.', 'nodebook' ), $niche ), 'done' => Nodebook_Presets::done() || '' !== (string) Nodebook_Settings::get( 'niche' ), 'url' => Nodebook_Admin::url( 'nodebook-welcome' ), 'cta' => __( 'Start the setup', 'nodebook' ), ), 'shop' => array( 'label' => __( 'When should shop customers become contacts?', 'nodebook' ), 'help' => __( 'Every buyer at checkout, only once an order is paid, or not automatically (you can still import past orders whenever you like). Change it any time under Settings → Capture.', 'nodebook' ), 'done' => ! Nodebook_Woocommerce::active() || '' !== (string) Nodebook_Settings::get( 'woo_capture' ), 'url' => Nodebook_Admin::url( 'nodebook-settings' ) . '#nb-capture', 'cta' => __( 'Settings', 'nodebook' ), 'setting' => 'woo_capture', 'choices' => array( 'orders' => __( 'Every buyer', 'nodebook' ), 'paid' => __( 'Only paid orders', 'nodebook' ), 'off' => __( 'Not automatically', 'nodebook' ), ), ), 'capture' => array( 'label' => __( 'Capture your first contact', 'nodebook' ), 'help' => $sources /* translators: %s: list of detected plugins */ ? sprintf( __( 'Detected: %s. Submit any form on your site (with your own email) and you will appear here.', 'nodebook' ), implode( ', ', $sources ) ) : __( 'No form or booking plugin detected. Add [nodebook_form] to your contact page, or connect another system with the inbound webhook.', 'nodebook' ), 'done' => $captured > 0, 'url' => home_url( '/' ), 'cta' => __( 'Open your site', 'nodebook' ), ), 'tracking' => array( 'label' => __( 'See a return visit', 'nodebook' ), 'help' => __( 'After submitting a form, browse a few pages in the same browser. They appear on your timeline within seconds. Nothing showing? Check the Status card under Settings.', 'nodebook' ), 'done' => $tracked > 0, 'url' => Nodebook_Admin::url( 'nodebook-settings' ) . '#nb-status', 'cta' => __( 'Check status', 'nodebook' ), ), 'import' => array( 'label' => __( 'Bring in the contacts you already have', 'nodebook' ), 'help' => Nodebook_Woocommerce::active() ? __( 'Import past WooCommerce orders in one click, or upload a CSV from your old CRM or spreadsheet.', 'nodebook' ) : __( 'Upload a CSV from your old CRM, spreadsheet or email tool. Columns are matched automatically.', 'nodebook' ), 'done' => (bool) $imported || $contacts >= 25, 'url' => Nodebook_Admin::url( 'nodebook-tools' ), 'cta' => __( 'Import', 'nodebook' ), ), ); return apply_filters( 'nodebook_setup_steps', $steps ); } /** Answers to setup questions: which setting, and the values it takes. */ private static function questions() { return array( 'team_size' => array( 'solo', 'team' ), 'woo_capture' => array( 'orders', 'paid', 'existing', 'off' ), ); } /** Answer to a setup question (team size, shop customers). */ public static function choice_post() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to do that.', 'nodebook' ), 403 ); } check_admin_referer( 'nodebook_setup_choice' ); $key = isset( $_POST['setting'] ) ? sanitize_key( wp_unslash( $_POST['setting'] ) ) : ''; $value = isset( $_POST['value'] ) ? sanitize_key( wp_unslash( $_POST['value'] ) ) : ''; $q = self::questions(); $note = 'saved'; if ( isset( $q[ $key ] ) && in_array( $value, $q[ $key ], true ) ) { $all = Nodebook_Settings::all(); $all[ $key ] = $value; update_option( Nodebook_Settings::OPTION, $all ); if ( 'team_size' === $key && 'team' === $value && count( Nodebook_Team::users() ) < 2 ) { $note = 'teamnext'; } } Nodebook_Admin::redirect( Nodebook_Admin::url( 'nodebook-today' ), $note ); } /** Buttons for a step that is a question: one small form per answer. */ public static function choices( array $step, $primary = true ) { $out = ''; foreach ( (array) ( $step['choices'] ?? array() ) as $value => $label ) { $out .= '
' . wp_nonce_field( 'nodebook_setup_choice', '_wpnonce', true, false ) . '
'; $primary = false; } return $out; } public static function visible() { if ( get_user_meta( get_current_user_id(), self::HIDE, true ) ) { return false; } foreach ( self::steps() as $s ) { if ( ! $s['done'] ) { return true; } } return false; } /** * Server-side health checks. The browser-side check (can visitors reach the beacon endpoint?) * runs in admin.js against the same URL the tracker uses. * * @return array[] key => [ label, state ok|warn|bad, message ] */ public static function checks() { global $wpdb; $a = Nodebook_Activities::table(); $checks = array(); $mode = Nodebook_Settings::get( 'tracking_mode' ); if ( 'off' === $mode ) { $checks['tracking'] = array( __( 'Visit tracking', 'nodebook' ), 'warn', __( 'Turned off: you will see form submissions and orders, but not return visits.', 'nodebook' ) ); } else { $recent = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM ( SELECT 1 FROM %i WHERE type = 'pageview' AND created_at >= %s LIMIT 100000 ) t", $a, gmdate( 'Y-m-d H:i:s', time() - 14 * DAY_IN_SECONDS ) ) ); $contacts = (int) $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i', Nodebook_Contacts::table() ) ); if ( $recent ) { /* translators: %s: number of page views */ $checks['tracking'] = array( __( 'Visit tracking', 'nodebook' ), 'ok', sprintf( __( '%s page views of known contacts in the last 14 days.', 'nodebook' ), number_format_i18n( $recent ) ) ); } elseif ( $contacts >= 10 ) { $checks['tracking'] = array( __( 'Visit tracking', 'nodebook' ), 'warn', __( 'No page views of known contacts in 14 days. Usually a caching or security plugin blocks the tracking request, or a minify plugin broke the script. Check the result below.', 'nodebook' ) ); } else { $checks['tracking'] = array( __( 'Visit tracking', 'nodebook' ), 'ok', __( 'Ready. Page views appear once known contacts come back.', 'nodebook' ) ); } } $cmp = Nodebook_Consent::detected(); if ( Nodebook_Settings::get( 'require_consent' ) ) { $checks['consent'] = $cmp /* translators: %s: consent plugins */ ? array( __( 'Consent', 'nodebook' ), 'ok', sprintf( __( 'Works with %s: tracking starts as soon as a visitor accepts statistics/analytics cookies.', 'nodebook' ), implode( ', ', $cmp ) ) ) : array( __( 'Consent', 'nodebook' ), 'warn', __( 'Consent is required, but no consent banner Nodebook recognises is active. Nothing is tracked unless your banner calls window.nodebookConsent(true) after visitors accept statistics cookies. Supported: Complianz, CookieYes, Cookiebot, Borlabs, Real Cookie Banner, GDPR Cookie Compliance, Google Consent Mode and any plugin using the WP Consent API.', 'nodebook' ) ); } elseif ( array_diff_key( $cmp, array( 'wpconsent' => 1 ) ) ) { /* translators: %s: consent plugins */ $checks['consent'] = array( __( 'Consent', 'nodebook' ), 'warn', sprintf( __( '%s is active, but Nodebook does not wait for consent. If your visitors are in the EU or UK, turn on “Only track after the visitor accepts statistics cookies” under Visits.', 'nodebook' ), implode( ', ', array_diff_key( $cmp, array( 'wpconsent' => 1 ) ) ) ) ); } if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) { $checks['cron'] = array( __( 'Scheduled tasks', 'nodebook' ), 'warn', __( 'WP-Cron is disabled. Make sure a server cron calls wp-cron.php, or the daily digest and clean-up will not run.', 'nodebook' ) ); } else { $next = wp_next_scheduled( Nodebook_Cron::HOOK ); $late = $next && $next < time() - 2 * HOUR_IN_SECONDS; $checks['cron'] = $late ? array( __( 'Scheduled tasks', 'nodebook' ), 'warn', __( 'The daily task is overdue. WP-Cron only runs when someone visits the site; on quiet sites set up a real server cron.', 'nodebook' ) ) : array( __( 'Scheduled tasks', 'nodebook' ), 'ok', __( 'Daily digest and clean-up are scheduled.', 'nodebook' ) ); } $last = get_option( 'nodebook_mail_test' ); if ( is_array( $last ) ) { $checks['mail'] = $last['ok'] /* translators: %s: email address */ ? array( __( 'Email alerts', 'nodebook' ), 'ok', sprintf( __( 'Test sent to %s. Not in your inbox? Check spam, or use an SMTP plugin.', 'nodebook' ), $last['to'] ) ) : array( __( 'Email alerts', 'nodebook' ), 'bad', __( 'WordPress could not send the test email. Install an SMTP plugin so alerts reach you.', 'nodebook' ) ); } else { $checks['mail'] = array( __( 'Email alerts', 'nodebook' ), 'warn', __( 'Not tested yet. Many hosts silently drop WordPress email: send a test.', 'nodebook' ) ); } return apply_filters( 'nodebook_health_checks', $checks ); } /** Send a sample alert to the alert recipients. */ public static function send_test() { $to = Nodebook_Alerts::recipients(); $ok = (bool) wp_mail( $to, /* translators: %s: site name */ sprintf( __( '[%s] Nodebook test alert', 'nodebook' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ), __( "This is a test. When a known contact comes back to a high-intent page, you will get an email like this with who it is, what they looked at and how to reach them.\n\nNodebook", 'nodebook' ) ); update_option( 'nodebook_mail_test', array( 'ok' => $ok, 'to' => implode( ', ', (array) $to ), 'time' => time(), ), false ); return $ok; } }