plugin_slug = $plugin_slug; $this->version = $version; $this->option_name = $option_name; if ( is_admin() ) { Color_Defaults_Migration::apply(); } $raw = get_option($this->option_name); // Runtime fallback key. // when the new key is missing (sites that didn't re-activate after rebrand). if ( ! is_array( $raw ) || empty( $raw ) ) { $legacy_key = defined( __NAMESPACE__ . '\\Info::LEGACY_OPTION_NAME' ) ? Info::LEGACY_OPTION_NAME : 'picky_settings_legacy'; if ( $legacy_key && $legacy_key !== $this->option_name ) { $legacy = get_option( $legacy_key ); if ( is_array( $legacy ) && ! empty( $legacy ) ) { $raw = $legacy; } } } $this->settings = is_array($raw) ? wp_parse_args($raw, Info::$DEFAULT_OPTIONS) : Info::$DEFAULT_OPTIONS; $this->settings_group = $this->option_name.'_group'; } /** * Inline help control (native details/summary for keyboard + mobile). * * @param string $uid_suffix Unique fragment for stable id. * @param string $text Plain text; newlines become br. */ private function picky_settings_help_details( $uid_suffix, $text ) { $text = trim( (string) $text ); if ( $text === '' ) { return ''; } $uid = 'picky-help-' . sanitize_html_class( (string) $uid_suffix ); $body = wp_kses( nl2br( esc_html( $text ) ), array( 'br' => array(), ) ); return '
' . '' . '' . '
' . $body . '
' . '
'; } /** * Short URL summary for status panels (host + path, truncated). Never includes credentials. * * @param string $url Full URL. * @return string */ private function picky_integration_url_summary( $url ) { $url = trim( (string) $url ); if ( $url === '' ) { return ''; } $p = wp_parse_url( $url ); if ( ! is_array( $p ) || empty( $p['host'] ) ) { $excerpt = $url; } else { $scheme = isset( $p['scheme'] ) ? (string) $p['scheme'] : ''; $host = (string) $p['host']; $path = isset( $p['path'] ) ? (string) $p['path'] : ''; $excerpt = ( $scheme !== '' ? $scheme . '://' : '' ) . $host . $path; } $max = 72; if ( function_exists( 'mb_strlen' ) && function_exists( 'mb_substr' ) && mb_strlen( $excerpt, 'UTF-8' ) > $max ) { return mb_substr( $excerpt, 0, $max, 'UTF-8' ) . '…'; } if ( strlen( $excerpt ) > $max ) { return substr( $excerpt, 0, $max ) . '…'; } return $excerpt; } /** * Short connection + webhook summary under HubSpot / n8n / Zapier / Make section headings (saved options only). * * @param string $sec_slug Section slug (picky_sec_*). * @param array $settings Plugin options. * @return string Safe HTML or empty. */ private function picky_settings_section_integration_strip( $sec_slug, $settings ) { if ( ! is_array( $settings ) ) { $settings = array(); } $sec_slug = (string) $sec_slug; if ( 'picky_sec_hubspot' === $sec_slug ) { $hs_on = isset( $settings['hubspot_enabled'] ) && (string) $settings['hubspot_enabled'] === '1'; $hs_tok = isset( $settings['hubspot_access_token'] ) ? trim( (string) $settings['hubspot_access_token'] ) : ''; if ( ! $hs_on ) { $state = 'disabled'; $conn = __( 'Disabled', 'pickybooking' ); } elseif ( $hs_tok === '' ) { $state = 'incomplete'; $conn = __( 'Incomplete — add access token below', 'pickybooking' ); } else { $state = 'ready'; $conn = __( 'Ready — token saved', 'pickybooking' ); } $hook_val = '' . esc_html__( 'Not used (outbound REST to HubSpot only).', 'pickybooking' ) . ''; } elseif ( 'picky_sec_mailchimp' === $sec_slug ) { $mc_on = isset( $settings['mailchimp_enabled'] ) && (string) $settings['mailchimp_enabled'] === '1'; $mc_key = isset( $settings['mailchimp_api_key'] ) ? trim( (string) $settings['mailchimp_api_key'] ) : ''; $mc_list = isset( $settings['mailchimp_list_id'] ) ? trim( (string) $settings['mailchimp_list_id'] ) : ''; if ( ! $mc_on ) { $state = 'disabled'; $conn = __( 'Disabled', 'pickybooking' ); } elseif ( $mc_key === '' || $mc_list === '' ) { $state = 'incomplete'; $conn = __( 'Incomplete — add API key and Audience ID below', 'pickybooking' ); } else { $state = 'ready'; /* translators: Shown when API key and Audience ID are stored; does not mean Mailchimp already accepted a request. */ $conn = __( 'Credentials saved — use Test Connection to verify with Mailchimp', 'pickybooking' ); } $hook_val = '' . esc_html__( 'Not used (outbound REST to Mailchimp only).', 'pickybooking' ) . ''; } elseif ( 'picky_sec_n8n' === $sec_slug ) { $on = isset( $settings['n8n_webhook_enabled'] ) && (string) $settings['n8n_webhook_enabled'] === '1'; $url = isset( $settings['n8n_webhook_url'] ) ? trim( (string) $settings['n8n_webhook_url'] ) : ''; if ( ! $on ) { $state = 'disabled'; $conn = __( 'Webhook disabled', 'pickybooking' ); } elseif ( $url === '' ) { $state = 'incomplete'; $conn = __( 'Incomplete — add webhook URL below', 'pickybooking' ); } else { $state = 'ready'; $conn = __( 'Ready to POST after each booking', 'pickybooking' ); } $hook_val = $url !== '' ? '' . esc_html( $this->picky_integration_url_summary( $url ) ) . '' : '' . esc_html__( '—', 'pickybooking' ) . ''; } elseif ( 'picky_sec_zapier' === $sec_slug ) { $on = isset( $settings['zapier_webhook_enabled'] ) && (string) $settings['zapier_webhook_enabled'] === '1'; $url = isset( $settings['zapier_webhook_url'] ) ? trim( (string) $settings['zapier_webhook_url'] ) : ''; if ( ! $on ) { $state = 'disabled'; $conn = __( 'Webhook disabled', 'pickybooking' ); } elseif ( $url === '' ) { $state = 'incomplete'; $conn = __( 'Incomplete — add Catch Hook URL below', 'pickybooking' ); } else { $state = 'ready'; $conn = __( 'Ready to POST after each booking', 'pickybooking' ); } $hook_val = $url !== '' ? '' . esc_html( $this->picky_integration_url_summary( $url ) ) . '' : '' . esc_html__( '—', 'pickybooking' ) . ''; } elseif ( 'picky_sec_make' === $sec_slug ) { $on = isset( $settings['make_webhook_enabled'] ) && (string) $settings['make_webhook_enabled'] === '1'; $url = isset( $settings['make_webhook_url'] ) ? trim( (string) $settings['make_webhook_url'] ) : ''; if ( ! $on ) { $state = 'disabled'; $conn = __( 'Webhook disabled', 'pickybooking' ); } elseif ( $url === '' ) { $state = 'incomplete'; $conn = __( 'Incomplete — add Custom webhook URL below', 'pickybooking' ); } else { $state = 'ready'; $conn = __( 'Ready to POST after each booking', 'pickybooking' ); } $hook_val = $url !== '' ? '' . esc_html( $this->picky_integration_url_summary( $url ) ) . '' : '' . esc_html__( '—', 'pickybooking' ) . ''; } elseif ( 'picky_sec_gcal' === $sec_slug ) { $on = isset( $settings['gcal_enabled'] ) && (string) $settings['gcal_enabled'] === '1'; $json = isset( $settings['gcal_service_account_json'] ) ? trim( (string) $settings['gcal_service_account_json'] ) : ''; $cal = isset( $settings['gcal_calendar_id'] ) ? trim( (string) $settings['gcal_calendar_id'] ) : ''; if ( ! $on ) { $state = 'disabled'; $conn = __( 'Sync disabled', 'pickybooking' ); } elseif ( $json === '' ) { $state = 'incomplete'; $conn = __( 'Incomplete — add Service Account JSON key', 'pickybooking' ); } elseif ( $cal === '' ) { $state = 'incomplete'; $conn = __( 'Incomplete — add Calendar ID', 'pickybooking' ); } else { $state = 'ready'; $conn = __( 'Ready to sync to Google Calendar', 'pickybooking' ); } $k_conn = esc_html__( 'Connection', 'pickybooking' ); $k_cal = esc_html__( 'Calendar', 'pickybooking' ); $cal_span = $cal !== '' ? '' . esc_html( $cal === 'primary' ? __( 'Primary calendar', 'pickybooking' ) : $cal ) . '' : '' . esc_html__( '—', 'pickybooking' ) . ''; return '

' . '' . $k_conn . ' ' . '' . esc_html( $conn ) . '' . '' . '' . $k_cal . ' ' . $cal_span . '

'; } else { return ''; } $k_conn = esc_html__( 'Connection', 'pickybooking' ); $k_hook = esc_html__( 'Webhook URL', 'pickybooking' ); return '

' . '' . $k_conn . ' ' . '' . esc_html( $conn ) . '' . '' . '' . $k_hook . ' ' . $hook_val . '

