true, "short_description" => true, "description" => true, ]; public function toggle() { return null; } public function get() { $value = get_option(self::OPTION_NAME, null); if ($value === null) { return self::DEFAULT_FIELDS; } return json_decode($value, true); } public function validate($v): bool { if (!is_array($v) && !is_object($v)) { return false; } return true; } public function set($value) { if (!$this->validate($value)) { throw new \Exception("Only array or object values are accepted for sync_fields setting"); } // Merge with defaults to ensure all fields are present $fields = array_merge(self::DEFAULT_FIELDS, (array) $value); update_option(self::OPTION_NAME, json_encode($fields)); return $this->get(); } private static $cachedFields = null; /** * Verifica se un campo specifico deve essere sincronizzato. * * @param string $field_name Nome del campo (es. "short_description", "description") * @return bool True se il campo deve essere sincronizzato, false altrimenti */ public static function shouldSyncField($field_name) { if (self::$cachedFields === null) { $value = get_option(self::OPTION_NAME, null); self::$cachedFields = ($value === null) ? self::DEFAULT_FIELDS : json_decode($value, true); } return isset(self::$cachedFields[$field_name]) ? (bool) self::$cachedFields[$field_name] : true; } } }