| @@ -1242,8 +1242,21 @@ | ||
| 1242 | 1242 | if ( empty( $snippet_code ) ) { |
| 1243 | 1243 | return true; |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | + $redeclaration = WINP_Code_Validator::find_function_redeclaration( $snippet_code, $snippet_type ); | |
| 1247 | + if ( null !== $redeclaration ) { | |
| 1248 | + $this->display_validation_error( | |
| 1249 | + $redeclaration['line'], | |
| 1250 | + sprintf( | |
| 1251 | + // translators: %s is the fully qualified function name. | |
| 1252 | + __( 'Cannot redeclare function %s(). Rename the function or guard its declaration with function_exists().', 'insert-php' ), | |
| 1253 | + $redeclaration['name'] | |
| 1254 | + ) | |
| 1255 | + ); | |
| 1256 | + return false; | |
| 1257 | + } | |
| 1258 | + | |
| 1246 | 1259 | // Set custom error handler to catch warnings and notices. |
| 1247 | 1260 | set_error_handler( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler |
| 1248 | 1261 | function ( $errno, $errstr, $errfile, $errline ) { |
| 1249 | 1262 | $error_file = $errfile; |