'; } /** * Optional brand icon beside integration section titles (`assets/img/brands/{slug}.svg`). * * @param string $brand Alphanumeric key (hubspot, mailchimp, …). * @param int $size Image width/height in pixels. * @return string Safe HTML or empty. */ private function picky_settings_section_brand_img_tag( $brand, $size = 28 ) { $brand = preg_replace( '/[^a-z0-9_-]/', '', strtolower( (string) $brand ) ); $size = max( 16, (int) $size ); if ( $brand === '' ) { return ''; } $basename = 'assets/img/brands/' . $brand . '.svg'; $abs = dirname( __DIR__ ) . '/' . $basename; if ( ! is_readable( $abs ) ) { return ''; } $url = plugins_url( $basename, dirname( __DIR__ ) . '/' . Info::MAIN_FILE ); return '' . '' . ''; } /** * Connection badge for an Integrations card (Off / Setup / Ready). * * @param string $sec_slug Section slug. * @param array $settings Plugin options. * @return array{0:string,1:string} State key and label. */ private function picky_integration_status( $sec_slug, $settings ) { if ( ! is_array( $settings ) ) { $settings = array(); } $on = static function ( $key ) use ( $settings ) { return isset( $settings[ $key ] ) && (string) $settings[ $key ] === '1'; }; $val = static function ( $key ) use ( $settings ) { return isset( $settings[ $key ] ) ? trim( (string) $settings[ $key ] ) : ''; }; if ( 'picky_sec_ai' === $sec_slug ) { if ( ! $on( 'ai_enabled' ) ) { return array( 'disabled', __( 'Off', 'pickybooking' ) ); } if ( $val( 'ai_groq_key' ) === '' && $val( 'ai_openai_key' ) === '' ) { return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } return array( 'ready', __( 'Ready', 'pickybooking' ) ); } if ( 'picky_sec_hubspot' === $sec_slug ) { if ( ! $on( 'hubspot_enabled' ) ) { return array( 'disabled', __( 'Off', 'pickybooking' ) ); } if ( $val( 'hubspot_access_token' ) === '' ) { return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } return array( 'ready', __( 'Ready', 'pickybooking' ) ); } if ( 'picky_sec_mailchimp' === $sec_slug ) { if ( ! $on( 'mailchimp_enabled' ) ) { return array( 'disabled', __( 'Off', 'pickybooking' ) ); } if ( $val( 'mailchimp_api_key' ) === '' || $val( 'mailchimp_list_id' ) === '' ) { return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } return array( 'ready', __( 'Ready', 'pickybooking' ) ); } if ( 'picky_sec_n8n' === $sec_slug ) { if ( ! $on( 'n8n_webhook_enabled' ) ) { return array( 'disabled', __( 'Off', 'pickybooking' ) ); } if ( $val( 'n8n_webhook_url' ) === '' ) { return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } return array( 'ready', __( 'Ready', 'pickybooking' ) ); } if ( 'picky_sec_zapier' === $sec_slug ) { if ( ! $on( 'zapier_webhook_enabled' ) ) { return array( 'disabled', __( 'Off', 'pickybooking' ) ); } if ( $val( 'zapier_webhook_url' ) === '' ) { return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } return array( 'ready', __( 'Ready', 'pickybooking' ) ); } if ( 'picky_sec_make' === $sec_slug ) { if ( ! $on( 'make_webhook_enabled' ) ) { return array( 'disabled', __( 'Off', 'pickybooking' ) ); } if ( $val( 'make_webhook_url' ) === '' ) { return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } return array( 'ready', __( 'Ready', 'pickybooking' ) ); } if ( 'picky_sec_gcal' === $sec_slug ) { if ( ! $on( 'gcal_enabled' ) ) { return array( 'disabled', __( 'Off', 'pickybooking' ) ); } if ( $val( 'gcal_service_account_json' ) === '' || $val( 'gcal_calendar_id' ) === '' ) { return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } return array( 'ready', __( 'Ready', 'pickybooking' ) ); } if ( 'picky_sec_pay_collect' === $sec_slug ) { if ( ! $on( 'deposit_enabled' ) ) { return array( 'disabled', __( 'Off', 'pickybooking' ) ); } return array( 'ready', __( 'On', 'pickybooking' ) ); } if ( 'picky_sec_pay_method' === $sec_slug ) { $p = $val( 'payment_provider' ); if ( $p === '' || $p === 'none' ) { return array( 'disabled', __( 'Free', 'pickybooking' ) ); } if ( $p === 'stripe' ) { return array( 'ready', __( 'Stripe', 'pickybooking' ) ); } if ( $p === 'woocommerce' ) { return array( 'ready', __( 'Woo', 'pickybooking' ) ); } return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } if ( 'picky_sec_pay_stripe' === $sec_slug ) { $pk = $val( 'stripe_publishable_key' ); $sk = $val( 'stripe_secret_key' ); if ( $val( 'payment_provider' ) !== 'stripe' ) { return array( 'disabled', __( 'Idle', 'pickybooking' ) ); } if ( $pk === '' || $sk === '' ) { return array( 'incomplete', __( 'Setup', 'pickybooking' ) ); } return array( 'ready', __( 'Ready', 'pickybooking' ) ); } if ( 'picky_sec_pay_paypal' === $sec_slug ) { return array( 'disabled', __( 'Soon', 'pickybooking' ) ); } return array( 'disabled', __( 'Off', 'pickybooking' ) ); } /** * Open an Integrations gallery card (Layouts-style preview + configure drawer). * * @param array $field Section field. * @param array $settings Plugin options. * @param array $section_help Short blurbs. * @return string */ private function picky_integration_card_open_html( $field, $settings, $section_help ) { $sec_slug = isset( $field['slug'] ) ? (string) $field['slug'] : ''; $brand = isset( $field['brand'] ) ? (string) $field['brand'] : ''; $title = isset( $field['title'] ) ? (string) $field['title'] : ''; $desc = ''; if ( isset( $section_help[ $sec_slug ] ) && $section_help[ $sec_slug ] !== '' ) { $desc = (string) $section_help[ $sec_slug ]; } elseif ( ! empty( $field['description'] ) ) { $desc = wp_strip_all_tags( (string) $field['description'] ); if ( function_exists( 'mb_substr' ) && mb_strlen( $desc ) > 140 ) { $desc = rtrim( mb_substr( $desc, 0, 137 ) ) . '…'; } elseif ( strlen( $desc ) > 140 ) { $desc = rtrim( substr( $desc, 0, 137 ) ) . '…'; } } list( $state, $badge ) = $this->picky_integration_status( $sec_slug, $settings ); $brand_key = preg_replace( '/[^a-z0-9_-]/', '', strtolower( $brand ) ); $brand_cls = $brand_key !== '' ? ' picky-int-card--' . $brand_key : ''; $logo = $brand !== '' ? $this->picky_settings_section_brand_img_tag( $brand, 56 ) : ''; if ( $logo === '' ) { $fallback = ''; if ( $sec_slug === 'picky_sec_ai' ) { $fallback = 'AI'; } elseif ( $sec_slug === 'picky_sec_pay_collect' ) { $fallback = '$'; } elseif ( $sec_slug === 'picky_sec_pay_method' ) { $fallback = 'Pay'; } if ( $fallback !== '' ) { $logo = ''; } } $html = '
'; $html .= '
'; $html .= $logo; $html .= '' . esc_html( $badge ) . ''; $html .= '
'; $html .= '
'; if ( $title !== '' ) { $html .= '

' . esc_html( $title ) . '

'; } if ( $desc !== '' ) { $html .= '

' . esc_html( $desc ) . '

