| @@ -157,11 +157,25 @@ | ||
| 157 | 157 | if ($attrs->scale->isNotEmpty()) { |
| 158 | 158 | $blockAttrs['scale'] = $attrs->scale->dangerouslyUseRawValue(); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | + // block_core_image_render_lightbox() type-hints a real WP_Block, not | |
| 162 | + // just any object with a `context` property — a plain stdClass | |
| 163 | + // fatals with a TypeError. Reusing the registered `core/image` name | |
| 164 | + // gives it a real block type without side effects: the function | |
| 165 | + // only reads `$block_instance->context`, which stays empty here | |
| 166 | + // same as it would for a standalone (non-gallery) image. | |
| 167 | + $blockInstance = class_exists('WP_Block') | |
| 168 | + ? new \WP_Block(['blockName' => 'core/image', 'attrs' => $blockAttrs]) | |
| 169 | + : null; | |
| 170 | + | |
| 171 | + if (!$blockInstance) { | |
| 172 | + return $figureHtml; | |
| 173 | + } | |
| 174 | + | |
| 161 | 175 | return \block_core_image_render_lightbox( |
| 162 | 176 | $figureHtml, |
| 163 | 177 | ['attrs' => $blockAttrs], |
| 164 | - (object) ['context' => []] | |
| 178 | + $blockInstance | |
| 165 | 179 | ); |
| 166 | 180 | } |
| 167 | 181 | } |