| @@ -229,8 +229,31 @@ | ||
| 229 | 229 | return WINP_Plugin::app()->get_execute_object()->prepareCode( $snippet_code, $id ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | + * Report a top-level declaration the snippet would redeclare instead of evaluating it. | |
| 234 | + * | |
| 235 | + * Repeated placements of one snippet re-evaluate it, and a redeclaration inside | |
| 236 | + * eval() ends the request. Clears the current snippet context when reporting. | |
| 237 | + * | |
| 238 | + * @param string $snippet_content Snippet code. | |
| 239 | + * @param string $snippet_type Snippet type. | |
| 240 | + * | |
| 241 | + * @return string|null Error output, or null when the snippet can be evaluated. | |
| 242 | + */ | |
| 243 | + protected function render_redeclaration_error( string $snippet_content, string $snippet_type ): ?string { | |
| 244 | + $redeclaration_error = WINP_Code_Validator::get_redeclaration_error( $snippet_content, $snippet_type ); | |
| 245 | + if ( null === $redeclaration_error ) { | |
| 246 | + return null; | |
| 247 | + } | |
| 248 | + | |
| 249 | + $error_output = WINP_Error_Handler::handle_exception( $redeclaration_error ); | |
| 250 | + WINP_Error_Handler::clear_current_snippet(); | |
| 251 | + | |
| 252 | + return $error_output; | |
| 253 | + } | |
| 254 | + | |
| 255 | + /** | |
| 233 | 256 | * Content render |
| 234 | 257 | * |
| 235 | 258 | * @param array<string, mixed> $attr Shortcode attributes. |
| 236 | 259 | * @param string $content Shortcode content. |