'; } $html .= $this->picky_settings_section_integration_strip( $sec_slug, $settings ); $html .= '
'; $html .= '' . esc_html__( 'Configure', 'pickybooking' ) . ''; $html .= '
'; return $html; } /** * Long tooltips and short visible hints keyed by field slug / section slug / radio index / checkbox item slug. * * @param string $item_label Singular reservable label. * @param string $items_label Plural reservable label. * @return array{section:array,slug:array,radio:array>,checkbox_item:array,hints:array} */ private function picky_get_settings_help_pack( $item_label, $items_label ) { return array( 'section' => array( 'picky_sec_main_labels' => __( 'Set how your bookable thing is named everywhere in the plugin, and how far into the future the calendar opens.', 'pickybooking' ), 'picky_sec_main_capacity' => __( 'Control headcount and which parts of the form and map visitors see. Capacity mode needs party size when items share one area.', 'pickybooking' ), 'picky_sec_main_ux' => __( 'Choose the step order on the frontend, how phones behave, and how the widget sits in the page.', 'pickybooking' ), 'picky_sec_payments' => __( 'Turn on paid bookings and pick Stripe Checkout or WooCommerce. Keys here are only for direct Stripe; Woo uses its own store gateways.', 'pickybooking' ), 'picky_sec_pay_collect' => __( 'When this is on, the slot is held only after the guest pays. Choose a fixed amount, services total, or both.', 'pickybooking' ), 'picky_sec_pay_method' => __( 'None skips checkout. Stripe uses the keys in the Stripe card. WooCommerce sends guests to your shop checkout.', 'pickybooking' ), 'picky_sec_pay_stripe' => __( 'Used only when the provider is Stripe Checkout (direct). WooCommerce Stripe plugins do not use these keys.', 'pickybooking' ), 'picky_sec_pay_paypal' => __( 'Reserved for a future PayPal flow. These fields are unused until that integration ships.', 'pickybooking' ), 'picky_sec_schedule' => __( 'Bookings are only accepted inside the green windows you enable. Use the second window for split shifts.', 'pickybooking' ), 'picky_sec_form_copy' => __( 'Copy shown on the public form and where admin / customer emails go.', 'pickybooking' ), 'picky_sec_sms' => __( 'Optional SMS to your staff phone via Vonage. Test credentials in dashboard first; failed SMS shows a settings notice.', 'pickybooking' ), 'picky_sec_layout_colors' => __( 'Public shortcode appearance only. Does not change colors inside the admin layout builder.', 'pickybooking' ), 'picky_sec_integrations' => __( 'Optional connections to HubSpot, Mailchimp, n8n, Zapier, and Make. Each section includes a short status line and a test where available.', 'pickybooking' ), 'picky_sec_hubspot' => __( 'Send all successful bookings to HubSpot CRM. Adds them as contacts and optionally creates a deal.', 'pickybooking' ), 'picky_sec_mailchimp' => __( 'Send all successful bookings to a Mailchimp Audience. Adds or updates them as subscribers.', 'pickybooking' ), 'picky_sec_n8n' => __( 'Ping an n8n webhook URL with booking data when a reservation is placed.', 'pickybooking' ), 'picky_sec_zapier' => __( 'Ping a Zapier Catch Hook URL with booking data when a reservation is placed.', 'pickybooking' ), 'picky_sec_make' => __( 'Ping a Make.com Custom Webhook URL with booking data when a reservation is placed.', 'pickybooking' ), 'picky_sec_gcal' => __( 'Create events in Google Calendar for each booking using a Service Account.', 'pickybooking' ), ), 'slug' => array( 'reservable_item_name' => __( 'Shown in admin lists, emails, and payment line items. Use Title Case in your language (e.g. “Room”, “Court”).', 'pickybooking' ), 'reservable_items_name' => __( 'Plural form for menus and headings. Leave empty to auto-append “s” to the singular name.', 'pickybooking' ), 'days_ahead' => __( 'Rolling horizon: today + this many days is the last selectable date. Lower for tight inventory; higher for long-term planning.', 'pickybooking' ), 'table_booked_time' => __( 'When the guest does not pick an end time, this is how long the slot lasts. It is also the default span used when checking conflicts.', 'pickybooking' ), 'table_before_booked_time' => __( 'Adds empty time before an existing booking starts so staff can reset the room. Zero means no extra padding.', 'pickybooking' ), 'shop_people_amount' => sprintf( /* translators: %s: singular item */ __( 'Shows a “people” field on the form. Required for capacity mode so the plugin knows how many guests share one %s.', 'pickybooking' ), $item_label ), 'picky_group_display_options' => __( 'Controls which fields appear on the public booking form and which numbers appear on the floor plan. Email must be on if you send confirmations.', 'pickybooking' ), 'mobile_table_select' => sprintf( /* translators: 1: singular item, 2: plural items */ __( 'Small screens (under 768px): choose whether guests pick a specific %1$s on the map, use a list, or skip map selection. Test on a real phone. Applies to %2$s choice, not other fields.', 'pickybooking' ), $item_label, $items_label ), 'booking_mode' => sprintf( /* translators: %s: plural items */ __( 'Exclusive = one party blocks the whole %s for the time range. Capacity = many parties until “max persons” is reached.', 'pickybooking' ), $items_label ), 'shortcode_layout' => sprintf( /* translators: %s: plural items */ __( 'Site-wide default for the order of booking steps. Each layout can override this under “Wizard flow on the public site” in the layout editor. Classic suits “pick %s first”; Smart suits “pick date/time first”; Simple hides map picking.', 'pickybooking' ), $items_label ), 'container_align' => __( 'CSS alignment of the shortcode wrapper: useful inside full-width themes where you want the widget centered.', 'pickybooking' ), 'deposit_enabled' => __( 'When on, the booking is not final until payment succeeds. Failed payment frees the slot again. The amount comes from "Payment amount source" below.', 'pickybooking' ), 'deposit_amount' => __( 'Used when "Payment amount source" is Fixed amount (or as a fallback). Use the same currency as your Stripe account or WooCommerce store.', 'pickybooking' ), 'deposit_currency' => __( 'ISO 4217 code. Mismatched currency vs Stripe/Woo will cause declines or wrong totals.', 'pickybooking' ), 'payment_amount_source' => __( 'Where to read the charge amount from: a fixed value, the sum of selected services, or both with services taking priority.', 'pickybooking' ), 'payment_provider' => __( 'None = free booking only. Direct Stripe uses the keys below. WooCommerce creates an order and uses whatever gateways you enabled in Woo.', 'pickybooking' ), 'stripe_publishable_key' => __( 'Public key safe for browsers. Only needed for Direct Stripe mode (not for Woo’s own Stripe gateway).', 'pickybooking' ), 'stripe_secret_key' => __( 'Secret key — never share. Store stays in wp_options; restrict admin users. Rotate if leaked.', 'pickybooking' ), 'paypal_client_id' => __( 'Reserved for a future PayPal flow; currently unused by the booking payment logic.', 'pickybooking' ), 'paypal_client_secret' => __( 'Reserved for future PayPal integration.', 'pickybooking' ), 'hubspot_enabled' => __( 'Requires email or phone on the booking form so HubSpot can match or create a contact.', 'pickybooking' ), 'hubspot_access_token' => __( 'HubSpot private apps live under Development → Legacy apps (or a project on the new developer platform). The access token works like an API key—rotate it in HubSpot if compromised.', 'pickybooking' ), 'hubspot_sync_deals' => __( 'When on, each booking also creates a HubSpot deal linked to the contact, with reservation details in the deal description.', 'pickybooking' ), 'hubspot_deal_pipeline_id' => __( 'Optional. Paste your pipeline internal ID from HubSpot (Settings → Objects → Deals → Pipelines). Leave blank with stage blank to auto-pick the first pipeline and first stage.', 'pickybooking' ), 'hubspot_deal_stage_id' => __( 'Optional. Stage internal ID in that pipeline. Must be set together with pipeline ID, or leave both blank for auto-detection.', 'pickybooking' ), 'n8n_webhook_enabled' => __( 'Sends a JSON POST to your n8n Webhook node URL after each successful booking. Failures are logged on the booking and do not block the guest. Use Zapier or Make below for those platforms.', 'pickybooking' ), 'n8n_webhook_url' => __( 'Production webhook URL from n8n (HTTPS recommended). Payload: event pickybooking.booking_created plus guest, reservation, payment, HubSpot IDs if synced.', 'pickybooking' ), 'n8n_webhook_secret' => __( 'Optional shared secret: HMAC-SHA256 of the raw JSON body is sent as header X-Picky-N8N-Signature (prefix sha256=). Verify in n8n to reject forged requests.', 'pickybooking' ), 'zapier_webhook_enabled' => __( 'Sends the same JSON payload as n8n to your Zapier “Webhooks by Zapier” Catch Hook URL after each successful booking. Runs after the n8n webhook when both are on.', 'pickybooking' ), 'zapier_webhook_url' => __( 'Paste the HTTPS URL from Zapier’s Catch Hook trigger. Payload matches the n8n webhook (event pickybooking.booking_created).', 'pickybooking' ), 'zapier_webhook_secret' => __( 'Optional: HMAC-SHA256 of the raw JSON body is sent as X-Picky-ZAPIER-Signature: sha256=… for verification in a Zap Code step.', 'pickybooking' ), 'make_webhook_enabled' => __( 'Sends the same JSON payload as n8n to your Make.com Custom webhook URL after each successful booking. Runs after the Zapier webhook when both are on.', 'pickybooking' ), 'make_webhook_url' => __( 'From Make: add a Webhooks module → Custom webhook, run once to get the URL, then paste it here (HTTPS). Payload: event pickybooking.booking_created.', 'pickybooking' ), 'make_webhook_secret' => __( 'Optional: HMAC-SHA256 of the raw JSON body is sent as X-Picky-MAKE-Signature: sha256=… Verify in Make (e.g. HTTP tools or a filter) if you need request authentication.', 'pickybooking' ), 'gcal_enabled' => __( 'Creates a Google Calendar event for each booking. Requires a Google Cloud Service Account with Calendar API access.', 'pickybooking' ), 'gcal_service_account_json' => __( 'Service Account JSON key from Google Cloud Console. Grants server-to-server access without OAuth user consent.', 'pickybooking' ), 'gcal_calendar_id' => __( 'Target calendar ID. Use "primary" for the main calendar, or the specific calendar ID found in calendar settings.', 'pickybooking' ), 'gcal_add_attendees' => __( 'Adds the customer email as an attendee so they receive a calendar invitation.', 'pickybooking' ), 'work_days' => __( 'Turn a weekday on, set open/close, optionally add a second interval. Disabled days never show slots.', 'pickybooking' ), 'form_message' => __( 'Short reassurance under the main button (e.g. “We reply within 15 minutes”). Keep it one line if possible.', 'pickybooking' ), 'picky_group_form_email_flags' => __( 'Consent stores legal text you provide. Customer email requires the email field to be visible and filled.', 'pickybooking' ), 'form_confirm_text' => __( 'HTML snippet next to the checkbox (links allowed). Shown only when consent is enabled.', 'pickybooking' ), 'form_thx' => __( 'Shown after a successful unpaid booking or after payment redirect success. Leave empty for the built-in message.', 'pickybooking' ), 'form_email' => __( 'Where admin copies of bookings go. Must be a valid address; falls back to the site admin email if empty.', 'pickybooking' ), 'send_sms' => __( 'Sends one SMS per booking to the phone below using Vonage REST. Costs money per message—disable when not needed.', 'pickybooking' ), 'sms_key' => __( 'Vonage “API key” from the dashboard. Together with the secret it authorizes balance checks on save.', 'pickybooking' ), 'sms_secret' => __( 'Vonage “API secret”. Treat like a password.', 'pickybooking' ), 'sms_phone' => __( 'Destination in E.164 (+countrycode…). This is usually your staff phone, not the guest’s.', 'pickybooking' ), 'color_main' => sprintf( /* translators: %s: plural bookable items (e.g. Tables, Seats) */ __( 'Public shortcode only: outer booking wrapper, calendar column tint, %s shapes on the map, seat chips, capacity badge, and ID labels. Does not change the map background image (set per layout in the builder).', 'pickybooking' ), $items_label ), 'color_datepicker' => __( 'Public shortcode only: jQuery UI datepicker cells, text, and month arrows for the booking calendar.', 'pickybooking' ), 'color_form' => __( 'Public shortcode only: submit button, form typography, inputs inside the widget, notices, and secondary step panels (see each label for exact scope).', 'pickybooking' ), ), 'radio' => array( 'mobile_table_select' => array( 0 => sprintf( /* translators: %s: singular item */ __( 'Fastest on small screens if you assign %s manually or run first-come-first-served without map picking.', 'pickybooking' ), $item_label ), 1 => sprintf( /* translators: %s: singular item */ __( 'Best when the map is simple; guests tap the exact %s. Can feel cramped on very small phones.', 'pickybooking' ), $item_label ), 2 => sprintf( /* translators: %s: plural items */ __( 'Good for many %s: scrollable list, still respects availability when the plugin can compute it.', 'pickybooking' ), $items_label ), ), 'booking_mode' => array( 0 => __( 'Use for rooms, courts, equipment—anything that cannot be shared by strangers at the same time.', 'pickybooking' ), 1 => sprintf( /* translators: %s: plural items */ __( 'Use for coworking-style %s: turn on party size and set “max persons” on each element in the layout editor.', 'pickybooking' ), $items_label ), ), 'shortcode_layout' => array( 0 => sprintf( /* translators: %s: singular item */ __( 'Guest chooses %s first, then date/time in the modal—closest to classic restaurant booking.', 'pickybooking' ), $item_label ), 1 => sprintf( /* translators: %s: plural items */ __( 'Guest filters by date/time first, then sees only free %s—reduces hunting on busy days.', 'pickybooking' ), $items_label ), 2 => sprintf( /* translators: %s: plural items */ __( 'Map is visible immediately; guest picks date/time in a compact bottom bar and free %s update live on the layout.', 'pickybooking' ), $items_label ), 3 => sprintf( /* translators: %s: singular item */ __( 'Guest never picks a %s on the map; plugin assigns the first free slot. Good for events or uniform seats.', 'pickybooking' ), $item_label ), ), 'payment_provider' => array( 0 => __( 'Bookings are stored without taking card data through PickyBooking.', 'pickybooking' ), 1 => __( 'Redirects to Stripe-hosted Checkout; you maintain Stripe keys in these two fields only.', 'pickybooking' ), 2 => __( 'Creates a WooCommerce pending order with a fee line; customer pays with any gateway you configured in Woo (Stripe, PayPal, etc.).', 'pickybooking' ), ), ), 'checkbox_item' => array( 'show_email' => __( 'Turn off if you only take phone bookings or want fewer GDPR fields. Required for “email confirmation to guest”.', 'pickybooking' ), 'show_phone' => __( 'Turn off if you do not collect a guest phone on the public form (e.g. email-only or walk-in follow-up). Admin can still add a phone when editing a reservation.', 'pickybooking' ), 'show_people' => sprintf( /* translators: %s: singular item */ __( 'Shows the capacity number painted on each %s in the map. Helps guests pick the right size.', 'pickybooking' ), $item_label ), 'show_seats' => __( 'Shows the center capacity / seat count badge on each bookable item on the map (independent of “max persons”). Turn off for a cleaner floor plan. Each layout can override this under “Center seat/capacity badge on the public site” in the layout editor.', 'pickybooking' ), 'show_id_badge' => __( 'Shows the ID badge (for example, table number) on map items. Turn off for a cleaner map. Each layout can override this under “ID badge on the public site” in the layout editor.', 'pickybooking' ), 'show_element_label' => __( 'Shows the custom label text on map items. Turn off to hide labels globally. Each layout can override this under “Element label on the public site” in the layout editor.', 'pickybooking' ), 'show_time_to' => __( 'Shows an end-time field so guests can shorten or lengthen the default slot where your layout supports intervals.', 'pickybooking' ), 'animate_bookable_items' => __( 'Plays a short staggered “pop in” when the floor plan loads and a gentle scale on hover/selection for bookable items. Turn off for a static map (also respects the guest’s “reduce motion” preference).', 'pickybooking' ), 'form_confirm' => __( 'Adds a mandatory checkbox—pair it with the consent text area below. Common for EU privacy compliance.', 'pickybooking' ), 'send_customer_email' => __( 'Uses WordPress mail (wp_mail). For deliverability add SMTP plugin; requires email field on and filled.', 'pickybooking' ), ), 'hints' => array( 'deposit_currency' => __( 'Example: EUR for a European Stripe account.', 'pickybooking' ), 'days_ahead' => __( 'Tip: include your busiest booking horizon only—very large values slow down calendar generation.', 'pickybooking' ), 'deposit_amount' => __( 'Use the same major-unit amount your gateway expects (e.g. 25.00, not cents, unless your store is configured otherwise).', 'pickybooking' ), 'deposit_enabled' => __( 'Guests who abandon payment do not keep a confirmed booking; the time slot is released.', 'pickybooking' ), 'payment_amount_source' => __( 'Choose Selected services total when each bookable item exposes priced services and the customer’s total should equal the sum of what they picked.', 'pickybooking' ), 'shop_people_amount' => __( 'In capacity mode this field is required so the plugin can subtract the right headcount from each item.', 'pickybooking' ), 'animate_bookable_items' => __( 'Entrance and hover motion only — availability colors and selection still work when this is off.', 'pickybooking' ), 'picky_group_display_options' => __( 'Toggle email and phone on the public form, map visibility elements (“max persons”, center badge, ID badge, label), and the optional end-time field. If you hide email, turn off “email confirmation to guest” below.', 'pickybooking' ), 'picky_group_form_email_flags' => __( 'Consent text supports basic HTML; test the form once after changing these toggles.', 'pickybooking' ), ), ); } private function custom_settings_fields( $field_args, $settings ) { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only admin GET for UI $output = ''; $output_return = ''; $output_tab = ''; $output_tab_1 = ''; $output_tab_2 = ''; $output_tab_3 = ''; $output_tab_4 = ''; $output_tab_5 = ''; $output_tab_6 = ''; $output_tab_1_fake = ''; $output_tab_2_fake = ''; $output_tab_3_fake = ''; $output_tab_4_fake = ''; $output_tab_5_fake = ''; $output_tab_6_fake = ''; $output_tab_12_fake = ''; $tab = ""; $output_all = ""; $option_name = INFO::OPTION_NAME; $default_options = INFO::$DEFAULT_OPTIONS; if ( ! is_array( $settings ) ) { $settings = array(); } $item_label = $this->picky_item_label(); $items_label = $this->picky_items_label(); $help_pack = $this->picky_get_settings_help_pack( $item_label, $items_label ); $slug_help = isset( $help_pack['slug'] ) && is_array( $help_pack['slug'] ) ? $help_pack['slug'] : array(); $radio_help = isset( $help_pack['radio'] ) && is_array( $help_pack['radio'] ) ? $help_pack['radio'] : array(); $cb_item_help = isset( $help_pack['checkbox_item'] ) && is_array( $help_pack['checkbox_item'] ) ? $help_pack['checkbox_item'] : array(); $field_hints = isset( $help_pack['hints'] ) && is_array( $help_pack['hints'] ) ? $help_pack['hints'] : array(); $section_help = isset( $help_pack['section'] ) && is_array( $help_pack['section'] ) ? $help_pack['section'] : array(); $picky_int_card_open = false; $picky_int_grid_open = false; $picky_pay_card_open = false; $picky_pay_grid_open = false; foreach ($field_args as $key_field => $field) { // clear output $output = ''; $ftype = isset( $field['type'] ) ? (string) $field['type'] : ''; if ( 'settings_section' === $ftype ) { $tab = ''; if ( isset( $field['tab'] ) && $field['tab'] !== '' ) { $tab = (string) $field['tab']; } $sec_slug = isset( $field['slug'] ) ? (string) $field['slug'] : 'section-' . (string) $key_field; $section_classes = 'picky-settings-section'; if ( 'picky_sec_layout_colors' === $sec_slug ) { $section_classes .= ' picky-settings-section--layout-colors-intro'; } if ( $tab === '12' ) { if ( $sec_slug === 'picky_sec_integrations' ) { $section_classes .= ' picky-settings-section--integrations-header picky-int-intro'; } } if ( $tab === '5' && $sec_slug === 'picky_sec_payments' ) { $section_classes .= ' picky-int-intro picky-pay-intro'; } if ( $tab === '12' && $sec_slug !== 'picky_sec_integrations' ) { if ( $picky_int_card_open ) { $output_tab_12_fake .= '
'; $picky_int_card_open = false; } if ( ! $picky_int_grid_open ) { $output_tab_12_fake .= '
'; $picky_int_grid_open = true; } $output .= $this->picky_integration_card_open_html( $field, $settings, $section_help ); $picky_int_card_open = true; } elseif ( $tab === '5' && $sec_slug !== 'picky_sec_payments' ) { if ( $picky_pay_card_open ) { $output_tab_5_fake .= '
'; $picky_pay_card_open = false; } if ( ! $picky_pay_grid_open ) { $output_tab_5_fake .= '
'; $picky_pay_grid_open = true; } $output .= $this->picky_integration_card_open_html( $field, $settings, $section_help ); $picky_pay_card_open = true; } else { $output .= '
'; $output .= '
'; if ( isset( $field['brand'] ) && (string) $field['brand'] !== '' ) { $output .= $this->picky_settings_section_brand_img_tag( (string) $field['brand'] ); } if ( ! empty( $field['title'] ) ) { $output .= '

