| @@ -87,9 +87,11 @@ | ||
| 87 | 87 | $style = $tp->get_attribute('style'); |
| 88 | 88 | if (is_string($style) && stripos($style, 'background-image') !== false) { |
| 89 | 89 | $tp->set_attribute('style', preg_replace_callback( |
| 90 | 90 | '/background-image\s*:\s*url\([^)]*\)/i', |
| 91 | - static fn () => 'background-image:url(' . $url . ')', | |
| 91 | + static function () use ($url) { | |
| 92 | + return 'background-image:url(' . $url . ')'; | |
| 93 | + }, | |
| 92 | 94 | $style |
| 93 | 95 | )); |
| 94 | 96 | $patched = true; |
| 95 | 97 | } |
| @@ -101,22 +103,19 @@ | ||
| 101 | 103 | if ($alt !== null) { |
| 102 | 104 | $tp->set_attribute('alt', $alt); |
| 103 | 105 | } |
| 104 | 106 | |
| 105 | - // Gutenberg's media-text save() derives wp-image-{id} from | |
| 106 | - // attrs.mediaId; a mismatch trips the validator. Strip any | |
| 107 | - // pre-existing first so re-edits don't stack. | |
| 108 | - $cls = (string) ($tp->get_attribute('class') ?? ''); | |
| 109 | - $cls = trim((string) preg_replace('/\bwp-image-\d+\b/', '', $cls)); | |
| 107 | + // Core's save() derives wp-image-{id} + size-{mediaSizeSlug||full} | |
| 108 | + // from attrs; mismatched markup trips the block validator. | |
| 109 | + foreach ($tp->class_list() as $class) { | |
| 110 | + if (str_starts_with($class, 'wp-image-') || str_starts_with($class, 'size-')) { | |
| 111 | + $tp->remove_class($class); | |
| 112 | + } | |
| 113 | + } | |
| 110 | 114 | if ($id !== null && $id > 0) { |
| 111 | - $cls = trim($cls . ' wp-image-' . $id); | |
| 115 | + $tp->add_class('wp-image-' . $id); | |
| 116 | + $tp->add_class('size-' . ($attrs['mediaSizeSlug'] ?? 'full')); | |
| 112 | 117 | } |
| 113 | - $cls = (string) preg_replace('/\s{2,}/', ' ', $cls); | |
| 114 | - if ($cls === '') { | |
| 115 | - $tp->remove_attribute('class'); | |
| 116 | - } else { | |
| 117 | - $tp->set_attribute('class', $cls); | |
| 118 | - } | |
| 119 | 118 | |
| 120 | 119 | if ($id === null || $id <= 0) { |
| 121 | 120 | $tp->remove_attribute('srcset'); |
| 122 | 121 | $tp->remove_attribute('sizes'); |
| @@ -130,9 +129,11 @@ | ||
| 130 | 129 | $innerContent[$i] = $patchedChunk; |
| 131 | 130 | $block['innerContent'] = $innerContent; |
| 132 | 131 | // Inspection-only; the serializer rebuilds innerHTML from innerContent. |
| 133 | 132 | $block['innerHTML'] = implode('', array_map( |
| 134 | - static fn ($c) => is_string($c) ? $c : '', | |
| 133 | + static function ($c) { | |
| 134 | + return is_string($c) ? $c : ''; | |
| 135 | + }, | |
| 135 | 136 | $innerContent |
| 136 | 137 | )); |
| 137 | 138 | break; |
| 138 | 139 | } |
| @@ -150,9 +151,11 @@ | ||
| 150 | 151 | return $attrs; |
| 151 | 152 | } |
| 152 | 153 | $classes = array_filter( |
| 153 | 154 | preg_split('/\s+/', $attrs['className']) ?: [], |
| 154 | - static fn ($c) => $c !== '' && $c !== 'extendify-image-import' | |
| 155 | + static function ($c) { | |
| 156 | + return $c !== '' && $c !== 'extendify-image-import'; | |
| 157 | + } | |
| 155 | 158 | ); |
| 156 | 159 | if ($classes) { |
| 157 | 160 | $attrs['className'] = implode(' ', $classes); |
| 158 | 161 | } else { |