| @@ -310,8 +310,19 @@ | ||
| 310 | 310 | if ( empty( $snippet_code ) ) { |
| 311 | 311 | wp_send_json_success( [ 'valid' => true ] ); |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | + $redeclaration = WINP_Code_Validator::find_function_redeclaration( $snippet_code, $snippet_type ); | |
| 315 | + if ( null !== $redeclaration ) { | |
| 316 | + wp_send_json_error( | |
| 317 | + [ | |
| 318 | + 'valid' => false, | |
| 319 | + // translators: %1$d is the line number, %2$s is the fully qualified function name. | |
| 320 | + 'message' => sprintf( __( 'Line %1$d: Cannot redeclare function %2$s(). Rename the function or guard its declaration with function_exists().', 'insert-php' ), $redeclaration['line'], $redeclaration['name'] ), | |
| 321 | + ] | |
| 322 | + ); | |
| 323 | + } | |
| 324 | + | |
| 314 | 325 | // Validate using the same logic as validate_code method. |
| 315 | 326 | $validation_errors = []; |
| 316 | 327 | |
| 317 | 328 | // Set custom error handler to catch warnings and notices. |