' . esc_html( (string) $field['title'] ) . '

'; } $output .= '
'; $sec_desc = ''; if ( ! empty( $field['description'] ) ) { $sec_desc = (string) $field['description']; } elseif ( isset( $section_help[ $sec_slug ] ) && $section_help[ $sec_slug ] !== '' ) { $sec_desc = (string) $section_help[ $sec_slug ]; } if ( $sec_desc !== '' ) { $output .= '

' . wp_kses_post( $sec_desc ) . '

'; } $output .= $this->picky_settings_section_integration_strip( $sec_slug, $settings ); $output .= '
'; if ( $tab === '12' && $sec_slug === 'picky_sec_integrations' ) { $output .= '
'; $picky_int_grid_open = true; } if ( $tab === '5' && $sec_slug === 'picky_sec_payments' ) { $output .= '
'; $picky_pay_grid_open = true; } } if ( $tab === '1' ) { $output_tab_1_fake .= $output; } elseif ( $tab === '2' ) { $output_tab_2_fake .= $output; } elseif ( $tab === '3' ) { $output_tab_3_fake .= $output; } elseif ( $tab === '4' ) { $output_tab_4_fake .= $output; } elseif ( $tab === '5' ) { $output_tab_5_fake .= $output; } elseif ( $tab === '6' ) { $output_tab_6_fake .= $output; } elseif ( $tab === '12' ) { $output_tab_12_fake .= $output; } elseif ( $tab === '' ) { $output_all .= $output; } continue; } if ( 'integration_test_button' === $ftype ) { $tab = ''; if ( isset( $field['tab'] ) && $field['tab'] !== '' ) { $tab = (string) $field['tab']; } $integration_name = isset( $field['slug'] ) ? (string) $field['slug'] : ''; $btn_label = ( isset( $field['button_label'] ) && (string) $field['button_label'] !== '' ) ? esc_html( (string) $field['button_label'] ) : esc_html__( 'Test Connection', 'pickybooking' ); $test_row_class = 'picky-integration-test-row'; if ( $tab !== '12' ) { $test_row_class = 'picky-settings-card ' . $test_row_class; } $output .= '
'; if ( ! empty( $field['description'] ) ) { $output .= '

' . wp_kses_post( (string) $field['description'] ) . '

'; } $output .= ''; $output .= ' '; $output .= '
'; if ( $tab === '1' ) { $output_tab_1_fake .= $output; } elseif ( $tab === '2' ) { $output_tab_2_fake .= $output; } elseif ( $tab === '3' ) { $output_tab_3_fake .= $output; } elseif ( $tab === '4' ) { $output_tab_4_fake .= $output; } elseif ( $tab === '5' ) { $output_tab_5_fake .= $output; } elseif ( $tab === '6' ) { $output_tab_6_fake .= $output; } elseif ( $tab === '12' ) { $output_tab_12_fake .= $output; } elseif ( $tab === '' ) { $output_all .= $output; } continue; } if ( 'ai_form_copy_button' === $ftype ) { // Pro-only UI — omitted entirely in Lite (no locked/disabled AI controls). if ( ! \Picky\Edition::allows( 'ai' ) ) { continue; } $tab = isset( $field['tab'] ) ? (string) $field['tab'] : '6'; $output .= '
'; $output .= '

' . esc_html__( 'Generate form copy with AI', 'pickybooking' ) . '

'; if ( ! empty( $field['description'] ) ) { $output .= '

' . wp_kses_post( (string) $field['description'] ) . '

'; } $output .= '

'; $output .= '

'; $output .= '

'; $output .= '
'; if ( $tab === '6' ) { $output_tab_6_fake .= $output; } elseif ( $tab === '12' ) { $output_tab_12_fake .= $output; } else { $output_all .= $output; } continue; } if ( 'checkbox_group' === $ftype ) { $tab = ''; if ( isset( $field['tab'] ) && $field['tab'] !== '' ) { $tab = (string) $field['tab']; } $slug = isset( $field['slug'] ) ? (string) $field['slug'] : 'checkbox-group-' . (string) $key_field; $output .= '
'; $grp_label = isset( $field['label'] ) ? (string) $field['label'] : ''; $output .= '
'; $output .= '

' . esc_html( $grp_label ) . '

'; $output .= '
'; if ( ! empty( $field['description'] ) ) { $output .= '
' . wp_kses_post( (string) $field['description'] ) . '
'; } if ( isset( $field_hints[ $slug ] ) && $field_hints[ $slug ] !== '' ) { $output .= '

' . esc_html( (string) $field_hints[ $slug ] ) . '

'; } $output .= '
    '; foreach ( (array) ( $field['items'] ?? array() ) as $item ) { $is_slug = isset( $item['slug'] ) ? (string) $item['slug'] : ''; if ( $is_slug === '' ) { continue; } $checkbox_name = $this->option_name . '[' . $is_slug . ']'; $checkbox_value = ''; $has_explicit_checkbox = array_key_exists( $is_slug, $settings ) && $settings[ $is_slug ] !== '' && $settings[ $is_slug ] !== null; if ( $has_explicit_checkbox ) { $checkbox_value = (string) $settings[ $is_slug ]; } elseif ( isset( $default_options[ $is_slug ] ) ) { $checkbox_value = (string) $default_options[ $is_slug ]; } $checked = ( $checkbox_value === '1' ) ? 'checked' : ''; $item_label = isset( $item['label'] ) ? (string) $item['label'] : $is_slug; $ih = isset( $cb_item_help[ $is_slug ] ) ? (string) $cb_item_help[ $is_slug ] : ''; $output .= '
  • '; $output .= '
    '; $output .= ''; if ( $ih !== '' ) { $output .= $this->picky_settings_help_details( $slug . '-item-' . $is_slug . '-' . (string) $key_field, $ih ); } $output .= '
    '; $output .= '
  • '; } $output .= '
