Skip to content

Instantly share code, notes, and snippets.

@shaunpalmer
Forked from iwek/save_wp_error.php
Last active September 16, 2024 05:00
Show Gist options
  • Save shaunpalmer/18799399a960b07f3b7998782ea5470e to your computer and use it in GitHub Desktop.
Save shaunpalmer/18799399a960b07f3b7998782ea5470e to your computer and use it in GitHub Desktop.
Send WordPress Plugin Activation Errors to a File
<?php
# error_log('Red Alert: Shields failing! Code malfunction in sector 42.');
add_action('activated_plugin', 'save_error_to_log');
function save_error_to_log() {
// Get the error message (if any) during plugin activation
$error_message = ob_get_contents();
// Define the log file path (adjust as needed)
$log_file_path = ABSPATH . 'wp-content/plugins/PLUGIN_FOLDER/plugin_activation.log';
// Append the error message to the log file
file_put_contents($log_file_path, $error_message, FILE_APPEND);
// Clear the output buffer
ob_clean();
}
?>
@shaunpalmer
Copy link
Author

Star Trek Analogy (because why not?):
Think of this snippet as the USS Enterprise’s logbook. Whenever a new crew member (plugin) comes aboard, Captain WordPress makes a note of any strange occurrences. “Stardate 2024.09.15: Plugin ‘@ YourPlugin ’ activated. Spock raised an eyebrow. McCoy grumbled about missing semicolons. All systems nominal… for now.”
Remember, even in the vastness of code, there’s always room for improvement. 🚀 If you have any specific tweaks in mind or need further assistance, just let me know! Live long and debug! 🖖😄

Captain’s Log (Stardate 2024.09.15):

“Plugin ‘CleanSweep’ activated. Scotty grumbled about missing semicolons. Spock raised an eyebrow. All systems nominal… except for that pesky whitespace issue in line 42.”

“Scotty’s Scottish Accent” Flavor: error_log("Captain, I cannae change the laws of PHP! But I found a bug in the dilithium matrix (line 23).");

Feel free to adapt this snippet to your needs, and may your logs be as organized as a well-arranged bookshelf! 📚🔍
Engage warp drive to productivity… 🚀🖖

P.S. If you’d like, we can also discuss how Data’s cat, Spot, would handle PHP errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment