! in_array( $item['action'], HeaderActions::PHONE_LEAVES, true ) ) ); } private static function phone_start(): array { return array_values( array_filter( HeaderActions::items(), static fn ( array $item ): bool => in_array( $item['action'], [ 'academy', 'account', 'wishlist', 'cart' ], true ) ) ); } private static function entries( $value ): array { if ( ! is_array( $value ) ) { return []; } if ( isset( $value['order'] ) ) { $list = []; foreach ( (array) $value['order'] as $key ) { $key = sanitize_key( (string) $key ); if ( '' !== $key && ! empty( $value['show'][ $key ] ) ) { $list[] = [ 'action' => $key, 'label' => sanitize_text_field( (string) ( $value['label'][ $key ] ?? '' ) ), 'text' => ! empty( $value['text'][ $key ] ) ]; } } return $list; } $plain = []; foreach ( $value as $entry ) { if ( is_array( $entry ) ) { $entry['label'] = is_scalar( $entry['label'] ?? null ) ? sanitize_text_field( (string) $entry['label'] ) : ''; } $plain[] = $entry; } return $plain; } private static function rows( array $items, array $leave ): array { $rows = []; foreach ( $items as $item ) { if ( ! in_array( $item['action'], $leave, true ) ) { $rows[ $item['action'] ] = [ 'label' => $item['label'], 'text' => $item['text'], 'shown' => true ]; } } foreach ( HeaderActions::known() as $action ) { if ( ! isset( $rows[ $action ] ) && ! in_array( $action, $leave, true ) && HeaderActions::available( $action ) ) { $rows[ $action ] = [ 'label' => '', 'text' => false, 'shown' => false ]; } } return $rows; } private static function editor( string $id, string $name, string $title, array $rows, bool $phone ): string { $names = HeaderActionsChecks::names(); $out = []; foreach ( $rows as $action => $row ) { $label = $names[ $action ] ?? $action; $plugin = isset( HeaderActions::registered()[ $action ] ); $control = ''; if ( ! $phone && ( in_array( $action, HeaderActions::TEXT, true ) || $plugin ) ) { $control .= ''; } if ( ! $phone && ( in_array( $action, HeaderActions::LABELLED, true ) || $plugin ) ) { $control .= Ui::input( $name . '[label][' . $action . ']', $row['label'], [ 'id' => $id . '-label-' . $action, 'short' => true, 'maxlength' => HeaderActions::LABEL_MAX, 'placeholder' => __( 'Custom text', 'ai-eshop-optimizer' ), 'aria-label' => sprintf( __( '%s: custom text (a pill for the search, a button for visitors for the account)', 'ai-eshop-optimizer' ), $label ), ] ); } $out[] = [ 'key' => $action, 'label' => $label, 'origin' => $action, 'show' => $row['shown'], 'show_name' => $name . '[show][' . $action . ']', 'control' => $control, 'state' => HeaderActions::available( $action ) ? [] : [ __( 'Not on this site', 'ai-eshop-optimizer' ), 'warning' ], ]; } $default = array_values( array_filter( HeaderActions::known(), static fn ( string $action ): bool => isset( $rows[ $action ] ) ) ); return Fields::ordered_list( $out, [ 'id' => $id . '-list', 'label' => $title, 'name' => $name . '[order]', 'default' => $default ] ); } public static function control( string $id, string $name, $value, array $field ): string { if ( ! class_exists( Fields::class ) || ! empty( $field['plain'] ) ) { return HeaderActionsChecks::control( $id, $name, $value, $field ); } return '
' . $mode . '
'; if ( ! $own ) { $short = [ 'search' => __( 'Search', 'ai-eshop-optimizer' ), 'language' => __( 'Language', 'ai-eshop-optimizer' ), 'scheme' => __( 'Theme', 'ai-eshop-optimizer' ), 'text-size' => __( 'Text size', 'ai-eshop-optimizer' ), 'academy' => __( 'Learning', 'ai-eshop-optimizer' ), 'account' => __( 'Account', 'ai-eshop-optimizer' ), 'wishlist' => __( 'Wishlist', 'ai-eshop-optimizer' ), 'cart' => __( 'Cart', 'ai-eshop-optimizer' ) ]; $word = static fn ( string $action ): string => $short[ $action ] ?? ( HeaderActions::registered()[ $action ]['label'] ?? $action ); $beside = array_map( $word, array_values( array_filter( array_column( self::phone_start(), 'action' ), [ HeaderActions::class, 'available' ] ) ) ); $menu = array_map( $word, array_values( array_intersect( HeaderActions::names(), [ 'search', 'language', 'scheme', 'text-size' ] ) ) ); $summary = sprintf( __( 'Beside the menu button: %1$s. In the menu: %2$s. Choose "A list of their own" and save to set the phones\' actions.', 'ai-eshop-optimizer' ), [] === $beside ? __( 'nothing', 'ai-eshop-optimizer' ) : implode( ', ', $beside ), [] === $menu ? __( 'nothing', 'ai-eshop-optimizer' ) : implode( ', ', $menu ) ); return '' . esc_html( $summary ) . '