fix: lit/divi-presets-set – name und rename schließen sich aus, Namensprüfung vorziehen
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
b3c3e69a53
commit
25720ad086
@@ -236,6 +236,17 @@ final class DiviPresetsSetAbility implements Ability
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($existing === null && isset($item['rename'])) {
|
||||
$errors[$field . '.rename'] = 'nur zusammen mit preset; für ein neues Preset name verwenden';
|
||||
|
||||
return null;
|
||||
}
|
||||
if ($existing !== null && isset($item['name'])) {
|
||||
$errors[$field . '.name'] = 'zum Umbenennen rename verwenden';
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (['name' => $existing === null, 'rename' => $existing !== null] as $key => $applies) {
|
||||
if (! $applies || ! is_string($item[$key] ?? null)) {
|
||||
continue;
|
||||
@@ -269,10 +280,12 @@ final class DiviPresetsSetAbility implements Ability
|
||||
/** Plain text of 1 to 100 characters, or null (ruling: preset names). */
|
||||
private function cleanName(string $name): ?string
|
||||
{
|
||||
if (strlen($name) > self::NAME_MAX * 4) {
|
||||
return null;
|
||||
}
|
||||
$clean = sanitize_text_field($name);
|
||||
$length = function_exists('mb_strlen') ? mb_strlen($clean) : strlen($clean);
|
||||
|
||||
return $clean === '' || $length > self::NAME_MAX || strlen($name) > self::NAME_MAX * 4 ? null : $clean;
|
||||
return $clean === '' || mb_strlen($clean) > self::NAME_MAX ? null : $clean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user