Skip to content

Instantly share code, notes, and snippets.

@jmcausing
Created November 8, 2023 23:05
Show Gist options
  • Save jmcausing/a04a03b8ba451aacf4569beb4b7addc5 to your computer and use it in GitHub Desktop.
Save jmcausing/a04a03b8ba451aacf4569beb4b7addc5 to your computer and use it in GitHub Desktop.
WordPress 500 Simulation
Creating plugins intentionally causing a 500 Internal Server Error is not a common practice due to the potential risks and impact on a live website. However, for educational purposes or testing on a local or staging site, you might create custom plugins that result in an error, simulating a 500 Internal Server Error.
Here are three basic examples of custom plugins that could potentially cause a 500 Internal Server Error:
### Plugin 1: PHP Fatal Error
Create a custom plugin with PHP code that causes a fatal error.
```php
<?php
/*
Plugin Name: Fatal Error Generator
Description: Plugin to simulate a PHP Fatal Error.
*/
// Intentionally calling a non-existent function to generate a fatal error
nonexistent_function();
```
### Plugin 2: Syntax Error
Create a plugin with a syntax error in the code to simulate a 500 error.
```php
<?php
/*
Plugin Name: Syntax Error Generator
Description: Plugin to simulate a syntax error.
*/
// Intentionally adding a syntax error
echo "This is a syntax error"
```
### Plugin 3: Infinite Loop
Creating a loop that doesn't terminate can also result in a 500 error.
```php
<?php
/*
Plugin Name: Infinite Loop Generator
Description: Plugin to simulate an infinite loop.
*/
// Intentionally creating an infinite loop
while (true) {
// This loop will keep running and eventually cause a server timeout
}
```
Please use caution and create these plugins in a controlled environment, such as a local installation or staging site. After testing or demonstration, ensure to delete or deactivate these plugins to restore normal functionality. Always maintain backups before experimenting with such plugins to avoid adverse effects on your live WordPress site.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment