'', 'logo_url' => '', 'hero_image' => '', 'background_color' => '#141f31', 'button_label' => __('Add to Wallet', 'addtowallet-for-bookly'), 'allowed_statuses' => ['approved'], 'expire_statuses' => ['cancelled', 'rejected'], 'barcode_type' => 'QR_CODE', 'debug' => 0, 'template' => ATW_Bookly_Template::defaults(), ]; } /** * Saved settings over the defaults. The template is normalised on every read: an * install without one (a fresh install, or settings imported from the 1.x zip) gets * the default template, and a damaged one is repaired rather than trusted. */ public static function get() { $saved = get_option(self::OPTION, []); if (!is_array($saved)) { $saved = []; } $all = array_merge(self::defaults(), $saved); $all['template'] = ATW_Bookly_Template::normalize(isset($saved['template']) ? $saved['template'] : null); if (!in_array($all['barcode_type'], self::BARCODE_TYPES, true)) { $all['barcode_type'] = 'QR_CODE'; } $colour = self::normalize_hex($all['background_color']); $all['background_color'] = $colour !== '' ? $colour : '#141f31'; $all['allowed_statuses'] = array_values(array_intersect(self::ISSUABLE_STATUSES, (array) $all['allowed_statuses'])); $all['expire_statuses'] = array_values(array_intersect(self::EXPIRABLE_STATUSES, (array) $all['expire_statuses'])); return $all; } /** * A colour code as "#rrggbb", or '' when it is not one. Accepts the forms people type: * with or without "#", and the three-digit shorthand, which is expanded because the * colour picker only understands six digits. */ public static function normalize_hex($value) { $hex = ltrim(trim((string) $value), '#'); if (preg_match('/^[0-9a-f]{3}$/i', $hex)) { $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; } $colour = sanitize_hex_color('#' . strtolower($hex)); return $colour && strlen($colour) === 7 ? $colour : ''; } public static function value($key) { $all = self::get(); return isset($all[$key]) ? $all[$key] : null; } /** * Merges already-sanitised values into the stored option. * * @param array $changes key => value */ public static function update(array $changes) { $saved = get_option(self::OPTION, []); if (!is_array($saved)) { $saved = []; } update_option(self::OPTION, array_merge($saved, $changes)); } /** * First activation: settings from the 1.x zip are imported if there are any, otherwise * the defaults are stored. */ public static function on_activate() { ATW_Bookly_Legacy::maybe_import(); if (get_option(self::OPTION) === false) { add_option(self::OPTION, self::defaults()); } } /** Plain-English names for the barcode formats the API accepts. */ public static function barcode_label($type) { $labels = [ 'QR_CODE' => __('QR code', 'addtowallet-for-bookly'), 'AZTEC' => __('Aztec', 'addtowallet-for-bookly'), 'PDF_417' => __('PDF417', 'addtowallet-for-bookly'), 'CODE_128' => __('Code 128', 'addtowallet-for-bookly'), 'NONE' => __('None', 'addtowallet-for-bookly'), ]; return isset($labels[$type]) ? $labels[$type] : $type; } public static function status_label($status) { return ATW_Bookly_Template::status_label($status); } public static function status_hint($status) { $hints = [ 'approved' => __('Confirmed bookings. Recommended.', 'addtowallet-for-bookly'), 'pending' => __('Waiting for you to approve them (services set to need approval). They may still be rejected.', 'addtowallet-for-bookly'), 'waitlisted' => __('On a waiting list (Bookly Pro). They may never get a place.', 'addtowallet-for-bookly'), 'cancelled' => __('Cancelled by you, or by the customer through their cancel link. Deleting a booking counts as cancelling it.', 'addtowallet-for-bookly'), 'rejected' => __('Rejected by you or a staff member.', 'addtowallet-for-bookly'), 'done' => __('Marked as done after the appointment.', 'addtowallet-for-bookly'), ]; return isset($hints[$status]) ? $hints[$status] : ''; } }