'USD — US Dollar', 'EUR' => 'EUR — Euro', 'GBP' => 'GBP — British Pound', 'AUD' => 'AUD — Australian Dollar', 'CAD' => 'CAD — Canadian Dollar', 'NZD' => 'NZD — New Zealand Dollar', 'CHF' => 'CHF — Swiss Franc', 'SEK' => 'SEK — Swedish Krona', 'NOK' => 'NOK — Norwegian Krone', 'DKK' => 'DKK — Danish Krone', 'SGD' => 'SGD — Singapore Dollar', 'HKD' => 'HKD — Hong Kong Dollar', 'AED' => 'AED — UAE Dirham', 'INR' => 'INR — Indian Rupee', 'NPR' => 'NPR — Nepalese Rupee', 'JPY' => 'JPY — Japanese Yen', 'KRW' => 'KRW — South Korean Won', 'MXN' => 'MXN — Mexican Peso', 'BRL' => 'BRL — Brazilian Real', 'ZAR' => 'ZAR — South African Rand', ); } /** * Full grouped schema. Group → sections → fields. */ public static function schema() { if ( null !== self::$schema ) { return self::$schema; } $placeholders = '{name}, {reference}, {date}, {time}, {party}, {table}, {room}, {restaurant}, {manage_url}, {amount}, {notes}, {phone}, {email}'; self::$schema = apply_filters( 'tableengine_settings_schema', array( 'general' => array( 'label' => __( 'General', 'tableengine' ), 'icon' => 'admin-home', 'sections' => array( 'restaurant' => array( 'title' => __( 'Restaurant', 'tableengine' ), 'desc' => __( 'Basic details shown on the booking widget, emails and calendar invites.', 'tableengine' ), 'fields' => array( 'restaurant_name' => array( 'type' => 'text', 'label' => __( 'Restaurant name', 'tableengine' ), 'default' => get_bloginfo( 'name' ) ), 'restaurant_address' => array( 'type' => 'textarea', 'label' => __( 'Address', 'tableengine' ), 'default' => '', 'rows' => 2, 'help' => __( 'Used in calendar invites and confirmation emails.', 'tableengine' ) ), 'restaurant_phone' => array( 'type' => 'text', 'label' => __( 'Phone', 'tableengine' ), 'default' => '' ), 'booking_page' => array( 'type' => 'page', 'label' => __( 'Booking page', 'tableengine' ), 'default' => 0, 'help' => __( 'Page containing the [tableengine] shortcode. Used for “manage booking” links.', 'tableengine' ) ), ), ), 'locale' => array( 'title' => __( 'Locale & format', 'tableengine' ), 'fields' => array( 'currency' => array( 'type' => 'select', 'label' => __( 'Currency', 'tableengine' ), 'default' => 'USD', 'options' => self::currencies() ), 'time_format' => array( 'type' => 'select', 'label' => __( 'Time format', 'tableengine' ), 'default' => '12', 'options' => array( '12' => __( '12-hour (7:30 PM)', 'tableengine' ), '24' => __( '24-hour (19:30)', 'tableengine' ) ), ), 'week_starts' => array( 'type' => 'select', 'label' => __( 'Calendar week starts on', 'tableengine' ), 'default' => '1', 'options' => array( '0' => __( 'Sunday', 'tableengine' ), '1' => __( 'Monday', 'tableengine' ), '6' => __( 'Saturday', 'tableengine' ) ), ), ), ), ), ), 'booking' => array( 'label' => __( 'Booking rules', 'tableengine' ), 'icon' => 'calendar-alt', 'sections' => array( 'party' => array( 'title' => __( 'Party size', 'tableengine' ), 'fields' => array( 'min_party' => array( 'type' => 'number', 'label' => __( 'Minimum guests', 'tableengine' ), 'default' => 1, 'min' => 1, 'max' => 100 ), 'max_party' => array( 'type' => 'number', 'label' => __( 'Maximum guests online', 'tableengine' ), 'default' => 10, 'min' => 1, 'max' => 200 ), 'large_party_message' => array( 'type' => 'text', 'label' => __( 'Large party message', 'tableengine' ), 'default' => __( 'For larger groups, please call us — we’d love to host you.', 'tableengine' ), 'help' => __( 'Shown below the guest picker.', 'tableengine' ) ), ), ), 'timing' => array( 'title' => __( 'Timing & durations', 'tableengine' ), 'fields' => array( 'slot_interval' => array( 'type' => 'select', 'label' => __( 'Time slot interval', 'tableengine' ), 'default' => '15', 'options' => array( '10' => '10 min', '15' => '15 min', '20' => '20 min', '30' => '30 min', '45' => '45 min', '60' => '60 min' ), ), 'duration' => array( 'type' => 'number', 'label' => __( 'Default dining duration (minutes)', 'tableengine' ), 'default' => 90, 'min' => 15, 'max' => 600, 'step' => 5 ), 'large_party_threshold' => array( 'type' => 'number', 'label' => __( 'Large party threshold (guests)', 'tableengine' ), 'default' => 6, 'min' => 1, 'max' => 200, 'help' => __( 'Parties of this size or more use the longer duration.', 'tableengine' ) ), 'large_party_duration' => array( 'type' => 'number', 'label' => __( 'Large party duration (minutes)', 'tableengine' ), 'default' => 120, 'min' => 15, 'max' => 600, 'step' => 5 ), 'buffer' => array( 'type' => 'number', 'label' => __( 'Turnover buffer (minutes)', 'tableengine' ), 'default' => 15, 'min' => 0, 'max' => 240, 'step' => 5, 'help' => __( 'Time kept free between bookings at the same table for resetting.', 'tableengine' ) ), ), ), 'window' => array( 'title' => __( 'Booking window', 'tableengine' ), 'fields' => array( 'lead_time' => array( 'type' => 'number', 'label' => __( 'Minimum notice (minutes)', 'tableengine' ), 'default' => 60, 'min' => 0, 'max' => 10080, 'step' => 5 ), 'max_advance_days' => array( 'type' => 'number', 'label' => __( 'Book up to (days ahead)', 'tableengine' ), 'default' => 60, 'min' => 1, 'max' => 730 ), 'max_covers_slot' => array( 'type' => 'number', 'label' => __( 'Max guests starting per slot', 'tableengine' ), 'default' => 0, 'min' => 0, 'max' => 2000, 'help' => __( 'Pace the kitchen. 0 = unlimited.', 'tableengine' ) ), ), ), 'workflow' => array( 'title' => __( 'Workflow', 'tableengine' ), 'fields' => array( 'auto_confirm' => array( 'type' => 'toggle', 'label' => __( 'Auto-confirm bookings', 'tableengine' ), 'default' => 1, 'help' => __( 'When off, bookings stay “Pending” until you approve them.', 'tableengine' ) ), 'table_selection' => array( 'type' => 'select', 'label' => __( 'Table selection', 'tableengine' ), 'default' => 'optional', 'options' => array( 'required' => __( 'Guests must choose a table', 'tableengine' ), 'optional' => __( 'Guests may choose or let us assign', 'tableengine' ), 'auto' => __( 'Always auto-assign (hide floor plan)', 'tableengine' ), ), ), 'allow_oversize' => array( 'type' => 'toggle', 'label' => __( 'Allow small parties at large tables', 'tableengine' ), 'default' => 0, 'help' => __( 'When off, a table’s minimum seats is enforced.', 'tableengine' ) ), ), ), ), ), 'hours' => array( 'label' => __( 'Opening hours', 'tableengine' ), 'icon' => 'clock', 'sections' => array( 'weekly' => array( 'title' => __( 'Weekly schedule', 'tableengine' ), 'desc' => __( 'Add one or more service periods per day (e.g. lunch and dinner). Leave a day empty to close.', 'tableengine' ), 'fields' => array( 'opening_hours' => array( 'type' => 'weekly_hours', 'label' => '', 'default' => array( '0' => '12:00-15:00, 18:00-22:00', '1' => '', '2' => '18:00-22:00', '3' => '18:00-22:00', '4' => '18:00-22:00', '5' => '12:00-15:00, 18:00-23:00', '6' => '12:00-15:00, 18:00-23:00', ), ), 'last_seating' => array( 'type' => 'number', 'label' => __( 'Last booking before closing (minutes)', 'tableengine' ), 'default' => 60, 'min' => 0, 'max' => 600, 'step' => 5 ), ), ), 'closures' => array( 'title' => __( 'Closures & exceptions', 'tableengine' ), 'fields' => array( 'closed_dates' => array( 'type' => 'textarea', 'label' => __( 'Closed dates', 'tableengine' ), 'default' => '', 'rows' => 4, 'placeholder' => "2026-12-25\n2026-12-31..2027-01-02", 'help' => __( 'One per line. Use YYYY-MM-DD or a range YYYY-MM-DD..YYYY-MM-DD.', 'tableengine' ) ), 'special_hours' => array( 'type' => 'textarea', 'label' => __( 'Special hours', 'tableengine' ), 'default' => '', 'rows' => 4, 'placeholder' => '2026-12-24 = 17:00-21:00', 'help' => __( 'Override a date’s hours: YYYY-MM-DD = 17:00-21:00, 22:00-23:30', 'tableengine' ) ), 'closed_message' => array( 'type' => 'text', 'label' => __( 'Closed day message', 'tableengine' ), 'default' => __( 'We’re closed on this day. Please choose another date.', 'tableengine' ) ), ), ), ), ), 'floorplan' => array( 'label' => __( 'Floor plan', 'tableengine' ), 'icon' => 'layout', 'sections' => array( 'views' => array( 'title' => __( 'Table picker', 'tableengine' ), 'fields' => array( 'mobile_view' => array( 'type' => 'select', 'label' => __( 'Default view on mobile', 'tableengine' ), 'default' => 'list', 'options' => array( 'list' => __( 'List', 'tableengine' ), 'map' => __( 'Map', 'tableengine' ) ) ), 'desktop_view' => array( 'type' => 'select', 'label' => __( 'Default view on desktop', 'tableengine' ), 'default' => 'map', 'options' => array( 'map' => __( 'Map', 'tableengine' ), 'list' => __( 'List', 'tableengine' ) ) ), 'mobile_breakpoint' => array( 'type' => 'number', 'label' => __( 'Mobile breakpoint (px)', 'tableengine' ), 'default' => 720, 'min' => 320, 'max' => 1400 ), 'map_height' => array( 'type' => 'number', 'label' => __( 'Map max height (% of screen)', 'tableengine' ), 'default' => 65, 'min' => 30, 'max' => 100 ), 'show_unavailable' => array( 'type' => 'toggle', 'label' => __( 'Show unavailable tables in list', 'tableengine' ), 'default' => 1 ), 'show_seats' => array( 'type' => 'toggle', 'label' => __( 'Show seat counts on the map', 'tableengine' ), 'default' => 1 ), 'show_chairs' => array( 'type' => 'toggle', 'label' => __( 'Draw chairs around tables', 'tableengine' ), 'default' => 1 ), 'show_legend' => array( 'type' => 'toggle', 'label' => __( 'Show legend', 'tableengine' ), 'default' => 1 ), 'auto_fit' => array( 'type' => 'toggle', 'label' => __( 'Zoom map to fit on load', 'tableengine' ), 'default' => 1 ), 'mobile_rotate' => array( 'type' => 'toggle', 'label' => __( 'Rotate wide floor plans to portrait on phones', 'tableengine' ), 'default' => 1, 'help' => __( 'Uses the screen height so tables are larger and easier to tap.', 'tableengine' ) ), ), ), 'colors' => array( 'title' => __( 'Map colours', 'tableengine' ), 'fields' => array( 'color_floor' => array( 'type' => 'color', 'label' => __( 'Floor', 'tableengine' ), 'default' => '#f6f1ea' ), 'color_table' => array( 'type' => 'color', 'label' => __( 'Table surface', 'tableengine' ), 'default' => '#ffffff' ), 'color_available' => array( 'type' => 'color', 'label' => __( 'Available', 'tableengine' ), 'default' => '#2f9e6b' ), 'color_selected' => array( 'type' => 'color', 'label' => __( 'Selected', 'tableengine' ), 'default' => '#c2410c' ), 'color_unavailable' => array( 'type' => 'color', 'label' => __( 'Unavailable', 'tableengine' ), 'default' => '#c9c3bb' ), ), ), ), ), 'payments' => array( 'label' => __( 'Payments', 'tableengine' ), 'icon' => 'money-alt', 'sections' => array( 'stripe' => array( 'title' => __( 'Stripe', 'tableengine' ), 'desc' => __( 'Collect a deposit or guarantee when guests book. Payments are confirmed via Stripe webhooks.', 'tableengine' ), 'fields' => array( 'stripe_enabled' => array( 'type' => 'toggle', 'label' => __( 'Require payment when booking', 'tableengine' ), 'default' => 0 ), 'stripe_mode' => array( 'type' => 'select', 'label' => __( 'Mode', 'tableengine' ), 'default' => 'test', 'options' => array( 'test' => __( 'Test', 'tableengine' ), 'live' => __( 'Live', 'tableengine' ) ) ), 'stripe_test_pk' => array( 'type' => 'text', 'label' => __( 'Test publishable key', 'tableengine' ), 'default' => '', 'placeholder' => 'pk_test_…', 'show_if' => array( 'stripe_mode' => 'test' ) ), 'stripe_test_sk' => array( 'type' => 'password', 'label' => __( 'Test secret key', 'tableengine' ), 'default' => '', 'placeholder' => 'sk_test_…', 'show_if' => array( 'stripe_mode' => 'test' ) ), 'stripe_test_whsec' => array( 'type' => 'password', 'label' => __( 'Test webhook signing secret', 'tableengine' ), 'default' => '', 'placeholder' => 'whsec_…', 'show_if' => array( 'stripe_mode' => 'test' ) ), 'stripe_live_pk' => array( 'type' => 'text', 'label' => __( 'Live publishable key', 'tableengine' ), 'default' => '', 'placeholder' => 'pk_live_…', 'show_if' => array( 'stripe_mode' => 'live' ) ), 'stripe_live_sk' => array( 'type' => 'password', 'label' => __( 'Live secret key', 'tableengine' ), 'default' => '', 'placeholder' => 'sk_live_… or rk_live_…', 'show_if' => array( 'stripe_mode' => 'live' ) ), 'stripe_live_whsec' => array( 'type' => 'password', 'label' => __( 'Live webhook signing secret', 'tableengine' ), 'default' => '', 'placeholder' => 'whsec_…', 'show_if' => array( 'stripe_mode' => 'live' ) ), 'stripe_webhook_info' => array( 'type' => 'webhook_info', 'label' => __( 'Webhook endpoint', 'tableengine' ) ), ), ), 'deposit' => array( 'title' => __( 'Deposit', 'tableengine' ), 'fields' => array( 'deposit_type' => array( 'type' => 'select', 'label' => __( 'Charge', 'tableengine' ), 'default' => 'per_person', 'options' => array( 'per_person' => __( 'Per guest', 'tableengine' ), 'per_booking' => __( 'Flat per booking', 'tableengine' ) ), ), 'deposit_amount' => array( 'type' => 'decimal', 'label' => __( 'Amount', 'tableengine' ), 'default' => '10.00' ), 'deposit_min_party' => array( 'type' => 'number', 'label' => __( 'Only charge parties of at least', 'tableengine' ), 'default' => 1, 'min' => 1, 'max' => 200 ), 'deposit_label' => array( 'type' => 'text', 'label' => __( 'Label shown to guests', 'tableengine' ), 'default' => __( 'Booking deposit', 'tableengine' ) ), 'deposit_note' => array( 'type' => 'textarea', 'label' => __( 'Deposit explanation', 'tableengine' ), 'default' => __( 'Your deposit is deducted from your final bill.', 'tableengine' ), 'rows' => 2 ), 'hold_minutes' => array( 'type' => 'number', 'label' => __( 'Hold table during checkout (minutes)', 'tableengine' ), 'default' => 10, 'min' => 3, 'max' => 60 ), 'payment_layout' => array( 'type' => 'select', 'label' => __( 'Payment form layout', 'tableengine' ), 'default' => 'tabs', 'options' => array( 'tabs' => __( 'Tabs', 'tableengine' ), 'accordion' => __( 'Accordion', 'tableengine' ) ) ), 'statement_descriptor' => array( 'type' => 'text', 'label' => __( 'Statement descriptor suffix', 'tableengine' ), 'default' => '', 'maxlength' => 22, 'help' => __( 'Optional. Max 22 characters, appears on card statements.', 'tableengine' ) ), ), ), 'refunds' => array( 'title' => __( 'Refunds', 'tableengine' ), 'fields' => array( 'refund_on_cancel' => array( 'type' => 'toggle', 'label' => __( 'Auto-refund when guests cancel in time', 'tableengine' ), 'default' => 1 ), 'refund_cutoff_hours' => array( 'type' => 'number', 'label' => __( 'Refund if cancelled at least (hours before)', 'tableengine' ), 'default' => 24, 'min' => 0, 'max' => 720 ), ), ), ), ), 'form' => array( 'label' => __( 'Guest form', 'tableengine' ), 'icon' => 'id', 'sections' => array( 'fields' => array( 'title' => __( 'Fields', 'tableengine' ), 'fields' => array( 'phone_field' => array( 'type' => 'select', 'label' => __( 'Phone number', 'tableengine' ), 'default' => 'required', 'options' => array( 'required' => __( 'Required', 'tableengine' ), 'optional' => __( 'Optional', 'tableengine' ), 'hidden' => __( 'Hidden', 'tableengine' ) ) ), 'notes_field' => array( 'type' => 'select', 'label' => __( 'Special requests', 'tableengine' ), 'default' => 'optional', 'options' => array( 'required' => __( 'Required', 'tableengine' ), 'optional' => __( 'Optional', 'tableengine' ), 'hidden' => __( 'Hidden', 'tableengine' ) ) ), 'occasion_field' => array( 'type' => 'toggle', 'label' => __( 'Ask for occasion', 'tableengine' ), 'default' => 1 ), 'occasions' => array( 'type' => 'textarea', 'label' => __( 'Occasions', 'tableengine' ), 'default' => "Birthday\nAnniversary\nDate night\nBusiness meal\nCelebration", 'rows' => 5, 'help' => __( 'One per line.', 'tableengine' ) ), 'notes_placeholder' => array( 'type' => 'text', 'label' => __( 'Requests placeholder', 'tableengine' ), 'default' => __( 'Allergies, high chair, accessibility needs…', 'tableengine' ) ), ), ), 'consent' => array( 'title' => __( 'Consent', 'tableengine' ), 'fields' => array( 'terms_required' => array( 'type' => 'toggle', 'label' => __( 'Require terms acceptance', 'tableengine' ), 'default' => 0 ), 'terms_text' => array( 'type' => 'text', 'label' => __( 'Terms checkbox text', 'tableengine' ), 'default' => __( 'I agree to the booking terms and cancellation policy.', 'tableengine' ) ), 'terms_url' => array( 'type' => 'url', 'label' => __( 'Terms page URL', 'tableengine' ), 'default' => '' ), 'marketing_optin' => array( 'type' => 'toggle', 'label' => __( 'Show marketing opt-in', 'tableengine' ), 'default' => 0 ), 'marketing_text' => array( 'type' => 'text', 'label' => __( 'Opt-in text', 'tableengine' ), 'default' => __( 'Send me news and special offers.', 'tableengine' ) ), ), ), ), ), 'guests' => array( 'label' => __( 'Guest self-service', 'tableengine' ), 'icon' => 'groups', 'sections' => array( 'manage' => array( 'title' => __( 'Manage booking', 'tableengine' ), 'fields' => array( 'allow_cancel' => array( 'type' => 'toggle', 'label' => __( 'Guests can cancel online', 'tableengine' ), 'default' => 1 ), 'cancel_cutoff_hours' => array( 'type' => 'number', 'label' => __( 'Cancellation allowed until (hours before)', 'tableengine' ), 'default' => 2, 'min' => 0, 'max' => 720 ), 'calendar_links' => array( 'type' => 'toggle', 'label' => __( 'Show “Add to calendar” buttons', 'tableengine' ), 'default' => 1 ), 'success_message' => array( 'type' => 'textarea', 'label' => __( 'Confirmation message', 'tableengine' ), 'default' => __( 'We’ve sent the details to your inbox. We look forward to welcoming you!', 'tableengine' ), 'rows' => 2 ), 'pending_message' => array( 'type' => 'textarea', 'label' => __( 'Pending approval message', 'tableengine' ), 'default' => __( 'Your request has been received. We’ll email you as soon as it’s confirmed.', 'tableengine' ), 'rows' => 2 ), ), ), ), ), 'notifications' => array( 'label' => __( 'Notifications', 'tableengine' ), 'icon' => 'email-alt', 'sections' => array( 'sender' => array( 'title' => __( 'Sender', 'tableengine' ), 'fields' => array( 'from_name' => array( 'type' => 'text', 'label' => __( 'From name', 'tableengine' ), 'default' => get_bloginfo( 'name' ) ), 'from_email' => array( 'type' => 'email', 'label' => __( 'From email', 'tableengine' ), 'default' => get_option( 'admin_email' ) ), 'email_logo' => array( 'type' => 'url', 'label' => __( 'Email logo URL', 'tableengine' ), 'default' => '' ), 'email_footer' => array( 'type' => 'textarea', 'label' => __( 'Email footer', 'tableengine' ), 'default' => '', 'rows' => 2 ), ), ), 'admin' => array( 'title' => __( 'Restaurant alerts', 'tableengine' ), 'fields' => array( 'admin_notify' => array( 'type' => 'toggle', 'label' => __( 'Email the restaurant on new bookings', 'tableengine' ), 'default' => 1 ), 'admin_cancel_notify' => array( 'type' => 'toggle', 'label' => __( 'Email the restaurant on cancellations', 'tableengine' ), 'default' => 1 ), 'admin_emails' => array( 'type' => 'text', 'label' => __( 'Recipients', 'tableengine' ), 'default' => get_option( 'admin_email' ), 'help' => __( 'Comma separated.', 'tableengine' ) ), ), ), 'confirm' => array( 'title' => __( 'Guest: confirmed', 'tableengine' ), 'desc' => sprintf( /* translators: %s placeholders */ __( 'Placeholders: %s', 'tableengine' ), $placeholders ), 'fields' => array( 'email_confirm_on' => array( 'type' => 'toggle', 'label' => __( 'Send', 'tableengine' ), 'default' => 1 ), 'email_confirm_subject' => array( 'type' => 'text', 'label' => __( 'Subject', 'tableengine' ), 'default' => __( 'Your table at {restaurant} is confirmed', 'tableengine' ) ), 'email_confirm_body' => array( 'type' => 'textarea', 'label' => __( 'Message', 'tableengine' ), 'rows' => 6, 'default' => __( "Hi {name},\n\nGreat news — your table is confirmed. We can’t wait to see you.\n\nNeed to make a change? Manage your booking here: {manage_url}", 'tableengine' ) ), ), ), 'pending' => array( 'title' => __( 'Guest: request received (pending)', 'tableengine' ), 'fields' => array( 'email_pending_on' => array( 'type' => 'toggle', 'label' => __( 'Send', 'tableengine' ), 'default' => 1 ), 'email_pending_subject' => array( 'type' => 'text', 'label' => __( 'Subject', 'tableengine' ), 'default' => __( 'We received your booking request', 'tableengine' ) ), 'email_pending_body' => array( 'type' => 'textarea', 'label' => __( 'Message', 'tableengine' ), 'rows' => 5, 'default' => __( "Hi {name},\n\nThanks for your request. We’ll review it and confirm shortly.", 'tableengine' ) ), ), ), 'cancel' => array( 'title' => __( 'Guest: cancelled', 'tableengine' ), 'fields' => array( 'email_cancel_on' => array( 'type' => 'toggle', 'label' => __( 'Send', 'tableengine' ), 'default' => 1 ), 'email_cancel_subject' => array( 'type' => 'text', 'label' => __( 'Subject', 'tableengine' ), 'default' => __( 'Your booking has been cancelled', 'tableengine' ) ), 'email_cancel_body' => array( 'type' => 'textarea', 'label' => __( 'Message', 'tableengine' ), 'rows' => 5, 'default' => __( "Hi {name},\n\nYour booking {reference} has been cancelled. We hope to see you another time.", 'tableengine' ) ), ), ), 'reminder' => array( 'title' => __( 'Guest: reminder', 'tableengine' ), 'fields' => array( 'email_reminder_on' => array( 'type' => 'toggle', 'label' => __( 'Send', 'tableengine' ), 'default' => 1 ), 'reminder_hours' => array( 'type' => 'number', 'label' => __( 'Hours before booking', 'tableengine' ), 'default' => 24, 'min' => 1, 'max' => 168 ), 'email_reminder_subject' => array( 'type' => 'text', 'label' => __( 'Subject', 'tableengine' ), 'default' => __( 'See you soon at {restaurant}', 'tableengine' ) ), 'email_reminder_body' => array( 'type' => 'textarea', 'label' => __( 'Message', 'tableengine' ), 'rows' => 5, 'default' => __( "Hi {name},\n\nJust a friendly reminder of your table for {party} on {date} at {time}.", 'tableengine' ) ), ), ), ), ), 'appearance' => array( 'label' => __( 'Appearance', 'tableengine' ), 'icon' => 'art', 'sections' => array( 'theme' => array( 'title' => __( 'Theme', 'tableengine' ), 'fields' => array( 'theme' => array( 'type' => 'select', 'label' => __( 'Colour scheme', 'tableengine' ), 'default' => 'light', 'options' => array( 'light' => __( 'Light', 'tableengine' ), 'dark' => __( 'Dark', 'tableengine' ), 'auto' => __( 'Follow device', 'tableengine' ) ) ), 'primary_color' => array( 'type' => 'color', 'label' => __( 'Primary colour', 'tableengine' ), 'default' => '#c2410c' ), 'accent_color' => array( 'type' => 'color', 'label' => __( 'Accent colour', 'tableengine' ), 'default' => '#1f2937' ), 'radius' => array( 'type' => 'number', 'label' => __( 'Corner radius (px)', 'tableengine' ), 'default' => 14, 'min' => 0, 'max' => 32 ), 'font' => array( 'type' => 'select', 'label' => __( 'Font', 'tableengine' ), 'default' => 'inherit', 'options' => array( 'inherit' => __( 'Inherit from theme', 'tableengine' ), 'system' => __( 'System UI', 'tableengine' ), 'serif' => __( 'Elegant serif headings', 'tableengine' ) ), ), ), ), 'layout' => array( 'title' => __( 'Layout', 'tableengine' ), 'fields' => array( 'max_width' => array( 'type' => 'number', 'label' => __( 'Widget max width (px)', 'tableengine' ), 'default' => 960, 'min' => 360, 'max' => 1600 ), 'show_header' => array( 'type' => 'toggle', 'label' => __( 'Show widget header', 'tableengine' ), 'default' => 1 ), 'header_title' => array( 'type' => 'text', 'label' => __( 'Header title', 'tableengine' ), 'default' => __( 'Reserve a table', 'tableengine' ) ), 'header_subtitle' => array( 'type' => 'text', 'label' => __( 'Header subtitle', 'tableengine' ), 'default' => __( 'Choose your time and pick your favourite spot.', 'tableengine' ) ), 'shadow' => array( 'type' => 'toggle', 'label' => __( 'Card shadow', 'tableengine' ), 'default' => 1 ), ), ), ), ), 'advanced' => array( 'label' => __( 'Advanced', 'tableengine' ), 'icon' => 'admin-tools', 'sections' => array( 'security' => array( 'title' => __( 'Spam & security', 'tableengine' ), 'fields' => array( 'rate_limit' => array( 'type' => 'number', 'label' => __( 'Max booking attempts per IP per hour', 'tableengine' ), 'default' => 15, 'min' => 0, 'max' => 1000, 'help' => __( '0 disables the limit.', 'tableengine' ) ), 'honeypot' => array( 'type' => 'toggle', 'label' => __( 'Honeypot spam trap', 'tableengine' ), 'default' => 1 ), ), ), 'data' => array( 'title' => __( 'Data', 'tableengine' ), 'fields' => array( 'debug_log' => array( 'type' => 'toggle', 'label' => __( 'Log Stripe requests to debug.log', 'tableengine' ), 'default' => 0 ), 'delete_on_uninstall' => array( 'type' => 'toggle', 'label' => __( 'Delete all data on uninstall', 'tableengine' ), 'default' => 0 ), ), ), ), ), ) ); return self::$schema; } /** * Flat map key => field definition. */ public static function fields() { $out = array(); foreach ( self::schema() as $group ) { foreach ( $group['sections'] as $section ) { foreach ( $section['fields'] as $key => $field ) { $out[ $key ] = $field; } } } return $out; } public static function defaults() { $defaults = array(); foreach ( self::fields() as $key => $field ) { if ( array_key_exists( 'default', $field ) ) { $defaults[ $key ] = $field['default']; } } return $defaults; } public static function all() { if ( null === self::$cache ) { $saved = get_option( self::OPTION, array() ); self::$cache = wp_parse_args( is_array( $saved ) ? $saved : array(), self::defaults() ); } /** Effective values, e.g. with the current location's overrides applied. */ return apply_filters( 'tableengine_settings_values', self::$cache ); } public static function get( $key, $fallback = null ) { $all = self::all(); return array_key_exists( $key, $all ) ? $all[ $key ] : $fallback; } public static function flush() { self::$cache = null; } /** * Choices of a select field: its `options`, or what its `options_cb` callable returns. * * @return array value => label. */ public static function field_options( array $field ) { if ( isset( $field['options'] ) && is_array( $field['options'] ) ) { return $field['options']; } if ( ! empty( $field['options_cb'] ) && is_callable( $field['options_cb'] ) ) { return (array) call_user_func( $field['options_cb'] ); } return array(); } /** * Sanitise submitted values against the schema. */ public static function sanitize( array $input ) { $clean = array(); foreach ( self::fields() as $key => $field ) { if ( ! array_key_exists( 'default', $field ) ) { continue; } $raw = isset( $input[ $key ] ) ? wp_unslash( $input[ $key ] ) : null; switch ( $field['type'] ) { case 'toggle': $clean[ $key ] = empty( $raw ) ? 0 : 1; break; case 'number': $val = is_numeric( $raw ) ? (int) $raw : (int) $field['default']; if ( isset( $field['min'] ) ) { $val = max( (int) $field['min'], $val ); } if ( isset( $field['max'] ) ) { $val = min( (int) $field['max'], $val ); } $clean[ $key ] = $val; break; case 'decimal': $val = is_numeric( $raw ) ? max( 0, (float) $raw ) : (float) $field['default']; $clean[ $key ] = number_format( $val, 2, '.', '' ); break; case 'select': $options = self::field_options( $field ); $clean[ $key ] = ( null !== $raw && is_scalar( $raw ) && isset( $options[ (string) $raw ] ) ) ? (string) $raw : $field['default']; break; case 'color': $clean[ $key ] = sanitize_hex_color( (string) $raw ) ? sanitize_hex_color( (string) $raw ) : $field['default']; break; case 'email': $clean[ $key ] = sanitize_email( (string) $raw ); break; case 'url': $clean[ $key ] = esc_url_raw( (string) $raw ); break; case 'page': $clean[ $key ] = absint( $raw ); break; case 'textarea': $clean[ $key ] = sanitize_textarea_field( (string) $raw ); break; case 'code': $clean[ $key ] = wp_strip_all_tags( (string) $raw ); break; case 'password': // Keep the existing secret when the masked field is left untouched. $raw = trim( (string) $raw ); $clean[ $key ] = ( '' === $raw || preg_match( '/^•+$/u', $raw ) ) ? ( '' === $raw ? '' : self::get( $key, '' ) ) : sanitize_text_field( $raw ); break; case 'weekly_hours': $days = array(); for ( $d = 0; $d < 7; $d++ ) { $days[ (string) $d ] = isset( $raw[ $d ] ) ? self::sanitize_ranges( (string) $raw[ $d ] ) : ''; } $clean[ $key ] = $days; break; default: if ( has_filter( "tableengine_sanitize_field_{$field['type']}" ) ) { // Custom field types registered by extensions sanitise themselves. $clean[ $key ] = apply_filters( "tableengine_sanitize_field_{$field['type']}", $field['default'], $raw, $field, $key ); break; } $val = sanitize_text_field( (string) $raw ); if ( isset( $field['maxlength'] ) ) { $val = mb_substr( $val, 0, (int) $field['maxlength'] ); } $clean[ $key ] = $val; } } // Keep values the current schema doesn't know (e.g. premium settings while premium is inactive). $saved = get_option( self::OPTION, array() ); $clean = array_merge( array_diff_key( is_array( $saved ) ? $saved : array(), self::fields() ), $clean ); return apply_filters( 'tableengine_sanitize_settings', $clean, $input ); } /** * Normalise "12:00-15:00, 18:00 - 22:30" into canonical "12:00-15:00, 18:00-22:30". */ public static function sanitize_ranges( $str ) { $out = array(); foreach ( self::parse_ranges( $str ) as $r ) { $out[] = sprintf( '%02d:%02d-%02d:%02d', intdiv( $r[0], 60 ), $r[0] % 60, intdiv( $r[1] % 1440, 60 ), $r[1] % 60 ); } return implode( ', ', $out ); } /** * Parse ranges into minute pairs. End may exceed 1440 for past-midnight service. * * @return array */ public static function parse_ranges( $str ) { $ranges = array(); foreach ( preg_split( '/[,;\n]+/', (string) $str ) as $part ) { if ( preg_match( '/(\d{1,2})[:.](\d{2})\s*[-–—]\s*(\d{1,2})[:.](\d{2})/', $part, $m ) ) { $s = (int) $m[1] * 60 + (int) $m[2]; $e = (int) $m[3] * 60 + (int) $m[4]; if ( $s >= 1440 || $e > 1440 ) { continue; } if ( $e <= $s ) { $e += 1440; } $ranges[] = array( $s, $e ); } } usort( $ranges, function ( $a, $b ) { return $a[0] - $b[0]; } ); return $ranges; } /** * Settings safe to expose to the public booking widget. */ public static function public_config() { $s = self::all(); $gateway = Payments::active(); $config = array( 'restaurant' => $s['restaurant_name'], 'currency' => $s['currency'], 'timeFormat' => $s['time_format'], 'weekStarts' => (int) $s['week_starts'], 'minParty' => (int) $s['min_party'], 'maxParty' => (int) $s['max_party'], 'largePartyMsg' => $s['large_party_message'], 'maxAdvanceDays' => (int) $s['max_advance_days'], 'tableSelection' => $s['table_selection'], 'closedMessage' => $s['closed_message'], 'mobileView' => $s['mobile_view'], 'desktopView' => $s['desktop_view'], 'breakpoint' => (int) $s['mobile_breakpoint'], 'mapHeight' => (int) $s['map_height'], 'showUnavailable' => (bool) $s['show_unavailable'], 'showSeats' => (bool) $s['show_seats'], 'showChairs' => (bool) $s['show_chairs'], 'showLegend' => (bool) $s['show_legend'], 'autoFit' => (bool) $s['auto_fit'], 'mobileRotate' => (bool) $s['mobile_rotate'], 'colors' => array( 'floor' => $s['color_floor'], 'table' => $s['color_table'], 'available' => $s['color_available'], 'selected' => $s['color_selected'], 'unavailable' => $s['color_unavailable'], ), 'payment' => array_merge( array( 'enabled' => null !== $gateway, 'gateway' => $gateway ? $gateway->id() : '', 'pk' => '', 'type' => $s['deposit_type'], 'amount' => (float) $s['deposit_amount'], 'minParty' => (int) $s['deposit_min_party'], 'label' => $s['deposit_label'], 'note' => $s['deposit_note'], 'layout' => $s['payment_layout'], 'holdMins' => (int) $s['hold_minutes'], 'zeroDecimal' => Payments::is_zero_decimal( $s['currency'] ), ), $gateway ? $gateway->frontend_config() : array() ), 'form' => array( 'phone' => $s['phone_field'], 'notes' => $s['notes_field'], 'occasion' => (bool) $s['occasion_field'], 'occasions' => array_values( array_filter( array_map( 'trim', explode( "\n", $s['occasions'] ) ) ) ), 'notesPlaceholder' => $s['notes_placeholder'], 'termsRequired' => (bool) $s['terms_required'], 'termsText' => $s['terms_text'], 'termsUrl' => $s['terms_url'], 'marketing' => (bool) $s['marketing_optin'], 'marketingText' => $s['marketing_text'], 'honeypot' => (bool) $s['honeypot'], ), 'guests' => array( 'allowCancel' => (bool) $s['allow_cancel'], 'calendarLinks' => (bool) $s['calendar_links'], 'successMsg' => $s['success_message'], 'pendingMsg' => $s['pending_message'], ), 'ui' => array( 'theme' => $s['theme'], 'showHeader' => (bool) $s['show_header'], 'title' => $s['header_title'], 'subtitle' => $s['header_subtitle'], ), ); /** Settings exposed to the booking widget (public: never add secrets). */ return apply_filters( 'tableengine_public_config', $config ); } }