'; if ( $tab === '1' ) { $output_tab_1_fake .= $output; } elseif ( $tab === '2' ) { $output_tab_2_fake .= $output; } elseif ( $tab === '3' ) { $output_tab_3_fake .= $output; } elseif ( $tab === '4' ) { $output_tab_4_fake .= $output; } elseif ( $tab === '5' ) { $output_tab_5_fake .= $output; } elseif ( $tab === '6' ) { $output_tab_6_fake .= $output; } elseif ( $tab === '12' ) { $output_tab_12_fake .= $output; } elseif ( $tab === '' ) { $output_all .= $output; } continue; } $slug = $field['slug']; $tab = ''; if ( isset( $field['tab'] ) && $field['tab'] !== '' ) { $tab = (string) $field['tab']; } $setting = $this->option_name . '[' . $slug . ']'; // Labels/after are translated where defined (__( ... , 'pickybooking' )); escape once at output. $label = isset( $field['label'] ) ? $field['label'] : ''; $after = ''; if ( isset( $field['after'] ) && $field['after'] !== '' ) { $after = $field['after']; } $class = ''; if ( $field['type'] === 'colors' ) { $class = 'picky-settings-group--colors'; } elseif ( $field['type'] === 'radio' ) { $class = 'picky-settings-group--radios'; } if ( isset( $field['class'] ) && $field['class'] !== '' ) { $class = trim( $class . ' ' . $field['class'] ); } $field_classes = 'picky-settings-field--' . esc_attr( (string) $slug ) . ' ' . esc_attr( (string) $class ) . ' picky-settings-group'; if ( $tab !== '12' ) { $field_classes .= ' picky-settings-card'; } $output .= '
'; $output .= '
'; $output .= '

'; $output .= '
'; // Checkbox descriptions are rendered beside the control (see checkbox branch). if ( $field['type'] !== 'checkbox' && isset( $field['description'] ) && ! empty( $field['description'] ) ) { $output .= '
' . wp_kses_post( $field['description'] ) . '
'; } if ( isset( $field_hints[ $slug ] ) && $field_hints[ $slug ] !== '' ) { $output .= '

' . esc_html( (string) $field_hints[ $slug ] ) . '

'; } if(!isset($settings[$slug])){ if(isset($default_options[$slug])){ $settings[$slug] = $default_options[$slug]; } } if ($field['type'] === 'text') { // text $output .= '

'; $output .= ''; if($after !== ''){ $output .= ''.esc_html((string)$after).''; } $output .= '

'; } elseif ( $field['type'] === 'password' ) { $output .= '

'; $stored = isset( $settings[ $slug ] ) ? (string) $settings[ $slug ] : ''; $default_ph = __( 'Paste secret token/key', 'pickybooking' ); if ( $slug === 'hubspot_access_token' ) { $default_ph = __( 'Paste HubSpot access token', 'pickybooking' ); } elseif ( $slug === 'mailchimp_api_key' ) { $default_ph = __( 'Marketing API key (Profile → Extras → API keys; not Mobile SDK)', 'pickybooking' ); } elseif ( $slug === 'ai_openai_key' ) { $default_ph = __( 'Paste OpenAI API key (sk-…)', 'pickybooking' ); } elseif ( $slug === 'ai_groq_key' ) { $default_ph = __( 'Paste Groq API key (gsk_…)', 'pickybooking' ); } elseif ( strpos( $slug, 'stripe_secret' ) !== false ) { $default_ph = __( 'Paste Stripe Secret key', 'pickybooking' ); } $ph = $stored !== '' ? __( 'Enter a new key/token to replace the stored one', 'pickybooking' ) : $default_ph; $output .= ''; if ( $stored !== '' ) { $output .= '' . esc_html__( 'A token is already saved (hidden). Leave blank to keep it.', 'pickybooking' ) . ''; } if ( $after !== '' ) { $output .= '' . esc_html( (string) $after ) . ''; } $output .= '

'; } elseif ($field['type'] === 'textarea') { // textarea $output .= '

'; $output .= ''; if($after !== ''){ $output .= ''.esc_html((string)$after).''; } $output .= '

'; } elseif ($field['type'] === 'number') { // number $output .= '

'; $output .= ''; if($after !== ''){ $output .= ''.esc_html((string)$after).''; } $output .= '

'; } elseif ($field['type'] === 'select') { // select $output .= '

'; $output .= ''; if($after !== ''){ $output .= '' . esc_html((string)$after) . ''; } $output .= '

