urn array(); } $dto = $this->{$method}(); $enabled_locations = $this->get_messaging_locations(); if ('shop' === $location || 'home' === $location) { return array('layout' => $dto->layout, 'color' => $dto->flex_color, 'ratio' => $dto->flex_ratio, 'status' => in_array($location, $enabled_locations, \true) ? 'enabled' : 'disabled', 'placement' => $location); } if ('custom_placement' === $location) { return array('status' => in_array('custom_placement', $enabled_locations, \true) ? 'enabled' : 'disabled', 'message_reference' => 'woocommerceBlock'); } return array('layout' => $dto->layout, 'logo-position' => $dto->logo_position, 'logo-type' => $dto->logo_type, 'text-color' => $dto->text_color, 'text-size' => $dto->text_size, 'status' => in_array($location, $enabled_locations, \true) ? 'enabled' : 'disabled', 'placement' => $location); } /** * Updates a location's settings from configurator config array. * * @param string $location The location name. * @param array $config The configurator config. */ public function set_location_from_config(string $location, array $config): void { $method = "get_{$location}"; if (!method_exists($this, $method)) { return; } $dto = $this->{$method}(); if (isset($config['layout'])) { $dto->layout = $this->sanitizer->sanitize_text($config['layout'], 'text'); } if (isset($config['logo-position'])) { $dto->logo_position = $this->sanitizer->sanitize_text($config['logo-position'], 'left'); } if (isset($config['logo-type'])) { $dto->logo_type = $this->sanitizer->sanitize_text($config['logo-type'], 'inline'); } if (isset($config['text-color']) || isset($config['logo-color'])) { $dto->text_color = $this->sanitizer->sanitize_text($config['text-color'] ?? $config['logo-color'] ?? 'black', 'black'); } if (isset($config['text-size'])) { $dto->text_size = $this->sanitizer->sanitize_text($config['text-size'], '12'); } if (isset($config['color'])) { $dto->flex_color = $this->sanitizer->sanitize_text($config['color'], 'black'); } if (isset($config['ratio'])) { $dto->flex_ratio = $this->sanitizer->sanitize_text($config['ratio'], '8x1'); } $setter = "set_{$location}"; $this->{$setter}($dto); } /** * Sanitizes Pay Later messaging data, overriding the enabled flag * based on the current messaging locations list. * * @param mixed $data The messaging data to sanitize. * @param ?string $location Name of the location. * @return PayLaterMessagingDTO Sanitized messaging data. */ private function sanitize_paylater_messaging($data, ?string $location = null): PayLaterMessagingDTO { $dto = $this->sanitizer->sanitize_paylater_messaging($data, $location); $dto->enabled = in_array($dto->location, $this->get_messaging_locations(), \true); return $dto; } private function maybe_migrate_from_legacy(): void { $has_new_data = get_option(static::OPTION_KEY); if (\false !== $has_new_data && !empty($has_new_data)) { return; } $legacy_settings = (array) get_option(self::LEGACY_OPTION_KEY, array()); if (empty($legacy_settings)) { return; } $this->data['messaging_enabled'] = !empty($legacy_settings['pay_later_messaging_enabled']); $this->data['styling_per_location'] = !empty($legacy_settings['pay_later_enable_styling_per_messaging_location']); $locations = $legacy_settings['pay_later_messaging_locations'] ?? array(); if (is_array($locations)) { $this->data['messaging_locations'] = $locations; } $location_map = array('cart' => 'cart', 'checkout' => 'checkout', 'product' => 'product', 'shop' => 'shop', 'home' => 'home', 'custom_placement' => 'custom_placement'); foreach ($location_map as $location => $key) { $prefix = "pay_later_{$location}_message"; $this->data[$key] = new PayLaterMessagingDTO($location, in_array($location, $this->data['messaging_locations'], \true), $legacy_settings["{$prefix}_layout"] ?? (in_array($location, array('shop', 'home'), \true) ? 'flex' : 'text'), $legacy_settings["{$prefix}_logo"] ?? 'inline', $legacy_settings["{$prefix}_position"] ?? 'left', $legacy_settings["{$prefix}_color"] ?? 'black', $legacy_settings["{$prefix}_text_size"] ?? '12', $legacy_settings["{$prefix}_flex_color"] ?? 'black', $legacy_settings["{$prefix}_flex_ratio"] ?? '8x1'); } $this->save(); } }