0; $inbox = $connected && (int) $settings['widget_inbox_id'] > 0 && '' !== $settings['website_token']; $widget = $inbox && ! empty( $settings['widget_enabled'] ); $identity = ! empty( $settings['identity_enabled'] ) && '' !== $settings['hmac_token']; $webhook = $connected && (int) $settings['webhook_id'] > 0 && '' !== $settings['webhook_secret']; $leads = $connected && (int) $settings['leads_inbox_id'] > 0; $connect_first = __( 'Connect ConvoHub first.', 'convohub' ); if ( $identity ) { $identity_state = 'done'; $identity_detail = __( 'Logged-in customers are signed, so ConvoHub knows who they are.', 'convohub' ); } elseif ( ! empty( $settings['identity_enabled'] ) ) { $identity_state = 'todo'; $identity_detail = __( 'Switched on, but the inbox identity secret is missing. Connect with a key made by a ConvoHub administrator, then choose the inbox again.', 'convohub' ); } elseif ( $widget ) { $identity_state = 'optional'; $identity_detail = __( 'Off. Fine if you do not need to recognize logged-in customers.', 'convohub' ); } else { $identity_state = 'todo'; $identity_detail = __( 'Decide whether to recognize logged-in customers once the widget is on.', 'convohub' ); } return array( array( 'id' => 'connect', 'label' => __( 'Connect ConvoHub', 'convohub' ), 'state' => $connected ? 'done' : 'todo', 'detail' => $connected ? __( 'This site is connected to your ConvoHub account.', 'convohub' ) : __( 'Paste a connection key from ConvoHub.', 'convohub' ), 'tab' => 'connection', 'anchor' => $connected ? 'cvh-connection' : 'cvh-connect', ), array( 'id' => 'inbox', 'label' => __( 'Choose the widget inbox', 'convohub' ), 'state' => $inbox ? 'done' : 'todo', 'detail' => $inbox ? __( 'A website inbox is chosen.', 'convohub' ) : ( $connected ? __( 'Pick a website inbox or create one.', 'convohub' ) : $connect_first ), 'tab' => 'widget', 'anchor' => 'cvh-inbox', ), array( 'id' => 'widget', 'label' => __( 'Turn the chat widget on', 'convohub' ), 'state' => $widget ? 'done' : 'todo', 'detail' => $widget ? __( 'The chat widget shows on your site.', 'convohub' ) : ( $inbox ? __( 'Switch on "Show the chat widget on this site".', 'convohub' ) : __( 'Choose an inbox first.', 'convohub' ) ), 'tab' => 'widget', 'anchor' => 'cvh-display', ), array( 'id' => 'identity', 'label' => __( 'Identity validation (optional)', 'convohub' ), 'state' => $identity_state, 'detail' => $identity_detail, 'tab' => 'widget', 'anchor' => 'cvh-display', ), array( 'id' => 'webhook', 'label' => __( 'Register the webhook', 'convohub' ), 'state' => $webhook ? 'done' : 'todo', 'detail' => $webhook ? __( 'ConvoHub sends events to this site.', 'convohub' ) : ( $connected ? __( 'Register it so this site hears about customer messages.', 'convohub' ) : $connect_first ), 'tab' => 'connection', 'anchor' => 'cvh-webhook', ), array( 'id' => 'leads', 'label' => __( 'Collect leads with the form (optional)', 'convohub' ), 'state' => $leads ? 'done' : 'optional', 'detail' => $leads ? __( 'Leads go to an API inbox.', 'convohub' ) : __( 'Choose an API inbox, then add the form to a page.', 'convohub' ), 'tab' => 'leads', 'anchor' => 'cvh-leads-inbox', ), ); } /** * How many of the five main steps are complete. A step that is optional counts as complete. * * @param array[] $steps Result of steps(). * @return array{done:int,total:int} */ public static function summary( array $steps ) { $main = array_slice( $steps, 0, 5 ); $done = 0; foreach ( $main as $step ) { if ( 'todo' !== $step['state'] ) { ++$done; } } return array( 'done' => $done, 'total' => count( $main ), ); } }