'; } else if($field['type'] === 'radio'){ // radio $output .= '
'; foreach ($field['inputs'] as $key => $input) { $checked = ''; if($settings[$slug] === $input['value']){ $checked = 'checked'; } $rid = esc_attr( (string)$setting . '_' . (string)$key ); $output .= '
'; $output .= ''; $rh = ''; if ( isset( $radio_help[ $slug ] ) && is_array( $radio_help[ $slug ] ) && isset( $radio_help[ $slug ][ (int) $key ] ) ) { $rh = (string) $radio_help[ $slug ][ (int) $key ]; } if ( $rh !== '' ) { $output .= $this->picky_settings_help_details( (string) $slug . '-opt-' . (string) $key . '-' . (string) $key_field, $rh ); } $output .= '
'; } $output .= '
'; } else if($field['type'] === 'image'){ // image $output .= $this->custom_image_uploader_field( $setting, $settings[$slug] ); } else if($field['type'] === 'checkboxes'){ // checkboxes $output .= '
'; foreach ($field['checkboxes'] as $key => $value) { $checkbox_name = $this->option_name.'['.$slug.'_'.$value['name'].']'; $opt_key = $slug . '_' . $value['name']; $checkbox_value = ''; $has_explicit = array_key_exists( $opt_key, $settings ) && $settings[ $opt_key ] !== '' && $settings[ $opt_key ] !== null; if ( $has_explicit ) { $checkbox_value = (string) $settings[ $opt_key ]; } elseif ( isset( $default_options[ $opt_key ] ) ) { $checkbox_value = (string) $default_options[ $opt_key ]; } $checked = ''; if ( $checkbox_value === '1' ) { $checked = 'checked'; } $output .= '
'; $output .= '
'; $output .= ''; $output .= '
'; if(isset($value['selects'])){ foreach ($value['selects'] as $key => $sel) { $checkbox_select_name = $this->option_name.'['.$slug.'_'.$value['name'].'_'.$sel['name'].']'; $checkbox_select_value = ''; if(isset($settings[$slug.'_'.$value['name'].'_'.$sel['name']]) ) { $checkbox_select_value = $settings[$slug.'_'.$value['name'].'_'.$sel['name']]; } else { $checkbox_select_value = $default_options[$slug.'_'.$value['name'].'_'.$sel['name']]; } $output .= ''; } } if(isset($value['selects'])){ $output .= '
'; $checkbox_name_more = $this->option_name.'['.$slug.'_'.$value['name'].'_more]'; $opt_key_more = $slug . '_' . $value['name'] . '_more'; $checkbox_value_more = ''; $has_explicit_more = array_key_exists( $opt_key_more, $settings ) && $settings[ $opt_key_more ] !== '' && $settings[ $opt_key_more ] !== null; if ( $has_explicit_more ) { $checkbox_value_more = (string) $settings[ $opt_key_more ]; } elseif ( isset( $default_options[ $opt_key_more ] ) ) { $checkbox_value_more = (string) $default_options[ $opt_key_more ]; } $checked_more = ''; if ( $checkbox_value_more === '1' ) { $checked_more = 'checked'; } $output .= '
'; $output .= '' . esc_html__( 'Second time window', 'pickybooking' ) . ''; $output .= ''; $output .= ''; $output .= '
'; $output .= '
$sel) { // _more $checkbox_select_name = $this->option_name.'['.$slug.'_'.$value['name'].'_'.$sel['name'].'_more]'; $checkbox_select_value = ''; if(isset($settings[$slug.'_'.$value['name'].'_'.$sel['name'].'_more']) ) { $checkbox_select_value = $settings[$slug.'_'.$value['name'].'_'.$sel['name'].'_more']; } else { $checkbox_select_value = $default_options[$slug.'_'.$value['name'].'_'.$sel['name'].'_more']; } $output .= ''; } $output .= '
'; $output .= '
'; } $output .= '
'; $output .= '' . esc_html__( 'Open', 'pickybooking' ) . ''; $output .= ''; $output .= ''; $output .= '
'; $output .= '
'; } $output .= '
'; } else if($field['type'] === 'checkbox'){ // checkbox $checkbox_name = $this->option_name.'['.$slug.']'; $checkbox_value = ''; $has_explicit_checkbox = array_key_exists( $slug, $settings ) && $settings[ $slug ] !== '' && $settings[ $slug ] !== null; if ( $has_explicit_checkbox ) { $checkbox_value = (string) $settings[ $slug ]; } elseif ( isset( $default_options[ $slug ] ) ) { $checkbox_value = (string) $default_options[ $slug ]; } $checked = ''; if($checkbox_value === "1"){ $checked = 'checked'; } $has_desc = ! empty( $field['description'] ); if ( $has_desc ) { $output .= '
'; $output .= '
' . wp_kses_post( $field['description'] ) . '
'; } $output .= '

'; $output .= ''; $output .= '

'; if ( $has_desc ) { $output .= '
'; } } else if($field['type'] === 'colors'){ // colors $picky_booking_shell_bg_subtle = false; if ( $slug === 'color_main' ) { $shortcode_layout_val = isset( $settings['shortcode_layout'] ) ? (string) $settings['shortcode_layout'] : ''; if ( $shortcode_layout_val === '' && isset( $default_options['shortcode_layout'] ) ) { $shortcode_layout_val = (string) $default_options['shortcode_layout']; } $picky_booking_shell_bg_subtle = ( $shortcode_layout_val !== '2' && $shortcode_layout_val !== '3' && $shortcode_layout_val !== '4' ); } $output .= '
'; foreach ($field['inputs'] as $key => $value) { $color_name = $this->option_name.'['.$slug.'_'.$value['name'].']'; $color_title = $value['title']; $color_value = ''; if(isset($settings[$slug.'_'.$value['name']])){ $color_value = $settings[$slug.'_'.$value['name']]; } else { if(isset($default_options[$slug.'_'.$value['name']])){ $color_value = $default_options[$slug.'_'.$value['name']]; } } $output .= '
'; $output .= '
'; $output .= ''; if ( $slug === 'color_main' && isset( $value['name'] ) && $value['name'] === 'main' && $picky_booking_shell_bg_subtle ) { $output .= $this->picky_settings_help_details( 'color-main-shell-' . (string) $key_field, __( 'With the default wizard (table first or date/time first on the map page), this background is usually covered by the floor plan and booking modal, so changing it has little effect. It matters most for Smart layout and Third layout, where it tints the booking shell and calendar column.', 'pickybooking' ) ); } $output .= '
'; $output .= '
'; $output .= ''; $output .= '
'; $output .= '
'; } $output .= '
'; } // end of choises $output .= '
'; if($tab === "1"){ $output_tab_1_fake .= $output; } else if($tab === "2"){ $output_tab_2_fake .= $output; } else if($tab === "3"){ $output_tab_3_fake .= $output; } else if($tab === "4"){ $output_tab_4_fake .= $output; } else if($tab === "5"){ $output_tab_5_fake .= $output; } else if($tab === "6"){ $output_tab_6_fake .= $output; } else if($tab === "12"){ $output_tab_12_fake .= $output; } else if($tab === ""){ $output_all .= $output; } } // foreach if ( $picky_int_card_open ) { $output_tab_12_fake .= '
'; $picky_int_card_open = false; } if ( $picky_int_grid_open ) { $output_tab_12_fake .= '
'; $picky_int_grid_open = false; } if ( $picky_pay_card_open ) { $output_tab_5_fake .= ''; $picky_pay_card_open = false; } if ( $picky_pay_grid_open ) { $output_tab_5_fake .= ''; $picky_pay_grid_open = false; } if($output_all === ""){ $plugin_title = Info::get_plugin_title(); $output_tab .= '
'; $output_tab .= '
'; $output_tab .= '
'; $output_tab .= '
'; $logo_src = plugins_url( 'assets/img/picky-logo.png', dirname( __DIR__ ) . '/' . Info::MAIN_FILE ); $output_tab .= '
'; $output_tab .= ''; $output_tab .= '' . esc_attr__( 'PickyBooking Logo', 'pickybooking' ) . ''; $output_tab .= ''; /* Collapsed + hover: logo swaps to this expand control (ChatGPT-style). */ $output_tab .= ''; $output_tab .= '' . esc_html( (string) $plugin_title ) . ''; $output_tab .= '
'; $output_tab .= '
'; /* Expanded: collapse control on the right of the header (not an edge tab). */ $output_tab .= ''; $output_tab .= '
'; $active_tab = '13'; $candidate = $this->picky_request_picky_tab_value(); if ( $candidate !== '' ) { // Legacy redirect: Reservations tab (7) was removed in favor of the unified Bookings (orders) tab. if ( $candidate === '7' ) { $candidate = '13'; } $active_tab = $candidate; } $active_tab_state_class = $this->picky_settings_active_tab_class( $active_tab ); $layout_id_req = absint( picky_request_query_value( 'layout_id' ) ); if ( '9' === (string) $active_tab && $layout_id_req > 0 ) { $active_tab_state_class .= ' builder-opened'; } for ( $ti = 1; $ti <= 13; $ti++ ) { $an = 'active_' . $ti; $tn = 'tab_' . $ti; $$an = ''; $$tn = 'display:none;'; } $an = 'active_' . $active_tab; $tn = 'tab_' . $active_tab; $$an = 'active'; $$tn = ''; /* Scrollable nav (logo + rail-edge stay outside so the collapse tab is not clipped). */ $output_tab .= ''; $output_tab .= '
'; $output_tab .= '
'; $output_tab .= $this->picky_render_settings_app_tab_panels(); $output_tab .= '
'; $output_tab .= ''; $output_tab .= '
'; if($output_tab_1_fake !== ""){ $output_tab .= '
'; $output_tab .= $output_tab_1_fake; $output_tab .= '
'; } if($output_tab_2_fake !== ""){ $output_tab .= '
'; $output_tab .= $output_tab_2_fake; $output_tab .= '
'; } if ( $output_tab_3_fake !== '' && \Picky\Edition::allows( 'sms' ) ) { $output_tab .= '
'; $output_tab .= $output_tab_3_fake; $output_tab .= '
'; } if($output_tab_4_fake !== ""){ $output_tab .= '
'; $output_tab .= $output_tab_4_fake; $output_tab .= '
'; } if ( $output_tab_5_fake !== '' && \Picky\Edition::allows( 'payments' ) ) { $output_tab .= '
'; $output_tab .= $output_tab_5_fake; $output_tab .= '
'; } if ( $output_tab_12_fake !== '' && \Picky\Edition::allows( 'integrations' ) ) { $output_tab .= '
'; $output_tab .= $output_tab_12_fake; $output_tab .= '
'; } if($output_tab_6_fake !== ""){ $output_tab .= '
'; $output_tab .= $output_tab_6_fake; $output_tab .= '
'; } $output_tab .= '
'; $output_tab .= ''; $output_tab .= '
'; return $output_tab; } else { return $output_all; } // phpcs:enable WordPress.Security.NonceVerification.Recommended } /** * URL for the Layouts dashboard tab (optional embedded builder when layout_id > 0). * * @param int $layout_id Layout post ID, or 0 for the layouts list only. * @param array $extra Extra query args (e.g. saved, imported). * @return string */ private function picky_layout_dashboard_url( $layout_id = 0, $extra = array() ) { $args = array( 'page' => 'picky_settings', 'picky-tab' => '9', ); if ( (int) $layout_id > 0 ) { $args['layout_id'] = absint( $layout_id ); } if ( is_array( $extra ) ) { foreach ( $extra as $k => $v ) { if ( $v === null || $v === '' ) { continue; } $args[ (string) $k ] = $v; } } return admin_url( add_query_arg( $args, 'admin.php' ) ); } /** * URL for the Bookings dashboard tab (optional embedded order editor when order_id > 0). * * Orders are auto-created from frontend bookings and were previously edited on the native * `post.php?post=N&action=edit` screen, which broke the dashboard SPA flow. Routing every * "Edit order" link through this helper keeps the user inside the dashboard shell. * * @param int $order_id Order post ID, or 0 for the bookings list only. * @param array $extra Extra query args (e.g. saved=1). * @return string */ public function picky_order_dashboard_url( $order_id = 0, $extra = array() ) { $args = array( 'page' => 'picky_settings', 'picky-tab' => '13', ); if ( (int) $order_id > 0 ) { $args['order_id'] = absint( $order_id ); } if ( is_array( $extra ) ) { foreach ( $extra as $k => $v ) { if ( $v === null || $v === '' ) { continue; } $args[ (string) $k ] = $v; } } return admin_url( add_query_arg( $args, 'admin.php' ) ); } /** * Filter `get_edit_post_link` for picky_order: WP's list table (and any other code that asks * for an order's edit URL) gets the dashboard URL so clicks stay inside Settings tab 13 * instead of jumping out to wp-admin/post.php. * * @param string $url URL WP built for the post. * @param int $post_id Post ID being linked. * @param string $context Context ('display'|'raw') — irrelevant here, returned as-is for non-orders. * @return string */ public function picky_order_filter_edit_post_link( $url, $post_id, $context = 'display' ) { if ( ! $post_id ) { return $url; } if ( get_post_type( (int) $post_id ) !== 'picky_order' ) { return $url; } return $this->picky_order_dashboard_url( (int) $post_id ); } /** * Override row actions for picky_order so the "Edit" action and any related admin links * route through the dashboard tab. Kept symmetrical with `picky_layout_row_actions`. */ public function picky_order_row_actions( $actions, $post ) { if ( ! ( $post instanceof \WP_Post ) || $post->post_type !== 'picky_order' ) { return $actions; } $url = $this->picky_order_dashboard_url( (int) $post->ID ); if ( isset( $actions['edit'] ) ) { $actions['edit'] = '' . esc_html__( 'Edit Order', 'pickybooking' ) . ''; } // Drop the inline editor — the embedded order edit screen is the canonical flow now. unset( $actions['inline hide-if-no-js'] ); return $actions; } /** * Compact Bookings list title: "Order #123" (date / items / customer already have columns). * * @param string $title Post title. * @param int $post_id Post ID. * @return string */ public function picky_order_list_title( $title, $post_id = 0 ) { $post_id = absint( $post_id ); if ( $post_id <= 0 || get_post_type( $post_id ) !== 'picky_order' ) { return $title; } if ( ! is_admin() ) { return $title; } // List / embedded Bookings table only — keep full titles elsewhere. $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen || ! isset( $screen->id ) || (string) $screen->id !== 'edit-picky_order' ) { return $title; } /* translators: %d: order post ID */ return sprintf( __( 'Order #%d', 'pickybooking' ), $post_id ); } /** * Intercept native WP "Edit" requests for picky_order: redirect to the embedded dashboard editor. * Mirrors `redirect_edit_layout` so old bookmarks / external integrations still land in the SPA. */ public function redirect_edit_order() { $action = sanitize_key( picky_request_query_value( 'action' ) ); if ( $action !== 'edit' ) { return; } $nonce = picky_request_query_value( '_wpnonce' ); if ( $nonce === '' || ! wp_verify_nonce( $nonce, 'picky_edit_picky_order' ) ) { return; } $post_id = absint( picky_request_query_value( 'post' ) ); if ( get_post_type( $post_id ) !== 'picky_order' ) { return; } if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'pickybooking' ) ); } wp_safe_redirect( $this->picky_order_dashboard_url( (int) $post_id ) ); exit; } /** * Render the embedded order-edit screen inside Bookings tab. * * Reuses the existing meta-box renderers from the Public class (`render_order_info` and * `render_order_items`) so the displayed data stays identical to the legacy native edit * screen — only the surrounding shell, navigation, and save flow change. * * @param int $order_id picky_order post id (already validated by caller). * @return void */ private function picky_render_order_edit_embedded( $order_id ) { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only admin GET for UI $order_id = absint( $order_id ); if ( $order_id <= 0 || get_post_type( $order_id ) !== 'picky_order' ) { return; } if ( ! current_user_can( 'edit_post', $order_id ) ) { echo '

' . esc_html__( 'Insufficient permissions.', 'pickybooking' ) . '

'; return; } $order_post = get_post( $order_id ); if ( ! ( $order_post instanceof \WP_Post ) ) { echo '

' . esc_html__( 'Order not found.', 'pickybooking' ) . '

'; return; } // Build a Public_Plugin instance on demand so we can reuse its meta-box renderers // without taking a hard dependency on the global plugin loader's instance graph. if ( ! class_exists( __NAMESPACE__ . '\\Public_Plugin' ) ) { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-public.php'; } $renderer = new Public_Plugin( $this->plugin_slug, $this->version, $this->option_name ); $back_url = $this->picky_order_dashboard_url( 0 ); $saved_flag = picky_request_query_value( 'saved' ) === '1'; $status_now = (string) get_post_status( $order_id ); $status_map = array( 'requests' => __( 'Requested', 'pickybooking' ), 'reserved' => __( 'Reserved', 'pickybooking' ), 'canceled' => __( 'Canceled', 'pickybooking' ), 'draft' => __( 'Draft', 'pickybooking' ), ); $title = get_the_title( $order_id ); if ( $title === '' ) { /* translators: %d: order id */ $title = sprintf( __( 'Order #%d', 'pickybooking' ), $order_id ); } $order_date = (string) get_post_meta( $order_id, '_picky_order_date', true ); $order_time = (string) get_post_meta( $order_id, '_picky_order_time', true ); $order_count = (int) get_post_meta( $order_id, '_picky_order_item_count', true ); ?>
0 ) : ?>

render_order_info( $order_post ); ?>

$st_label ) : ?>

0 ) : ?>
render_order_items( $order_post ); ?>
400 ) ); } if ( ! current_user_can( 'edit_post', $order_id ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'pickybooking' ), '', array( 'response' => 403 ) ); } // Re-use existing public-class save handler so any meta sanitization stays in one place. if ( ! class_exists( __NAMESPACE__ . '\\Public_Plugin' ) ) { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-public.php'; } $renderer = new Public_Plugin( $this->plugin_slug, $this->version, $this->option_name ); $renderer->save_order_metadata( $order_id ); // Status cascade: parent + every child picky_booking gets the same post_status so the // dashboard never shows "1 reserved / 2 requests" mismatches inside one order. $valid_statuses = array( 'draft', 'picky_requests', 'picky_reserved', 'picky_canceled', 'requests', 'reserved', 'canceled' ); $new_status = isset( $_POST['post_status'] ) && is_scalar( $_POST['post_status'] ) ? sanitize_key( wp_unslash( (string) $_POST['post_status'] ) ) : ''; if ( in_array( $new_status, $valid_statuses, true ) && $new_status !== get_post_status( $order_id ) ) { wp_update_post( array( 'ID' => $order_id, 'post_status' => $new_status, ) ); $children = get_posts( array( 'post_type' => 'picky_booking', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids', 'meta_query' => array( array( 'key' => '_picky_booking_order_id', 'value' => $order_id, 'compare' => '=', ), ), ) ); foreach ( $children as $cid ) { wp_update_post( array( 'ID' => (int) $cid, 'post_status' => $new_status, ) ); } } wp_safe_redirect( $this->picky_order_dashboard_url( $order_id, array( 'saved' => '1' ) ) ); exit; // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_query } /** * Dashboard URL for the calendar tab (tab 8), optionally opening a single booking editor. * * @param int $booking_id Booking post ID, or 0 for the calendar only. * @param array $extra Extra query args (e.g. saved=1). * @return string */ public function picky_booking_dashboard_url( $booking_id = 0, $extra = array() ) { $args = array( 'page' => 'picky_settings', 'picky-tab' => '8', ); $booking_id = absint( $booking_id ); if ( $booking_id > 0 ) { $args['booking_id'] = $booking_id; } if ( is_array( $extra ) ) { foreach ( $extra as $k => $v ) { if ( $v === null || $v === '' ) { continue; } $args[ (string) $k ] = $v; } } $url = admin_url( add_query_arg( $args, 'admin.php' ) ); if ( $booking_id > 0 ) { $url = wp_nonce_url( $url, 'picky_open_booking' ); } return $url; } /** * Filter `get_edit_post_link` for picky_booking so list/calendar links stay inside the dashboard. * * @param string $url URL WP built for the post. * @param int $post_id Post ID being linked. * @param string $context Context ('display'|'raw'). * @return string */ public function picky_booking_filter_edit_post_link( $url, $post_id, $context = 'display' ) { unset( $context ); if ( ! $post_id ) { return $url; } if ( get_post_type( (int) $post_id ) !== 'picky_booking' ) { return $url; } return $this->picky_booking_dashboard_url( (int) $post_id ); } /** * Intercept native WP "Edit" requests for picky_booking: redirect to the embedded calendar editor. */ public function redirect_edit_booking() { $action = sanitize_key( picky_request_query_value( 'action' ) ); if ( $action !== 'edit' ) { return; } $nonce = picky_request_query_value( '_wpnonce' ); if ( $nonce === '' || ! wp_verify_nonce( $nonce, 'picky_edit_picky_booking' ) ) { return; } $post_id = absint( picky_request_query_value( 'post' ) ); if ( get_post_type( $post_id ) !== 'picky_booking' ) { return; } if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'pickybooking' ) ); } wp_safe_redirect( $this->picky_booking_dashboard_url( (int) $post_id ) ); exit; } /** * Render the embedded booking-edit screen inside the Calendar tab. * * @param int $booking_id picky_booking post ID. * @return void */ private function picky_render_booking_edit_embedded( $booking_id ) { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only admin GET for UI $booking_id = absint( $booking_id ); if ( $booking_id <= 0 || get_post_type( $booking_id ) !== 'picky_booking' ) { return; } if ( ! current_user_can( 'edit_post', $booking_id ) ) { echo '

