*/ public function defaults() { $native = $this->get_native_store_data(); $legacy_address = $this->build_legacy_address( $native ); $default_contact_channel = $this->resolve_default_contact_channel( $native['contact_phone'], $native['admin_email'] ); $default_contact_value = $this->resolve_default_contact_value( $default_contact_channel, $native['contact_phone'], $native['admin_email'] ); return array( // Canonical store fields (read-only source: WordPress/WooCommerce). 'store_name' => $native['store_name'], 'slogan' => $native['slogan'], 'admin_email' => $native['admin_email'], 'address_line_1' => $native['address_line_1'], 'address_line_2' => $native['address_line_2'], 'city' => $native['city'], 'postcode' => $native['postcode'], 'country_state' => $native['country_state'], 'currency' => $native['currency'], 'contact_phone' => $native['contact_phone'], 'address' => $legacy_address, // ABCT complementary store fields. 'store_logo' => 0, 'display_name' => '', 'tax_id' => '', 'tax_label' => 'Tax ID', 'store_contact_label' => 'Primary contact', 'store_contact_channel' => $default_contact_channel, 'store_contact_value' => $default_contact_value, 'store_contact_notes' => '', 'store_contact_notes_display' => 'print', 'order_customer_notes_display' => 'print', // Premium sound contract (phase 1). 'new_order_sound_enabled' => 1, 'new_order_sound_variant' => 'sound_1', 'new_order_sound_volume' => 70, 'new_order_sound_target' => 'production_board', // Premium structured print contract (phase 1). 'print_show_logo' => 'yes', 'print_show_store_name' => 'yes', 'print_show_store_address'=> 'yes', 'print_show_store_contact'=> 'yes', 'print_layout' => 'receipt_80', 'print_paper_width' => '80', 'print_font_size' => 'medium', 'print_density' => 'normal', 'print_show_datetime' => 'yes', 'print_show_customer_phone' => 'yes', 'print_show_payment_status' => 'yes', 'print_show_order_notes' => 'yes', // Legacy compatibility aliases. 'cnpj' => '', // Legacy premium keys kept for backward compatibility. 'printer_settings' => '', 'new_order_sound' => 1, 'default_prep_time' => 20, 'kitchen_tv_mode' => 0, 'sound_volume' => 70, 'smart_silent_mode' => 1, 'sound_new_order' => 'sound_1.mp3', 'sound_order_ready' => 'order-ready.mp3', 'sound_urgent_order' => 'urgent-order.mp3', 'sound_reconnect' => 'reconnect.mp3', ); } /** * Read settings. * * @return array */ public function get() { $raw = get_option( self::OPTION_KEY, array() ); if ( ! is_array( $raw ) ) { $raw = array(); } $defaults = $this->defaults(); $native = $this->get_native_store_data(); $settings = wp_parse_args( $raw, $defaults ); unset( $settings['print_store_name_source'] ); $settings['store_name'] = '' !== $native['store_name'] ? $native['store_name'] : sanitize_text_field( isset( $settings['store_name'] ) ? (string) $settings['store_name'] : '' ); $settings['slogan'] = '' !== $native['slogan'] ? $native['slogan'] : sanitize_text_field( isset( $settings['slogan'] ) ? (string) $settings['slogan'] : '' ); $settings['admin_email'] = '' !== $native['admin_email'] ? $native['admin_email'] : sanitize_email( isset( $settings['admin_email'] ) ? (string) $settings['admin_email'] : '' ); $settings['address_line_1'] = '' !== $native['address_line_1'] ? $native['address_line_1'] : sanitize_text_field( isset( $settings['address_line_1'] ) ? (string) $settings['address_line_1'] : '' ); $settings['address_line_2'] = '' !== $native['address_line_2'] ? $native['address_line_2'] : sanitize_text_field( isset( $settings['address_line_2'] ) ? (string) $settings['address_line_2'] : '' ); $settings['city'] = '' !== $native['city'] ? $native['city'] : sanitize_text_field( isset( $settings['city'] ) ? (string) $settings['city'] : '' ); $settings['postcode'] = '' !== $native['postcode'] ? $native['postcode'] : sanitize_text_field( isset( $settings['postcode'] ) ? (string) $settings['postcode'] : '' ); $settings['country_state'] = '' !== $native['country_state'] ? $native['country_state'] : sanitize_text_field( isset( $settings['country_state'] ) ? (string) $settings['country_state'] : '' ); $settings['currency'] = '' !== $native['currency'] ? $native['currency'] : sanitize_text_field( isset( $settings['currency'] ) ? (string) $settings['currency'] : '' ); $legacy_contact_phone = sanitize_text_field( isset( $settings['contact_phone'] ) ? (string) $settings['contact_phone'] : '' ); $settings['contact_phone'] = '' !== $native['contact_phone'] ? $native['contact_phone'] : $legacy_contact_phone; $legacy_address = sanitize_textarea_field( isset( $settings['address'] ) ? (string) $settings['address'] : '' ); $base_address = $this->build_legacy_address( $settings ); $settings['address'] = '' !== $base_address ? $base_address : $legacy_address; $settings['display_name'] = sanitize_text_field( isset( $settings['display_name'] ) ? (string) $settings['display_name'] : '' ); if ( '' === $settings['display_name'] ) { $legacy_name = sanitize_text_field( isset( $raw['store_name'] ) ? (string) $raw['store_name'] : '' ); $settings['display_name'] = '' !== $legacy_name ? $legacy_name : $settings['store_name']; } $legacy_cnpj = sanitize_text_field( isset( $settings['cnpj'] ) ? (string) $settings['cnpj'] : '' ); $settings['tax_id'] = sanitize_text_field( isset( $settings['tax_id'] ) ? (string) $settings['tax_id'] : '' ); if ( '' === $settings['tax_id'] && '' !== $legacy_cnpj ) { $settings['tax_id'] = $legacy_cnpj; } $settings['tax_label'] = sanitize_text_field( isset( $settings['tax_label'] ) ? (string) $settings['tax_label'] : '' ); if ( '' === $settings['tax_label'] ) { $settings['tax_label'] = '' !== $legacy_cnpj ? 'CNPJ' : 'Tax ID'; } $settings['cnpj'] = '' !== $legacy_cnpj ? $legacy_cnpj : $settings['tax_id']; $settings['store_contact_label'] = sanitize_text_field( isset( $settings['store_contact_label'] ) ? (string) $settings['store_contact_label'] : '' ); $settings['store_contact_channel'] = $this->sanitize_contact_channel( isset( $settings['store_contact_channel'] ) ? $settings['store_contact_channel'] : '' ); $settings['store_contact_value'] = sanitize_text_field( isset( $settings['store_contact_value'] ) ? (string) $settings['store_contact_value'] : '' ); $settings['store_contact_notes'] = sanitize_textarea_field( isset( $settings['store_contact_notes'] ) ? (string) $settings['store_contact_notes'] : '' ); $settings['store_contact_notes_display'] = $this->sanitize_contact_notes_display( isset( $settings['store_contact_notes_display'] ) ? $settings['store_contact_notes_display'] : 'print' ); $settings['order_customer_notes_display'] = $this->sanitize_contact_notes_display( isset( $settings['order_customer_notes_display'] ) ? $settings['order_customer_notes_display'] : ( 'yes' === $this->sanitize_yes_no( isset( $settings['print_show_order_notes'] ) ? $settings['print_show_order_notes'] : 'yes', 'yes' ) ? 'print' : 'none' ) ); if ( '' === $settings['store_contact_label'] ) { $settings['store_contact_label'] = 'Primary contact'; } if ( '' === $settings['store_contact_value'] ) { $settings['store_contact_value'] = $this->resolve_default_contact_value( $settings['store_contact_channel'], $settings['contact_phone'], $settings['admin_email'] ); } $settings['store_logo'] = absint( isset( $settings['store_logo'] ) ? $settings['store_logo'] : 0 ); $settings['default_prep_time'] = max( 1, absint( isset( $settings['default_prep_time'] ) ? $settings['default_prep_time'] : 20 ) ); $settings['kitchen_tv_mode'] = ! empty( $settings['kitchen_tv_mode'] ) ? 1 : 0; $settings['printer_settings'] = sanitize_textarea_field( isset( $settings['printer_settings'] ) ? (string) $settings['printer_settings'] : '' ); // New sound contract with legacy fallback. $legacy_sound_enabled = ! empty( $settings['new_order_sound'] ) ? 1 : 0; $sound_enabled_raw = isset( $settings['new_order_sound_enabled'] ) ? $settings['new_order_sound_enabled'] : $legacy_sound_enabled; $settings['new_order_sound_enabled'] = ! empty( $sound_enabled_raw ) ? 1 : 0; $legacy_volume = isset( $settings['sound_volume'] ) ? absint( $settings['sound_volume'] ) : 70; $sound_volume_raw = isset( $settings['new_order_sound_volume'] ) ? $settings['new_order_sound_volume'] : $legacy_volume; $settings['new_order_sound_volume'] = min( 100, max( 0, absint( $sound_volume_raw ) ) ); $variant_raw = isset( $settings['new_order_sound_variant'] ) ? (string) $settings['new_order_sound_variant'] : ''; if ( '' === $variant_raw ) { $variant_raw = $this->map_legacy_sound_file_to_variant( isset( $settings['sound_new_order'] ) ? $settings['sound_new_order'] : 'new-order.mp3' ); } $settings['new_order_sound_variant'] = $this->sanitize_new_order_sound_variant( $variant_raw ); $settings['new_order_sound_target'] = $this->sanitize_new_order_sound_target( isset( $settings['new_order_sound_target'] ) ? $settings['new_order_sound_target'] : 'production_board' ); // Keep legacy sound keys mirrored for backward compatibility. $settings['new_order_sound'] = $settings['new_order_sound_enabled']; $settings['sound_volume'] = $settings['new_order_sound_volume']; $settings['sound_new_order'] = $this->map_sound_variant_to_file( $settings['new_order_sound_variant'] ); $settings['sound_order_ready'] = sanitize_file_name( isset( $settings['sound_order_ready'] ) ? (string) $settings['sound_order_ready'] : 'order-ready.mp3' ); $settings['sound_urgent_order'] = sanitize_file_name( isset( $settings['sound_urgent_order'] ) ? (string) $settings['sound_urgent_order'] : 'urgent-order.mp3' ); $settings['sound_reconnect'] = sanitize_file_name( isset( $settings['sound_reconnect'] ) ? (string) $settings['sound_reconnect'] : 'reconnect.mp3' ); $settings['smart_silent_mode'] = ! empty( $settings['smart_silent_mode'] ) ? 1 : 0; // New print contract. $settings['print_show_logo'] = $this->sanitize_yes_no( isset( $settings['print_show_logo'] ) ? $settings['print_show_logo'] : 'yes', 'yes' ); $settings['print_show_store_name'] = $this->sanitize_yes_no( isset( $settings['print_show_store_name'] ) ? $settings['print_show_store_name'] : 'yes', 'yes' ); $settings['print_show_store_address'] = $this->sanitize_yes_no( isset( $settings['print_show_store_address'] ) ? $settings['print_show_store_address'] : 'yes', 'yes' ); $settings['print_show_store_contact'] = $this->sanitize_yes_no( isset( $settings['print_show_store_contact'] ) ? $settings['print_show_store_contact'] : 'yes', 'yes' ); $settings['print_layout'] = $this->sanitize_print_layout( isset( $settings['print_layout'] ) ? $settings['print_layout'] : 'receipt_80' ); $settings['print_paper_width'] = $this->sanitize_print_paper_width( isset( $settings['print_paper_width'] ) ? $settings['print_paper_width'] : '80' ); $settings['print_font_size'] = $this->sanitize_print_font_size( isset( $settings['print_font_size'] ) ? $settings['print_font_size'] : 'medium' ); $settings['print_density'] = $this->sanitize_print_density( isset( $settings['print_density'] ) ? $settings['print_density'] : 'normal' ); $settings['print_show_datetime'] = $this->sanitize_yes_no( isset( $settings['print_show_datetime'] ) ? $settings['print_show_datetime'] : 'yes', 'yes' ); $settings['print_show_customer_phone'] = $this->sanitize_yes_no( isset( $settings['print_show_customer_phone'] ) ? $settings['print_show_customer_phone'] : 'yes', 'yes' ); $settings['print_show_payment_status'] = $this->sanitize_yes_no( isset( $settings['print_show_payment_status'] ) ? $settings['print_show_payment_status'] : 'yes', 'yes' ); $settings['print_show_order_notes'] = $this->sanitize_yes_no( isset( $settings['print_show_order_notes'] ) ? $settings['print_show_order_notes'] : 'yes', 'yes' ); return $settings; } /** * Save settings. * * @param array $input Raw payload. * @return array */ public function save( $input ) { if ( ! is_array( $input ) ) { $input = array(); } $current = get_option( self::OPTION_KEY, array() ); if ( ! is_array( $current ) ) { $current = array(); } $settings = $current; unset( $settings['print_store_name_source'] ); $settings['store_logo'] = absint( $this->pick_input_value( $input, 'store_logo', isset( $current['store_logo'] ) ? $current['store_logo'] : 0 ) ); $settings['display_name'] = sanitize_text_field( $this->pick_input_value( $input, 'display_name', isset( $current['display_name'] ) ? $current['display_name'] : '' ) ); $settings['tax_label'] = sanitize_text_field( $this->pick_input_value( $input, 'tax_label', isset( $current['tax_label'] ) ? $current['tax_label'] : '' ) ); $settings['tax_id'] = sanitize_text_field( $this->pick_input_value( $input, 'tax_id', isset( $current['tax_id'] ) ? $current['tax_id'] : '' ) ); $settings['store_contact_label'] = sanitize_text_field( $this->pick_input_value( $input, 'store_contact_label', isset( $current['store_contact_label'] ) ? $current['store_contact_label'] : '' ) ); $settings['store_contact_channel'] = $this->sanitize_contact_channel( $this->pick_input_value( $input, 'store_contact_channel', isset( $current['store_contact_channel'] ) ? $current['store_contact_channel'] : '' ) ); $settings['store_contact_value'] = sanitize_text_field( $this->pick_input_value( $input, 'store_contact_value', isset( $current['store_contact_value'] ) ? $current['store_contact_value'] : '' ) ); $settings['store_contact_notes'] = sanitize_textarea_field( $this->pick_input_value( $input, 'store_contact_notes', isset( $current['store_contact_notes'] ) ? $current['store_contact_notes'] : '' ) ); $settings['store_contact_notes_display'] = $this->sanitize_contact_notes_display( $this->pick_input_value( $input, 'store_contact_notes_display', isset( $current['store_contact_notes_display'] ) ? $current['store_contact_notes_display'] : 'print' ) ); $current_order_customer_notes_display = isset( $current['order_customer_notes_display'] ) ? $current['order_customer_notes_display'] : ( isset( $current['print_show_order_notes'] ) && 'no' === $this->sanitize_yes_no( $current['print_show_order_notes'], 'yes' ) ? 'none' : 'print' ); $settings['order_customer_notes_display'] = $this->sanitize_contact_notes_display( $this->pick_input_value( $input, 'order_customer_notes_display', $current_order_customer_notes_display ) ); // Legacy operational keys are still persisted for compatibility. $settings['default_prep_time'] = max( 1, absint( $this->pick_input_value( $input, 'default_prep_time', isset( $current['default_prep_time'] ) ? $current['default_prep_time'] : 20 ) ) ); $settings['kitchen_tv_mode'] = array_key_exists( 'kitchen_tv_mode', $input ) ? ( ! empty( $input['kitchen_tv_mode'] ) ? 1 : 0 ) : ( ! empty( $current['kitchen_tv_mode'] ) ? 1 : 0 ); $settings['printer_settings'] = sanitize_textarea_field( $this->pick_input_value( $input, 'printer_settings', isset( $current['printer_settings'] ) ? $current['printer_settings'] : '' ) ); $current_sound_enabled = ! empty( isset( $current['new_order_sound_enabled'] ) ? $current['new_order_sound_enabled'] : ( isset( $current['new_order_sound'] ) ? $current['new_order_sound'] : 1 ) ) ? 1 : 0; if ( array_key_exists( 'new_order_sound_enabled', $input ) ) { $new_sound_enabled = ! empty( $input['new_order_sound_enabled'] ) ? 1 : 0; } elseif ( array_key_exists( 'new_order_sound', $input ) ) { $new_sound_enabled = ! empty( $input['new_order_sound'] ) ? 1 : 0; } else { $new_sound_enabled = $current_sound_enabled; } $variant_fallback = isset( $current['new_order_sound_variant'] ) ? (string) $current['new_order_sound_variant'] : $this->map_legacy_sound_file_to_variant( isset( $current['sound_new_order'] ) ? $current['sound_new_order'] : 'new-order.mp3' ); if ( array_key_exists( 'new_order_sound_variant', $input ) ) { $variant_raw = $this->pick_input_value( $input, 'new_order_sound_variant', $variant_fallback ); } elseif ( array_key_exists( 'sound_new_order', $input ) ) { $variant_raw = $this->map_legacy_sound_file_to_variant( $this->pick_input_value( $input, 'sound_new_order', '' ) ); } else { $variant_raw = $variant_fallback; } $new_sound_variant = $this->sanitize_new_order_sound_variant( $variant_raw ); $volume_fallback = isset( $current['new_order_sound_volume'] ) ? $current['new_order_sound_volume'] : ( isset( $current['sound_volume'] ) ? $current['sound_volume'] : 70 ); if ( array_key_exists( 'new_order_sound_volume', $input ) ) { $volume_raw = $this->pick_input_value( $input, 'new_order_sound_volume', $volume_fallback ); } elseif ( array_key_exists( 'sound_volume', $input ) ) { $volume_raw = $this->pick_input_value( $input, 'sound_volume', $volume_fallback ); } else { $volume_raw = $volume_fallback; } $new_sound_volume = min( 100, max( 0, absint( $volume_raw ) ) ); $target_fallback = isset( $current['new_order_sound_target'] ) ? $current['new_order_sound_target'] : 'production_board'; $new_sound_target = $this->sanitize_new_order_sound_target( $this->pick_input_value( $input, 'new_order_sound_target', $target_fallback ) ); $settings['new_order_sound_enabled'] = $new_sound_enabled; $settings['new_order_sound_variant'] = $new_sound_variant; $settings['new_order_sound_volume'] = $new_sound_volume; $settings['new_order_sound_target'] = $new_sound_target; // Legacy sound mirrors. $settings['new_order_sound'] = $new_sound_enabled; $settings['sound_volume'] = $new_sound_volume; $settings['sound_new_order'] = $this->map_sound_variant_to_file( $new_sound_variant ); $settings['sound_order_ready'] = sanitize_file_name( $this->pick_input_value( $input, 'sound_order_ready', isset( $current['sound_order_ready'] ) ? $current['sound_order_ready'] : 'order-ready.mp3' ) ); $settings['sound_urgent_order'] = sanitize_file_name( $this->pick_input_value( $input, 'sound_urgent_order', isset( $current['sound_urgent_order'] ) ? $current['sound_urgent_order'] : 'urgent-order.mp3' ) ); $settings['sound_reconnect'] = sanitize_file_name( $this->pick_input_value( $input, 'sound_reconnect', isset( $current['sound_reconnect'] ) ? $current['sound_reconnect'] : 'reconnect.mp3' ) ); $settings['smart_silent_mode'] = array_key_exists( 'smart_silent_mode', $input ) ? ( ! empty( $input['smart_silent_mode'] ) ? 1 : 0 ) : ( ! empty( $current['smart_silent_mode'] ) ? 1 : 0 ); $settings['print_show_logo'] = $this->sanitize_yes_no( $this->pick_input_value( $input, 'print_show_logo', isset( $current['print_show_logo'] ) ? $current['print_show_logo'] : 'yes' ), 'yes' ); $settings['print_show_store_name'] = $this->sanitize_yes_no( $this->pick_input_value( $input, 'print_show_store_name', isset( $current['print_show_store_name'] ) ? $current['print_show_store_name'] : 'yes' ), 'yes' ); $settings['print_show_store_address'] = $this->sanitize_yes_no( $this->pick_input_value( $input, 'print_show_store_address', isset( $current['print_show_store_address'] ) ? $current['print_show_store_address'] : 'yes' ), 'yes' ); $settings['print_show_store_contact'] = $this->sanitize_yes_no( $this->pick_input_value( $input, 'print_show_store_contact', isset( $current['print_show_store_contact'] ) ? $current['print_show_store_contact'] : 'yes' ), 'yes' ); $settings['print_layout'] = $this->sanitize_print_layout( $this->pick_input_value( $input, 'print_layout', isset( $current['print_layout'] ) ? $current['print_layout'] : 'receipt_80' ) ); $settings['print_paper_width'] = $this->sanitize_print_paper_width( $this->pick_input_value( $input, 'print_paper_width', isset( $current['print_paper_width'] ) ? $current['print_paper_width'] : '80' ) ); $settings['print_font_size'] = $this->sanitize_print_font_size( $this->pick_input_value( $input, 'print_font_size', isset( $current['print_font_size'] ) ? $current['print_font_size'] : 'medium' ) ); $settings['print_density'] = $this->sanitize_print_density( $this->pick_input_value( $input, 'print_density', isset( $current['print_density'] ) ? $current['print_density'] : 'normal' ) ); $settings['print_show_datetime'] = $this->sanitize_yes_no( $this->pick_input_value( $input, 'print_show_datetime', isset( $current['print_show_datetime'] ) ? $current['print_show_datetime'] : 'yes' ), 'yes' ); $settings['print_show_customer_phone'] = $this->sanitize_yes_no( $this->pick_input_value( $input, 'print_show_customer_phone', isset( $current['print_show_customer_phone'] ) ? $current['print_show_customer_phone'] : 'yes' ), 'yes' ); $settings['print_show_payment_status'] = $this->sanitize_yes_no( $this->pick_input_value( $input, 'print_show_payment_status', isset( $current['print_show_payment_status'] ) ? $current['print_show_payment_status'] : 'yes' ), 'yes' ); $legacy_print_show_order_notes_default = in_array( $settings['order_customer_notes_display'], array( 'print', 'both' ), true ) ? 'yes' : 'no'; $settings['print_show_order_notes'] = $this->sanitize_yes_no( $this->pick_input_value( $input, 'print_show_order_notes', $legacy_print_show_order_notes_default ), $legacy_print_show_order_notes_default ); $settings['print_show_order_notes'] = in_array( $settings['order_customer_notes_display'], array( 'print', 'both' ), true ) ? 'yes' : 'no'; // Legacy payload compatibility from older forms/integrations. if ( array_key_exists( 'store_name', $input ) ) { $settings['store_name'] = sanitize_text_field( wp_unslash( $input['store_name'] ) ); } if ( array_key_exists( 'slogan', $input ) ) { $settings['slogan'] = sanitize_text_field( wp_unslash( $input['slogan'] ) ); } if ( array_key_exists( 'address', $input ) ) { $settings['address'] = sanitize_textarea_field( wp_unslash( $input['address'] ) ); } if ( array_key_exists( 'contact_phone', $input ) ) { $settings['contact_phone'] = sanitize_text_field( wp_unslash( $input['contact_phone'] ) ); } if ( array_key_exists( 'cnpj', $input ) ) { $settings['cnpj'] = sanitize_text_field( wp_unslash( $input['cnpj'] ) ); } elseif ( isset( $current['cnpj'] ) ) { $settings['cnpj'] = sanitize_text_field( (string) $current['cnpj'] ); } $legacy_cnpj = isset( $settings['cnpj'] ) ? sanitize_text_field( (string) $settings['cnpj'] ) : ''; if ( '' === $settings['tax_id'] && '' !== $legacy_cnpj ) { $settings['tax_id'] = $legacy_cnpj; } update_option( self::OPTION_KEY, $settings ); return $settings; } /** * Sanitize contact notes display mode. * * @param mixed $value Raw value. * @return string */ private function sanitize_contact_notes_display( $value ) { $value = sanitize_key( (string) $value ); $allowed = array( 'none', 'card', 'print', 'both' ); return in_array( $value, $allowed, true ) ? $value : 'print'; } /** * Sanitize new-order sound variant. * * @param mixed $value Raw value. * @return string */ private function sanitize_new_order_sound_variant( $value ) { $value = sanitize_key( (string) $value ); $allowed = array( 'sound_1', 'sound_2', 'sound_3' ); return in_array( $value, $allowed, true ) ? $value : 'sound_1'; } /** * Sanitize new-order sound target. * * @param mixed $value Raw value. * @return string */ private function sanitize_new_order_sound_target( $value ) { $value = sanitize_key( (string) $value ); $allowed = array( 'production_board', 'master_board_display', 'both' ); return in_array( $value, $allowed, true ) ? $value : 'production_board'; } /** * Map sound variant to internal file name. * * @param string $variant Variant key. * @return string */ private function map_sound_variant_to_file( $variant ) { $variant = $this->sanitize_new_order_sound_variant( $variant ); $map = array( 'sound_1' => 'sound_1.mp3', 'sound_2' => 'sound_2.mp3', 'sound_3' => 'sound_3.mp3', ); return isset( $map[ $variant ] ) ? $map[ $variant ] : 'sound_1.mp3'; } /** * Map legacy sound file name to new variant. * * @param mixed $file Legacy file name. * @return string */ private function map_legacy_sound_file_to_variant( $file ) { $file = sanitize_file_name( (string) $file ); $map = array( 'sound_1.mp3' => 'sound_1', 'sound_2.mp3' => 'sound_2', 'sound_3.mp3' => 'sound_3', 'new-order.mp3' => 'sound_1', 'new-order.ogg' => 'sound_1', 'order-ready.mp3' => 'sound_2', 'order-ready.ogg' => 'sound_2', 'urgent-order.mp3'=> 'sound_3', 'urgent-order.ogg'=> 'sound_3', 'reconnect.mp3' => 'sound_3', 'reconnect.ogg' => 'sound_3', ); return isset( $map[ $file ] ) ? $map[ $file ] : 'sound_1'; } /** * Sanitize yes/no value. * * @param mixed $value Raw value. * @param string $default Default value. * @return string */ private function sanitize_yes_no( $value, $default = 'yes' ) { if ( is_bool( $value ) ) { return $value ? 'yes' : 'no'; } $value = strtolower( trim( (string) $value ) ); if ( in_array( $value, array( '1', 'yes', 'true', 'on' ), true ) ) { return 'yes'; } if ( in_array( $value, array( '0', 'no', 'false', 'off' ), true ) ) { return 'no'; } return 'no' === $default ? 'no' : 'yes'; } /** * Sanitize print layout. * * @param mixed $value Raw value. * @return string */ private function sanitize_print_layout( $value ) { $value = sanitize_key( (string) $value ); $allowed = array( 'receipt_58', 'receipt_80', 'kitchen_ticket', 'simple_a4' ); return in_array( $value, $allowed, true ) ? $value : 'receipt_80'; } /** * Sanitize print paper width. * * @param mixed $value Raw value. * @return string */ private function sanitize_print_paper_width( $value ) { $value = strtolower( trim( (string) $value ) ); if ( in_array( $value, array( '58', '80', 'a4' ), true ) ) { return $value; } return '80'; } /** * Sanitize print font size. * * @param mixed $value Raw value. * @return string */ private function sanitize_print_font_size( $value ) { $value = sanitize_key( (string) $value ); $allowed = array( 'small', 'medium', 'large' ); return in_array( $value, $allowed, true ) ? $value : 'medium'; } /** * Sanitize print density. * * @param mixed $value Raw value. * @return string */ private function sanitize_print_density( $value ) { $value = sanitize_key( (string) $value ); $allowed = array( 'compact', 'normal', 'comfortable' ); return in_array( $value, $allowed, true ) ? $value : 'normal'; } /** * Resolve native store fields from WordPress and WooCommerce options. * * @return array */ private function get_native_store_data() { $currency = sanitize_text_field( (string) get_option( 'woocommerce_currency', '' ) ); if ( '' !== $currency ) { $currency = strtoupper( $currency ); } return array( 'store_name' => sanitize_text_field( (string) get_option( 'blogname', get_bloginfo( 'name' ) ) ), 'slogan' => sanitize_text_field( (string) get_option( 'blogdescription', get_bloginfo( 'description' ) ) ), 'admin_email' => sanitize_email( (string) get_option( 'admin_email', '' ) ), 'address_line_1'=> sanitize_text_field( (string) get_option( 'woocommerce_store_address', '' ) ), 'address_line_2'=> sanitize_text_field( (string) get_option( 'woocommerce_store_address_2', '' ) ), 'city' => sanitize_text_field( (string) get_option( 'woocommerce_store_city', '' ) ), 'postcode' => sanitize_text_field( (string) get_option( 'woocommerce_store_postcode', '' ) ), 'country_state' => sanitize_text_field( (string) get_option( 'woocommerce_default_country', '' ) ), 'currency' => $currency, 'contact_phone' => sanitize_text_field( (string) get_option( 'woocommerce_store_phone', '' ) ), ); } /** * Build legacy single-line address for compatibility consumers. * * @param array $settings Settings payload. * @return string */ private function build_legacy_address( $settings ) { $parts = array( isset( $settings['address_line_1'] ) ? sanitize_text_field( (string) $settings['address_line_1'] ) : '', isset( $settings['address_line_2'] ) ? sanitize_text_field( (string) $settings['address_line_2'] ) : '', isset( $settings['city'] ) ? sanitize_text_field( (string) $settings['city'] ) : '', isset( $settings['postcode'] ) ? sanitize_text_field( (string) $settings['postcode'] ) : '', isset( $settings['country_state'] ) ? sanitize_text_field( (string) $settings['country_state'] ) : '', ); $parts = array_values( array_filter( $parts, static function ( $part ) { return '' !== (string) $part; } ) ); return implode( ', ', $parts ); } /** * Resolve default generic contact channel. * * @param string $phone Native phone. * @param string $email Native admin email. * @return string */ private function resolve_default_contact_channel( $phone, $email ) { $phone = sanitize_text_field( (string) $phone ); $email = sanitize_email( (string) $email ); if ( '' !== $phone ) { return 'phone'; } if ( '' !== $email ) { return 'email'; } return 'other'; } /** * Resolve default generic contact value. * * @param string $channel Contact channel. * @param string $phone Native phone. * @param string $email Native email. * @return string */ private function resolve_default_contact_value( $channel, $phone, $email ) { $channel = $this->sanitize_contact_channel( $channel ); $phone = sanitize_text_field( (string) $phone ); $email = sanitize_email( (string) $email ); if ( in_array( $channel, array( 'phone', 'whatsapp', 'sms' ), true ) ) { if ( '' !== $phone ) { return $phone; } } if ( 'email' === $channel && '' !== $email ) { return $email; } if ( '' !== $phone ) { return $phone; } return $email; } /** * Sanitize generic contact channel. * * @param mixed $value Raw value. * @return string */ private function sanitize_contact_channel( $value ) { $value = sanitize_key( (string) $value ); return in_array( $value, $this->contact_channels, true ) ? $value : 'other'; } /** * Pick raw input field preserving current value when key is absent. * * @param array $input Input payload. * @param string $key Field key. * @param mixed $fallback Fallback value. * @return mixed */ private function pick_input_value( $input, $key, $fallback = '' ) { if ( ! array_key_exists( $key, $input ) ) { return $fallback; } return wp_unslash( $input[ $key ] ); } } if ( ! function_exists( 'abct_get_store_settings' ) ) { /** * Backward-compatible store settings accessor. * * @return array */ function abct_get_store_settings() { $service = new ABCT_Settings_Service(); return $service->get(); } }