__( 'Connection', 'agentixhub-chat' ), 'launcher' => __( 'Launcher', 'agentixhub-chat' ), 'appearance' => __( 'Chat Window', 'agentixhub-chat' ), 'behaviour' => __( 'Behaviour', 'agentixhub-chat' ), 'visitor' => __( 'Consent', 'agentixhub-chat' ), 'display' => __( 'Display Rules', 'agentixhub-chat' ), 'advanced' => __( 'Advanced', 'agentixhub-chat' ), ); } /** * key => [ tab, type, default, label, description, choices, show_if, range ] */ public static function schema(): array { return array( // Connection. 'enabled' => array( 'connection', 'toggle', 1, __( 'Enable chat', 'agentixhub-chat' ), __( 'Master switch for the launcher, block, widget and shortcode.', 'agentixhub-chat' ) ), 'workflow_url' => array( 'connection', 'workflow_url', '', __( 'Workflow URL', 'agentixhub-chat' ), __( 'Required. The workflow access URL from the AgentixHub control panel (…/run/…). It is loaded inside the chat window.', 'agentixhub-chat' ) ), 'mode' => array( 'connection', 'select', 'test', __( 'Mode', 'agentixhub-chat' ), __( 'Test mode lets you try the chat on your live site before visitors see it.', 'agentixhub-chat' ), array( 'test' => __( 'Test — only administrators see the chat', 'agentixhub-chat' ), 'live' => __( 'Live — visible to visitors', 'agentixhub-chat' ) ) ), 'iframe_preload' => array( 'connection', 'select', 'open', __( 'Load the workflow', 'agentixhub-chat' ), __( 'Loading on first open keeps your pages fast.', 'agentixhub-chat' ), array( 'open' => __( 'When the chat is first opened', 'agentixhub-chat' ), 'idle' => __( 'After the page has loaded', 'agentixhub-chat' ) ) ), 'iframe_permissions' => array( 'connection', 'checklist', array( 'microphone', 'autoplay', 'clipboard-write', 'fullscreen' ), __( 'Allow the workflow to use', 'agentixhub-chat' ), __( 'Voice and video agents need microphone / camera.', 'agentixhub-chat' ), array( 'microphone' => __( 'Microphone', 'agentixhub-chat' ), 'camera' => __( 'Camera', 'agentixhub-chat' ), 'autoplay' => __( 'Audio autoplay', 'agentixhub-chat' ), 'clipboard-write' => __( 'Clipboard', 'agentixhub-chat' ), 'fullscreen' => __( 'Full screen', 'agentixhub-chat' ), 'display-capture' => __( 'Screen sharing', 'agentixhub-chat' ), 'geolocation' => __( 'Location', 'agentixhub-chat' ) ) ), 'iframe_params' => array( 'connection', 'lines', '', __( 'Extra URL parameters', 'agentixhub-chat' ), __( 'key=value per line, appended to the workflow URL. theme and lang are sent automatically; set them here to override. Placeholders: {lang}, {page_url}, {page_title}, {user_name}, {user_email}.', 'agentixhub-chat' ) ), 'iframe_new_tab' => array( 'connection', 'toggle', 0, __( '“Open in new window” button', 'agentixhub-chat' ), __( 'Shown in the header — a fallback for browsers that block embedded content.', 'agentixhub-chat' ) ), // Launcher (bubble). 'launcher_style' => array( 'launcher', 'select', 'icon', __( 'Style', 'agentixhub-chat' ), '', array( 'icon' => __( 'Icon only', 'agentixhub-chat' ), 'pill' => __( 'Icon + label', 'agentixhub-chat' ), 'tab' => __( 'Side tab', 'agentixhub-chat' ) ) ), 'launcher_label' => array( 'launcher', 'text', __( 'Chat with us', 'agentixhub-chat' ), __( 'Label', 'agentixhub-chat' ), '', null, array( 'launcher_style' => array( 'pill', 'tab' ) ) ), 'launcher_shape' => array( 'launcher', 'select', 'circle', __( 'Shape', 'agentixhub-chat' ), '', array( 'circle' => __( 'Round', 'agentixhub-chat' ), 'rounded' => __( 'Rounded square', 'agentixhub-chat' ), 'square' => __( 'Square', 'agentixhub-chat' ) ), array( 'launcher_style' => array( 'icon', 'pill' ) ) ), 'launcher_size' => array( 'launcher', 'number', 60, __( 'Size (px)', 'agentixhub-chat' ), '', null, null, array( 40, 96 ) ), 'launcher_icon' => array( 'launcher', 'select', 'chat', __( 'Icon', 'agentixhub-chat' ), '', array( 'chat' => __( 'Speech bubble', 'agentixhub-chat' ), 'chat-dots' => __( 'Speech bubble with dots', 'agentixhub-chat' ), 'sparkle' => __( 'Sparkle (AI)', 'agentixhub-chat' ), 'headset' => __( 'Headset', 'agentixhub-chat' ), 'help' => __( 'Question mark', 'agentixhub-chat' ), 'mic' => __( 'Microphone', 'agentixhub-chat' ), 'avatar' => __( 'Agent avatar', 'agentixhub-chat' ), 'custom' => __( 'Custom image', 'agentixhub-chat' ), 'none' => __( 'No icon', 'agentixhub-chat' ) ) ), 'launcher_icon_url' => array( 'launcher', 'media', '', __( 'Custom icon image', 'agentixhub-chat' ), __( 'Square PNG or SVG, at least 96×96.', 'agentixhub-chat' ), null, array( 'launcher_icon' => 'custom' ) ), 'launcher_icon_scale' => array( 'launcher', 'number', 45, __( 'Icon size (% of launcher)', 'agentixhub-chat' ), '', null, null, array( 20, 100 ) ), 'launcher_bg' => array( 'launcher', 'color', '', __( 'Background', 'agentixhub-chat' ), __( 'Empty = brand colour.', 'agentixhub-chat' ) ), 'launcher_gradient' => array( 'launcher', 'toggle', 0, __( 'Gradient background', 'agentixhub-chat' ) ), 'launcher_bg2' => array( 'launcher', 'color', '#7c3aed', __( 'Gradient end colour', 'agentixhub-chat' ), '', null, array( 'launcher_gradient' => 1 ) ), 'launcher_fg' => array( 'launcher', 'color', '', __( 'Icon & text colour', 'agentixhub-chat' ), __( 'Empty = automatic contrast.', 'agentixhub-chat' ) ), 'launcher_border_width' => array( 'launcher', 'number', 0, __( 'Border width (px)', 'agentixhub-chat' ), '', null, null, array( 0, 8 ) ), 'launcher_border_color' => array( 'launcher', 'color', '#ffffff', __( 'Border colour', 'agentixhub-chat' ) ), 'launcher_shadow' => array( 'launcher', 'select', 'soft', __( 'Shadow', 'agentixhub-chat' ), '', array( 'none' => __( 'None', 'agentixhub-chat' ), 'soft' => __( 'Soft', 'agentixhub-chat' ), 'strong' => __( 'Strong', 'agentixhub-chat' ), 'glow' => __( 'Brand glow', 'agentixhub-chat' ) ) ), 'launcher_hover' => array( 'launcher', 'select', 'lift', __( 'Hover effect', 'agentixhub-chat' ), '', array( 'none' => __( 'None', 'agentixhub-chat' ), 'lift' => __( 'Lift', 'agentixhub-chat' ), 'grow' => __( 'Grow', 'agentixhub-chat' ), 'brighten' => __( 'Brighten', 'agentixhub-chat' ) ) ), 'launcher_attention' => array( 'launcher', 'select', 'none', __( 'Attention animation', 'agentixhub-chat' ), __( 'Plays until the visitor opens the chat. Respects “reduce motion”.', 'agentixhub-chat' ), array( 'none' => __( 'None', 'agentixhub-chat' ), 'pulse' => __( 'Pulse ring', 'agentixhub-chat' ), 'bounce' => __( 'Bounce', 'agentixhub-chat' ), 'wiggle' => __( 'Wiggle', 'agentixhub-chat' ), 'breathe' => __( 'Breathe', 'agentixhub-chat' ) ) ), 'launcher_attention_every' => array( 'launcher', 'number', 8, __( 'Repeat every (seconds)', 'agentixhub-chat' ), '', null, array( 'launcher_attention' => array( 'pulse', 'bounce', 'wiggle', 'breathe' ) ), array( 2, 120 ) ), 'launcher_dot' => array( 'launcher', 'toggle', 0, __( 'Notification dot', 'agentixhub-chat' ), __( 'Small dot on the launcher until the first open.', 'agentixhub-chat' ) ), 'launcher_tooltip' => array( 'launcher', 'text', '', __( 'Tooltip', 'agentixhub-chat' ), __( 'Shown on hover. Empty = none.', 'agentixhub-chat' ) ), 'launcher_when_open' => array( 'launcher', 'select', 'close', __( 'While the chat is open', 'agentixhub-chat' ), '', array( 'close' => __( 'Turn the launcher into a close button', 'agentixhub-chat' ), 'hide' => __( 'Hide the launcher', 'agentixhub-chat' ) ), array( 'launcher_style' => array( 'icon', 'pill' ) ) ), 'position' => array( 'launcher', 'select', 'right', __( 'Position', 'agentixhub-chat' ), '', array( 'right' => __( 'Bottom right', 'agentixhub-chat' ), 'left' => __( 'Bottom left', 'agentixhub-chat' ) ) ), 'offset_x' => array( 'launcher', 'number', 20, __( 'Horizontal offset (px)', 'agentixhub-chat' ), '', null, null, array( 0, 400 ) ), 'offset_y' => array( 'launcher', 'number', 20, __( 'Vertical offset (px)', 'agentixhub-chat' ), __( 'For the side tab: distance from the bottom of the screen.', 'agentixhub-chat' ), null, null, array( 0, 800 ) ), 'offset_mobile_y' => array( 'launcher', 'number', 16, __( 'Vertical offset on phones (px)', 'agentixhub-chat' ), __( 'Raise it above cookie banners or bottom bars.', 'agentixhub-chat' ), null, null, array( 0, 400 ) ), 'z_index' => array( 'launcher', 'number', 999999, __( 'Stacking order (z-index)', 'agentixhub-chat' ), '', null, null, array( 1, 2147483647 ) ), // Chat window. 'theme' => array( 'appearance', 'select', 'auto', __( 'Dark mode support', 'agentixhub-chat' ), __( 'Applies to the chat window and the workflow inside it.', 'agentixhub-chat' ), array( 'auto' => __( 'Automatic — follow the visitor’s device', 'agentixhub-chat' ), 'light' => __( 'Off — always light', 'agentixhub-chat' ), 'dark' => __( 'Always dark', 'agentixhub-chat' ) ) ), 'primary_color' => array( 'appearance', 'color', '#157bcc', __( 'Brand colour', 'agentixhub-chat' ), __( 'Text on it switches between light and dark automatically for contrast.', 'agentixhub-chat' ) ), 'font' => array( 'appearance', 'select', 'inherit', __( 'Font', 'agentixhub-chat' ), '', array( 'inherit' => __( 'Inherit from theme', 'agentixhub-chat' ), 'system' => __( 'System UI', 'agentixhub-chat' ) ) ), 'radius' => array( 'appearance', 'number', 20, __( 'Corner radius (px)', 'agentixhub-chat' ), '', null, null, array( 0, 32 ) ), 'panel_width' => array( 'appearance', 'number', 400, __( 'Width (px)', 'agentixhub-chat' ), '', null, null, array( 320, 720 ) ), 'panel_size' => array( 'appearance', 'select', 'fit', __( 'Height', 'agentixhub-chat' ), __( 'Fit to screen gives the workflow all the room available, so it rarely needs to scroll.', 'agentixhub-chat' ), array( 'fit' => __( 'Fit to screen (recommended)', 'agentixhub-chat' ), 'fixed' => __( 'Fixed', 'agentixhub-chat' ) ) ), 'panel_height' => array( 'appearance', 'number', 720, __( 'Fixed height (px)', 'agentixhub-chat' ), '', null, array( 'panel_size' => 'fixed' ), array( 380, 1000 ) ), 'open_animation' => array( 'appearance', 'select', 'pop', __( 'Open animation', 'agentixhub-chat' ), '', array( 'pop' => __( 'Pop', 'agentixhub-chat' ), 'slide' => __( 'Slide up', 'agentixhub-chat' ), 'fade' => __( 'Fade', 'agentixhub-chat' ), 'none' => __( 'None', 'agentixhub-chat' ) ) ), 'backdrop' => array( 'appearance', 'toggle', 0, __( 'Dim the page behind the chat', 'agentixhub-chat' ) ), 'show_header' => array( 'appearance', 'toggle', 1, __( 'Show header', 'agentixhub-chat' ), __( 'Turn off if the workflow already shows its own header; a close button sits just above the window.', 'agentixhub-chat' ) ), 'agent_avatar' => array( 'appearance', 'media', '', __( 'Avatar', 'agentixhub-chat' ), __( 'Defaults to the Site Icon when empty.', 'agentixhub-chat' ), null, array( 'show_header' => 1 ) ), 'header_title' => array( 'appearance', 'text', '', __( 'Header title', 'agentixhub-chat' ), __( 'Defaults to the site title.', 'agentixhub-chat' ), null, array( 'show_header' => 1 ) ), 'header_subtitle' => array( 'appearance', 'text', __( 'We typically reply instantly', 'agentixhub-chat' ), __( 'Header subtitle', 'agentixhub-chat' ), '', null, array( 'show_header' => 1 ) ), 'show_status' => array( 'appearance', 'toggle', 1, __( 'Online status dot', 'agentixhub-chat' ), '', null, array( 'show_header' => 1 ) ), 'loading_text' => array( 'appearance', 'text', __( 'Loading your assistant…', 'agentixhub-chat' ), __( 'Loading message', 'agentixhub-chat' ), '' ), 'mobile_fullscreen' => array( 'appearance', 'toggle', 1, __( 'Full screen on phones', 'agentixhub-chat' ) ), 'hide_overlays' => array( 'appearance', 'toggle', 0, __( 'On phones, hide other chat buttons and cookie bars while the chat is open', 'agentixhub-chat' ) ), 'show_branding' => array( 'appearance', 'toggle', 0, __( 'Show “Powered by AgentixHub”', 'agentixhub-chat' ), __( 'Adds a small link to agentixhub.ai in the chat header. Off unless you turn it on.', 'agentixhub-chat' ) ), // Behaviour. 'auto_open' => array( 'behaviour', 'select', 'never', __( 'Open automatically', 'agentixhub-chat' ), '', array( 'never' => __( 'Never', 'agentixhub-chat' ), 'delay' => __( 'After a delay', 'agentixhub-chat' ), 'scroll' => __( 'After scrolling', 'agentixhub-chat' ) ) ), 'auto_open_delay' => array( 'behaviour', 'number', 15, __( 'Delay (seconds)', 'agentixhub-chat' ), '', null, array( 'auto_open' => 'delay' ), array( 1, 600 ) ), 'auto_open_scroll' => array( 'behaviour', 'number', 50, __( 'Scroll depth (%)', 'agentixhub-chat' ), '', null, array( 'auto_open' => 'scroll' ), array( 5, 100 ) ), 'auto_open_once' => array( 'behaviour', 'toggle', 1, __( 'Auto-open once per visitor session', 'agentixhub-chat' ) ), 'teaser_enabled' => array( 'behaviour', 'toggle', 0, __( 'Proactive teaser bubble', 'agentixhub-chat' ), __( 'Shows a short message next to the launcher.', 'agentixhub-chat' ) ), 'teaser_text' => array( 'behaviour', 'text', __( 'Questions? I can help 👋', 'agentixhub-chat' ), __( 'Teaser text', 'agentixhub-chat' ), '', null, array( 'teaser_enabled' => 1 ) ), 'teaser_delay' => array( 'behaviour', 'number', 5, __( 'Teaser delay (seconds)', 'agentixhub-chat' ), '', null, array( 'teaser_enabled' => 1 ), array( 0, 600 ) ), 'close_on_esc' => array( 'behaviour', 'toggle', 1, __( 'Close with the Esc key', 'agentixhub-chat' ) ), 'hours_enabled' => array( 'behaviour', 'toggle', 0, __( 'Business hours', 'agentixhub-chat' ), __( 'Uses the site timezone from Settings → General.', 'agentixhub-chat' ) ), 'hours' => array( 'behaviour', 'hours', self::default_hours(), __( 'Weekly schedule', 'agentixhub-chat' ), '', null, array( 'hours_enabled' => 1 ) ), 'offline_behaviour' => array( 'behaviour', 'select', 'message', __( 'Outside business hours', 'agentixhub-chat' ), '', array( 'message' => __( 'Show offline message', 'agentixhub-chat' ), 'hide' => __( 'Hide the launcher', 'agentixhub-chat' ) ), array( 'hours_enabled' => 1 ) ), 'offline_message' => array( 'behaviour', 'textarea', __( "We're offline right now. We'll be back during business hours.", 'agentixhub-chat' ), __( 'Offline message', 'agentixhub-chat' ), '', null, array( 'hours_enabled' => 1 ) ), // Consent. 'consent_required' => array( 'visitor', 'toggle', 0, __( 'Require consent before starting', 'agentixhub-chat' ), __( 'The workflow is not loaded until the visitor agrees.', 'agentixhub-chat' ) ), 'consent_text' => array( 'visitor', 'textarea', __( 'I agree that my messages are processed by an AI assistant as described in the {privacy_policy}.', 'agentixhub-chat' ), __( 'Consent text', 'agentixhub-chat' ), __( '{privacy_policy} links to the page set in Settings → Privacy.', 'agentixhub-chat' ), null, array( 'consent_required' => 1 ) ), 'consent_button' => array( 'visitor', 'text', __( 'Start', 'agentixhub-chat' ), __( 'Button label', 'agentixhub-chat' ), '', null, array( 'consent_required' => 1 ) ), // Display rules. 'display_scope' => array( 'display', 'select', 'all', __( 'Show the floating launcher', 'agentixhub-chat' ), __( 'Blocks, widgets and shortcodes always render where placed.', 'agentixhub-chat' ), array( 'all' => __( 'On every page', 'agentixhub-chat' ), 'include' => __( 'Only where rules below match', 'agentixhub-chat' ), 'exclude' => __( 'Everywhere except where rules below match', 'agentixhub-chat' ), 'none' => __( 'Nowhere (embed only)', 'agentixhub-chat' ) ) ), // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- a choice key, not a query argument. 'display_special' => array( 'display', 'checklist', array(), __( 'Page types', 'agentixhub-chat' ), '', array( __CLASS__, 'special_pages' ), array( 'display_scope' => array( 'include', 'exclude' ) ) ), 'display_post_types' => array( 'display', 'checklist', array(), __( 'Post types', 'agentixhub-chat' ), '', array( __CLASS__, 'post_types' ), array( 'display_scope' => array( 'include', 'exclude' ) ) ), 'display_ids' => array( 'display', 'text', '', __( 'Specific posts / pages', 'agentixhub-chat' ), __( 'Comma-separated IDs.', 'agentixhub-chat' ), null, array( 'display_scope' => array( 'include', 'exclude' ) ) ), 'display_urls' => array( 'display', 'lines', '', __( 'URL patterns', 'agentixhub-chat' ), __( 'One per line, * as wildcard. e.g. /shop/* or */pricing', 'agentixhub-chat' ), null, array( 'display_scope' => array( 'include', 'exclude' ) ) ), 'display_audience' => array( 'display', 'select', 'everyone', __( 'Audience', 'agentixhub-chat' ), '', array( 'everyone' => __( 'Everyone', 'agentixhub-chat' ), 'guests' => __( 'Guests only', 'agentixhub-chat' ), 'logged_in' => __( 'Logged-in users only', 'agentixhub-chat' ) ) ), 'display_roles' => array( 'display', 'checklist', array(), __( 'Limit to roles', 'agentixhub-chat' ), __( 'Leave empty for all roles.', 'agentixhub-chat' ), array( __CLASS__, 'roles' ), array( 'display_audience' => 'logged_in' ) ), 'display_devices' => array( 'display', 'select', 'all', __( 'Devices', 'agentixhub-chat' ), '', array( 'all' => __( 'All devices', 'agentixhub-chat' ), 'desktop' => __( 'Desktop only', 'agentixhub-chat' ), 'mobile' => __( 'Mobile only', 'agentixhub-chat' ) ) ), 'hide_for_admins' => array( 'display', 'toggle', 0, __( 'Hide for administrators', 'agentixhub-chat' ), __( 'Ignored in Test mode.', 'agentixhub-chat' ) ), // Advanced. 'analytics' => array( 'advanced', 'toggle', 0, __( 'Analytics events', 'agentixhub-chat' ), __( 'Pushes agentix_chat_* events to dataLayer / gtag when present.', 'agentixhub-chat' ) ), 'delete_on_uninstall' => array( 'advanced', 'toggle', 1, __( 'Delete all settings when the plugin is uninstalled', 'agentixhub-chat' ) ), ); } /** Normalised field definition. */ public static function field( string $key ): array { $f = self::schema()[ $key ]; return array( 'key' => $key, 'tab' => $f[0], 'type' => $f[1], 'default' => $f[2], 'label' => $f[3], 'desc' => $f[4] ?? '', 'choices' => isset( $f[5] ) && is_callable( $f[5] ) ? call_user_func( $f[5] ) : ( $f[5] ?? array() ), 'show_if' => $f[6] ?? null, 'range' => $f[7] ?? null, ); } public static function defaults(): array { return array_map( fn( $f ) => $f[2], self::schema() ); } public static function all(): array { if ( null === self::$cache ) { $stored = get_option( self::OPTION, array() ); // Only current settings: values saved by older versions for removed settings are ignored. $stored = is_array( $stored ) ? array_intersect_key( $stored, self::schema() ) : array(); // 0.1/0.2 used mock|agentix. if ( isset( $stored['mode'] ) && ! in_array( $stored['mode'], array( 'test', 'live' ), true ) ) { $stored['mode'] = 'agentix' === $stored['mode'] ? 'live' : 'test'; } self::$cache = array_merge( wp_parse_args( $stored, self::defaults() ), array_intersect_key( self::defaults(), array_flip( self::HIDDEN ) ) ); if ( defined( 'AGENTIX_CHAT_WORKFLOW_URL' ) && AGENTIX_CHAT_WORKFLOW_URL ) { self::$cache['workflow_url'] = AGENTIX_CHAT_WORKFLOW_URL; } } return self::$cache; } public static function get( string $key ) { return self::all()[ $key ] ?? null; } public static function flush(): void { self::$cache = null; } /** Whether visitors (not only admins) should see the chat. */ public static function visible_to_current_user(): bool { return 'live' === self::get( 'mode' ) || current_user_can( 'manage_options' ); } public static function sanitize( $input ): array { $input = is_array( $input ) ? $input : array(); $current = get_option( self::OPTION, array() ); $out = array(); foreach ( array_keys( self::schema() ) as $key ) { $f = self::field( $key ); $out[ $key ] = in_array( $key, self::HIDDEN, true ) ? $f['default'] : self::sanitize_value( $f, $input[ $key ] ?? null ); } // Workflow URL: kept when the form does not send it (wp-config constant, settings import). $url = $out['workflow_url']; if ( ! array_key_exists( 'workflow_url', $input ) ) { $url = $current['workflow_url'] ?? ''; } if ( '' !== $url && is_wp_error( Agentix_Chat_Workflow_Url::parse( $url ) ) ) { add_settings_error( self::OPTION, 'workflow_url', Agentix_Chat_Workflow_Url::parse( $url )->get_error_message() ); $url = $current['workflow_url'] ?? ''; } $has_constant = defined( 'AGENTIX_CHAT_WORKFLOW_URL' ) && AGENTIX_CHAT_WORKFLOW_URL; if ( '' === $url && ! $has_constant && $out['enabled'] ) { add_settings_error( self::OPTION, 'workflow_url_required', __( 'A workflow URL is required — the chat stays hidden until one is saved.', 'agentixhub-chat' ), 'warning' ); } $out['workflow_url'] = $url; self::flush(); return $out; } private static function sanitize_value( array $f, $raw ) { // Only checklists and hours take arrays; anything else that is not a scalar (e.g. from a crafted import) falls back to the default. if ( ! in_array( $f['type'], array( 'checklist', 'hours' ), true ) && null !== $raw && ! is_scalar( $raw ) ) { $raw = $f['default']; } switch ( $f['type'] ) { case 'toggle': return empty( $raw ) ? 0 : 1; case 'number': $n = is_numeric( $raw ) ? (int) $raw : (int) $f['default']; return $f['range'] ? max( $f['range'][0], min( $f['range'][1], $n ) ) : $n; case 'select': return array_key_exists( (string) $raw, $f['choices'] ) ? (string) $raw : $f['default']; case 'checklist': return array_values( array_intersect( array_map( 'strval', array_filter( (array) $raw, 'is_scalar' ) ), array_map( 'strval', array_keys( $f['choices'] ) ) ) ); case 'color': // Colours with an empty default are optional ("inherit"); others fall back to their default. return sanitize_hex_color( (string) $raw ) ?: $f['default']; case 'media': return esc_url_raw( (string) $raw ); case 'workflow_url': return trim( esc_url_raw( (string) $raw ) ); case 'textarea': case 'lines': return sanitize_textarea_field( (string) $raw ); case 'hours': $raw = is_array( $raw ) ? $raw : array(); $out = array(); foreach ( self::default_hours() as $day => $d ) { $r = (array) ( $raw[ $day ] ?? array() ); $out[ $day ] = array( 'on' => empty( $r['on'] ) ? 0 : 1, 'open' => is_string( $r['open'] ?? null ) && preg_match( '/^\d{2}:\d{2}$/', $r['open'] ) ? $r['open'] : $d['open'], 'close' => is_string( $r['close'] ?? null ) && preg_match( '/^\d{2}:\d{2}$/', $r['close'] ) ? $r['close'] : $d['close'], ); } return $out; default: return sanitize_text_field( (string) $raw ); } } public static function default_hours(): array { $out = array(); foreach ( array( 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' ) as $i => $day ) { $out[ $day ] = array( 'on' => $i < 5 ? 1 : 0, 'open' => '09:00', 'close' => '18:00' ); } return $out; } public static function special_pages(): array { $pages = array( 'front' => __( 'Front page', 'agentixhub-chat' ), 'blog' => __( 'Blog index', 'agentixhub-chat' ), 'single' => __( 'Single posts', 'agentixhub-chat' ), 'page' => __( 'Pages', 'agentixhub-chat' ), 'archive' => __( 'Archives', 'agentixhub-chat' ), 'search' => __( 'Search results', 'agentixhub-chat' ), '404' => __( '404 page', 'agentixhub-chat' ), ); if ( class_exists( 'WooCommerce' ) ) { $pages += array( 'wc_shop' => __( 'Shop', 'agentixhub-chat' ), 'wc_product' => __( 'Product pages', 'agentixhub-chat' ), 'wc_cart' => __( 'Cart', 'agentixhub-chat' ), 'wc_checkout' => __( 'Checkout', 'agentixhub-chat' ), 'wc_account' => __( 'My Account', 'agentixhub-chat' ), ); } return $pages; } public static function post_types(): array { $out = array(); foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $pt ) { if ( 'attachment' !== $pt->name ) { $out[ $pt->name ] = $pt->labels->name; } } return $out; } public static function roles(): array { return function_exists( 'wp_roles' ) ? wp_roles()->get_names() : array(); } }