' . esc_html__( 'Insufficient permissions.', 'pickybooking' ) . '

'; return; } $booking_post = get_post( $booking_id ); if ( ! ( $booking_post instanceof \WP_Post ) ) { echo '

' . esc_html__( 'Reservation not found.', 'pickybooking' ) . '

'; return; } if ( current_user_can( 'manage_options' ) && isset( $_GET['_wpnonce'] ) && is_scalar( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( (string) $_GET['_wpnonce'] ) ), 'picky_open_booking' ) ) { update_post_meta( $booking_id, '_picky_admin_seen', '1' ); } if ( ! class_exists( __NAMESPACE__ . '\\Public_Plugin' ) ) { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-public.php'; } $renderer = new Public_Plugin( $this->plugin_slug, $this->version, $this->option_name ); $back_url = $this->picky_booking_dashboard_url( 0 ); $saved_flag = picky_request_query_value( 'saved' ) === '1'; $status_now = (string) get_post_status( $booking_id ); $status_map = array( 'requests' => __( 'Requested', 'pickybooking' ), 'reserved' => __( 'Reserved', 'pickybooking' ), 'canceled' => __( 'Canceled', 'pickybooking' ), 'draft' => __( 'Draft', 'pickybooking' ), ); $title = get_the_title( $booking_id ); if ( $title === '' ) { /* translators: %d: booking id */ $title = sprintf( __( 'Reservation #%d', 'pickybooking' ), $booking_id ); } $table_id = (string) get_post_meta( $booking_id, '_picky_booking_id', true ); $date = (string) get_post_meta( $booking_id, '_picky_booking_date', true ); $time = (string) get_post_meta( $booking_id, '_picky_booking_time', true ); $people = (string) get_post_meta( $booking_id, '_picky_booking_people', true ); $layout_id = (int) get_post_meta( $booking_id, '_picky_reservation_layout_id', true ); $order_id = (int) get_post_meta( $booking_id, '_picky_booking_order_id', true ); /* translators: %s: configurable item name singular (e.g. Table, Room, Court) */ $details_title = sprintf( __( '%s Reservation Details', 'pickybooking' ), $renderer->picky_item_label() ); ?>
picky_item_label() . ' ' . $table_id ); ?>
0 ) : ?>
0 && get_post_type( $order_id ) === 'picky_order' ) : ?>

render_location_info( $booking_post ); ?>

$st_label ) : ?>
picky_payment_status_map(); if ( $payment_now === '' || $payment_now === 'none' ) { $payment_now = 'not_required'; } elseif ( in_array( $payment_now, array( 'cancelled', 'init_failed' ), true ) ) { $payment_now = 'not_paid'; } if ( ! isset( $payment_map[ $payment_now ] ) ) { $payment_now = 'not_required'; } ?>

