$product Product. * @return array */ public static function spec( array $product ): array { $spec = is_array( $product['welcome'] ?? null ) ? $product['welcome'] : array(); $name = (string) $product['name']; $intro = is_array( $spec['intro'] ?? null ) ? $spec['intro'] : array(); $caution = is_array( $spec['caution'] ?? null ) ? $spec['caution'] : array(); return array( 'hero' => '' !== (string) ( $spec['hero'] ?? '' ) ? (string) $spec['hero'] : __( 'Thank you!', 'ai-eshop-optimizer' ), /* translators: %s: the product's name. */ 'title' => '' !== (string) ( $spec['title'] ?? '' ) ? (string) $spec['title'] : sprintf( __( 'Thank you for installing %s', 'ai-eshop-optimizer' ), $name ), 'intro' => array() !== $intro ? $intro : (array) $product['intro'], 'punch' => '' !== (string) ( $spec['punch'] ?? '' ) ? (string) $spec['punch'] : (string) $product['strapline'], 'caution' => array( 'title' => (string) ( $caution['title'] ?? '' ), 'body' => (string) ( $caution['body'] ?? '' ), ), 'blocks' => is_array( $spec['blocks'] ?? null ) ? $spec['blocks'] : array(), ); } /** * Whether the product has a welcome: words beyond the title (an introduction, a punch line, a caution or a fold). * * @param array $product Product. */ public static function applies( array $product ): bool { $spec = self::spec( $product ); return array() !== $spec['intro'] || '' !== $spec['punch'] || '' !== $spec['caution']['body'] || array() !== $spec['blocks']; } /** * The brand bar's item: the button that reopens the welcome. */ public static function button(): string { $label = __( 'Read the welcome again', 'ai-eshop-optimizer' ); return '
  • '; } /** * Whether the welcome was offered to the user on this product already. * * @param int $user User id. * @param string $product Product slug. */ public static function offered( int $user, string $product ): bool { return is_array( Prefs::get( $user, Prefs::WELCOMED, $product ) ); } /** * Records that the welcome was offered now. * * @param int $user User id. * @param string $product Product slug. */ public static function offer( int $user, string $product ): bool { return Prefs::set( $user, Prefs::WELCOMED, array( 'at' => time() ), $product ); } /** * The dialog (escaped here): the eyebrow (name and version), the hero with the logo, the title, the * introduction, the punch line, the caution, the folds, how to get around, and the way on (the manual, the * Home page, or straight in). Wide when it carries a caution or folds, as Rooster One's welcome is. * * @param Registry $registry The registry. * @param array $product Product. * @param bool $autoopen Whether the script opens it on load (the first visit). */ public static function dialog( Registry $registry, array $product, bool $autoopen ): string { $spec = self::spec( $product ); $id = self::DIALOG_ID; $name = (string) $product['name']; $version = (string) $product['version']; $wide = array() !== $spec['blocks'] || '' !== $spec['caution']['body']; $tags = array( 'strong' => array(), 'em' => array(), 'a' => array( 'href' => array() ), ); $html = '' . '
    ' . '

    ' . esc_html( $name ) . ( '' !== $version ? ' v' . esc_html( $version ) . '' : '' ) . '

    ' . '
    ' . '
    ' . '
    ' . '

    ' . esc_html( $spec['hero'] ) . '

    ' . '

    ' . esc_html( $spec['title'] ) . '

    '; foreach ( $spec['intro'] as $paragraph ) { $html .= '

    ' . wp_kses( (string) $paragraph, $tags ) . '

    '; } if ( '' !== $spec['punch'] ) { $html .= '

    ' . esc_html( $spec['punch'] ) . '

    '; } if ( '' !== $spec['caution']['body'] ) { $html .= '
    ' . ( '' !== $spec['caution']['title'] ? '

    ' . esc_html( $spec['caution']['title'] ) . '

    ' : '' ) . '

    ' . wp_kses( $spec['caution']['body'], $tags ) . '

    '; } foreach ( $spec['blocks'] as $block ) { if ( ! is_array( $block ) || '' === (string) ( $block['title'] ?? '' ) ) { continue; } $html .= '
    ' . esc_html( (string) $block['title'] ) . '' . ( '' !== (string) ( $block['lede'] ?? '' ) ? '' . esc_html( (string) $block['lede'] ) . '' : '' ) . '
    '; foreach ( is_array( $block['body'] ?? null ) ? $block['body'] : array() as $paragraph ) { $html .= '

    ' . wp_kses( (string) $paragraph, $tags ) . '

    '; } $html .= '
    '; } /* translators: %s: the product's name. */ $html .= '

    ' . wp_kses( sprintf( __( 'Press Ctrl+K on any %s screen to jump straight to a page, tab, card or setting. The Home page lists every destination with what you can do there, and the brand bar reopens this welcome whenever you like.', 'ai-eshop-optimizer' ), esc_html( $name ) ), $tags ) . '

    ' . '
    '; return $html . '
    '; } }