$pay_label ) : ?>
400 ) ); } if ( ! current_user_can( 'edit_post', $booking_id ) ) { wp_die( esc_html__( 'Insufficient permissions.', 'pickybooking' ), '', array( 'response' => 403 ) ); } if ( ! class_exists( __NAMESPACE__ . '\\Public_Plugin' ) ) { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-public.php'; } $renderer = new Public_Plugin( $this->plugin_slug, $this->version, $this->option_name ); $renderer->save_metadata( $booking_id ); $valid_statuses = array( 'draft', 'picky_requests', 'picky_reserved', 'picky_canceled', 'requests', 'reserved', 'canceled' ); $new_status = isset( $_POST['post_status'] ) && is_scalar( $_POST['post_status'] ) ? sanitize_key( wp_unslash( (string) $_POST['post_status'] ) ) : ''; if ( in_array( $new_status, $valid_statuses, true ) && $new_status !== get_post_status( $booking_id ) ) { wp_update_post( array( 'ID' => $booking_id, 'post_status' => $new_status, ) ); } if ( isset( $_POST['picky_payment_status'] ) && is_scalar( $_POST['picky_payment_status'] ) ) { $this->picky_update_booking_payment_status( $booking_id, sanitize_key( wp_unslash( (string) $_POST['picky_payment_status'] ) ) ); } wp_safe_redirect( $this->picky_booking_dashboard_url( $booking_id, array( 'saved' => '1' ) ) ); exit; } /** * Valid custom post statuses for bookings and orders. * * @return string[] */ private function picky_reservation_status_keys() { return array( 'draft', 'picky_requests', 'picky_reserved', 'picky_canceled', 'requests', 'reserved', 'canceled' ); } /** * Human-readable labels for reservation statuses. * * @return array */ private function picky_reservation_status_map() { return array( 'requests' => __( 'Requested', 'pickybooking' ), 'reserved' => __( 'Reserved', 'pickybooking' ), 'canceled' => __( 'Canceled', 'pickybooking' ), 'draft' => __( 'Draft', 'pickybooking' ), ); } /** * AJAX: save booking status immediately from the embedded editor. */ public function ajax_save_booking_status() { check_ajax_referer( 'picky_ajax_booking_status', 'nonce' ); $booking_id = isset( $_POST['booking_id'] ) && is_scalar( $_POST['booking_id'] ) ? absint( wp_unslash( (string) $_POST['booking_id'] ) ) : 0; if ( $booking_id <= 0 || get_post_type( $booking_id ) !== 'picky_booking' ) { wp_send_json_error( array( 'message' => __( 'Invalid reservation.', 'pickybooking' ) ), 400 ); } if ( ! current_user_can( 'edit_post', $booking_id ) ) { wp_send_json_error( array( 'message' => __( 'Insufficient permissions.', 'pickybooking' ) ), 403 ); } $new_status = isset( $_POST['post_status'] ) && is_scalar( $_POST['post_status'] ) ? sanitize_key( wp_unslash( (string) $_POST['post_status'] ) ) : ''; if ( ! in_array( $new_status, $this->picky_reservation_status_keys(), true ) ) { wp_send_json_error( array( 'message' => __( 'Invalid status.', 'pickybooking' ) ), 400 ); } $current = (string) get_post_status( $booking_id ); if ( $new_status !== $current ) { wp_update_post( array( 'ID' => $booking_id, 'post_status' => $new_status, ) ); } $labels = $this->picky_reservation_status_map(); wp_send_json_success( array( 'status' => $new_status, 'label' => isset( $labels[ $new_status ] ) ? $labels[ $new_status ] : ucfirst( $new_status ), ) ); } /** * Allowed payment status keys for admin booking editor. * * @return string[] */ private function picky_payment_status_keys() { return array( 'paid', 'pending', 'not_paid', 'not_required' ); } /** * Labels for payment statuses in the booking editor. * * @return array */ private function picky_payment_status_map() { return array( 'paid' => __( 'Paid', 'pickybooking' ), 'pending' => __( 'Pending', 'pickybooking' ), 'not_paid' => __( 'Unpaid', 'pickybooking' ), 'not_required' => __( 'No payment required', 'pickybooking' ), ); } /** * Persist booking payment status meta (and mark provider as manual when admin sets paid). * * @param int $booking_id Booking post ID. * @param string $status Payment status key. * @return string|false Normalized status on success, false on invalid. */ private function picky_update_booking_payment_status( $booking_id, $status ) { $booking_id = absint( $booking_id ); $status = sanitize_key( (string) $status ); if ( $booking_id <= 0 || ! in_array( $status, $this->picky_payment_status_keys(), true ) ) { return false; } update_post_meta( $booking_id, '_picky_payment_status', $status ); if ( $status === 'paid' ) { $provider = sanitize_key( (string) get_post_meta( $booking_id, '_picky_payment_provider', true ) ); if ( $provider === '' || $provider === 'none' ) { update_post_meta( $booking_id, '_picky_payment_provider', 'manual' ); } } elseif ( $status === 'not_required' ) { $provider = sanitize_key( (string) get_post_meta( $booking_id, '_picky_payment_provider', true ) ); if ( $provider === '' || $provider === 'manual' ) { update_post_meta( $booking_id, '_picky_payment_provider', 'none' ); } } return $status; } /** * AJAX: save booking payment status (Pro). */ public function ajax_save_booking_payment() { wp_send_json_error( array( 'message' => __( 'Not available.', 'pickybooking' ) ), 404 ); } /** * AJAX: save order status immediately and cascade to child bookings. */ public function ajax_save_order_status() { // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Admin list/filter queries require meta_query check_ajax_referer( 'picky_ajax_order_status', 'nonce' ); $order_id = isset( $_POST['order_id'] ) && is_scalar( $_POST['order_id'] ) ? absint( wp_unslash( (string) $_POST['order_id'] ) ) : 0; if ( $order_id <= 0 || get_post_type( $order_id ) !== 'picky_order' ) { wp_send_json_error( array( 'message' => __( 'Invalid order.', 'pickybooking' ) ), 400 ); } if ( ! current_user_can( 'edit_post', $order_id ) ) { wp_send_json_error( array( 'message' => __( 'Insufficient permissions.', 'pickybooking' ) ), 403 ); } $new_status = isset( $_POST['post_status'] ) && is_scalar( $_POST['post_status'] ) ? sanitize_key( wp_unslash( (string) $_POST['post_status'] ) ) : ''; if ( ! in_array( $new_status, $this->picky_reservation_status_keys(), true ) ) { wp_send_json_error( array( 'message' => __( 'Invalid status.', 'pickybooking' ) ), 400 ); } if ( $new_status !== get_post_status( $order_id ) ) { wp_update_post( array( 'ID' => $order_id, 'post_status' => $new_status, ) ); $children = get_posts( array( 'post_type' => 'picky_booking', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids', 'meta_query' => array( array( 'key' => '_picky_booking_order_id', 'value' => $order_id, 'compare' => '=', ), ), ) ); foreach ( $children as $cid ) { wp_update_post( array( 'ID' => (int) $cid, 'post_status' => $new_status, ) ); } } $labels = $this->picky_reservation_status_map(); wp_send_json_success( array( 'status' => $new_status, 'label' => isset( $labels[ $new_status ] ) ? $labels[ $new_status ] : ucfirst( $new_status ), ) ); // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_query } /** * Header nav: Layouts tab + submenu (All layouts as parent, named layouts nested under it). * * @param string $active_class Active class string for the primary Layouts control (e.g. 'active'). * @param string $active_tab Current tab index ('7', '9', …). * @return string */ private function picky_render_settings_header_layouts_nav( $active_class, $active_tab ) { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only admin GET for UI $current_layout = absint( picky_request_query_value( 'layout_id' ) ); $layouts = \Picky\Layout_Library::get_user_layout_posts( 'title', 'ASC' ); $pto = get_post_type_object( 'picky_layout' ); $can_add_layout = $pto && ! empty( $pto->cap->create_posts ) && current_user_can( $pto->cap->create_posts ); $layouts_add_url = $this->picky_new_layout_url(); $out = '
'; $out .= '' . esc_html__( 'Layouts', 'pickybooking' ) . ''; $out .= '
    '; foreach ( $layouts as $p ) { $lid = (int) $p->ID; $title = get_the_title( $p ); if ( $title === '' ) { /* translators: %d: layout post ID */ $title = sprintf( __( 'Layout #%d', 'pickybooking' ), $lid ); } $sub_active = ( $active_tab === '9' && $current_layout === $lid ); $out .= '
  • '; $out .= '' . esc_html( (string) $title ) . ''; $out .= '
  • '; } if ( $can_add_layout ) { $out .= '
  • ' . esc_html__( 'Add new', 'pickybooking' ) . '
  • '; } $out .= '
'; return $out; // phpcs:enable WordPress.Security.NonceVerification.Recommended } /** * Output layout builder markup (standalone or embedded in the Layouts tab). * * @param int $layout_id Post ID of picky_layout. * @param bool $embedded When true, omits duplicate page chrome (inside Settings). * @return void */ private function picky_render_layout_builder( $layout_id, $embedded = false ) { $layout_id = absint( $layout_id ); if ( ! $layout_id || get_post_type( $layout_id ) !== 'picky_layout' ) { return; } $this->picky_migrate_layout_to_library( $layout_id ); $picky_layout_embedded = (bool) $embedded; $layout_post = get_post( $layout_id ); $layout_title = $layout_post ? $layout_post->post_title : __( 'Layout', 'pickybooking' ); $layout_position = get_post_meta( $layout_id, '_picky_layout_position', true ); if ( ! $layout_position ) { $layout_position = ''; } $options = Info::get_settings(); $per_layout_w = (int) get_post_meta( $layout_id, '_picky_layout_canvas_width', true ); $per_layout_h = (int) get_post_meta( $layout_id, '_picky_layout_canvas_height', true ); if ( $per_layout_w > 0 ) { $options['canvas_width'] = $per_layout_w; } if ( $per_layout_h > 0 ) { $options['canvas_height'] = $per_layout_h; } $settings = $options; $option_name = INFO::OPTION_NAME; $heading = Info::get_plugin_title(); $submit_text = __( 'Save Layout', 'pickybooking' ); $tables = \Picky\Edition::tables_palette(); $builder_font_family_options = $this->picky_builder_font_family_options(); $background_canvas = $this->custom_image_uploader_field( 'picky_layout_bg_canvas', get_post_meta( $layout_id, '_picky_layout_bg_canvas', true ) ); $background_table = $this->custom_image_uploader_field( 'picky_layout_bg_table', get_post_meta( $layout_id, '_picky_layout_bg_table', true ) ); require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/view_layout.php'; } /** * Collapse duplicate query keys (e.g. picky-tab twice) into one via wp_parse_str + build_query. * * @param string $url Full URL. * @return string */ private function picky_normalize_admin_url_query( $url ) { $p = wp_parse_url( $url ); if ( ! is_array( $p ) || empty( $p['query'] ) || ! is_string( $p['query'] ) ) { return $url; } wp_parse_str( $p['query'], $args ); if ( ! is_array( $args ) ) { return $url; } $query = build_query( $args ); $out = ''; if ( isset( $p['scheme'] ) && is_string( $p['scheme'] ) ) { $out .= $p['scheme'] . '://'; } if ( isset( $p['host'] ) && is_string( $p['host'] ) ) { $out .= $p['host']; } if ( isset( $p['port'] ) ) { $out .= ':' . (int) $p['port']; } if ( isset( $p['path'] ) && is_string( $p['path'] ) ) { $out .= $p['path']; } $out .= ( $query !== '' ) ? '?' . $query : ''; if ( isset( $p['fragment'] ) && is_string( $p['fragment'] ) && $p['fragment'] !== '' ) { $out .= '#' . $p['fragment']; } return $out; } /** * Single picky-tab value for the current request. * Duplicate keys resolve to the last value. The value is sanitized before it is used. * * @return string Allowed tab id or '' if absent/invalid. */ private function picky_request_picky_tab_value() { $allowed = array( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13' ); $bag = picky_request_query_bag(); $raw = isset( $bag['picky-tab'] ) ? $bag['picky-tab'] : ''; if ( is_array( $raw ) ) { $last = end( $raw ); $raw = is_scalar( $last ) ? sanitize_text_field( (string) $last ) : ''; } $candidate = is_scalar( $raw ) ? sanitize_text_field( (string) $raw ) : ''; if ( $candidate === '' || ! in_array( $candidate, $allowed, true ) ) { return ''; } return $candidate; } /** * Active-tab state class for settings wrappers. * * @param string $tab * @return string */ private function picky_settings_active_tab_class( $tab ) { $map = array( '1' => 'is-tab-main', '2' => 'is-tab-work-days', '3' => 'is-tab-sms', '4' => 'is-tab-layout-colors', '5' => 'is-tab-payments', '6' => 'is-tab-form-emails', '7' => 'is-tab-reservations', '8' => 'is-tab-calendar', '9' => 'is-tab-layouts', '10' => 'is-tab-import-export', '11' => 'is-tab-documentation', '12' => 'is-tab-integrations', '13' => 'is-tab-orders', ); return isset( $map[ $tab ] ) ? $map[ $tab ] : 'is-tab-unknown'; } /** * Escape trusted admin shell HTML with wp_kses, preserving data:image URIs * (layout library preset thumbs). Core kses strips the data: protocol. * * @param string $html Raw plugin-generated admin HTML. * @return string */ public function picky_escape_admin_shell_html( $html ) { $html = (string) $html; if ( $html === '' ) { return ''; } $allowed = $this->picky_kses_allowed_admin_list_html(); $map = array(); $that = $this; // Park full or empty string when nothing usable remains. */ private function picky_rebuild_safe_admin_style_block( $attrs_raw, $css_raw ) { $attrs_raw = is_string( $attrs_raw ) ? $attrs_raw : ''; $css_raw = is_string( $css_raw ) ? $css_raw : ''; $safe_attrs = array(); if ( preg_match( '/\bid\s*=\s*([\'"])([^\'"]*)\1/i', $attrs_raw, $m ) ) { $id = sanitize_html_class( $m[2] ); if ( $id === '' || strpos( $id, 'picky-' ) === 0 ) { $safe_attrs[] = 'id="' . esc_attr( $id ) . '"'; } } if ( preg_match( '/\bclass\s*=\s*([\'"])([^\'"]*)\1/i', $attrs_raw, $m ) ) { $classes = preg_split( '/\s+/', (string) $m[2] ); $keep = array(); if ( is_array( $classes ) ) { foreach ( $classes as $class ) { $class = sanitize_html_class( $class ); if ( $class !== '' && strpos( $class, 'picky-' ) === 0 ) { $keep[] = $class; } } } if ( ! empty( $keep ) ) { $safe_attrs[] = 'class="' . esc_attr( implode( ' ', $keep ) ) . '"'; } } if ( preg_match( '/\btype\s*=\s*([\'"])([^\'"]*)\1/i', $attrs_raw, $m ) ) { $type = strtolower( trim( (string) $m[2] ) ); if ( $type === 'text/css' ) { $safe_attrs[] = 'type="text/css"'; } } $css = $this->picky_sanitize_admin_inline_css( $css_raw ); if ( $css === '' ) { return ''; } $open = '' . $css . ''; } /** * Sanitize inline CSS used in trusted admin