Created
April 24, 2024 01:15
-
-
Save roymckenzie/b55575c63e3f987465512f80aa585ef0 to your computer and use it in GitHub Desktop.
wpdebug.sh - WordPress Debugging Shell Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script Name: Script Name: wpdebug.sh | |
# Description: A script for enabling or disabling WordPress debugging mode in the wp-config.php file. | |
# Author: Roy McKenzie | |
# Date: April 23, 2024 | |
# Version: 1.0 | |
# | |
# Usage: ./wpdebug.sh [install|uninstall|enable|disable|tail|delete] | |
# | |
# Options: | |
# install Add alias 'wpdebug' for this script in .bashrc | |
# uninstall Remove alias 'wpdebug' for this script from .bashrc | |
# enable Enable WordPress debugging by setting WP_DEBUG to true in wp-config.php | |
# tail Tail the log located at wp-content/debug.log | |
# delete Delete the log located at wp-content/debug.log | |
# | |
# Example: ./wpdebug.sh enable | |
# | |
# Notes: | |
# - This script modifies the wp-config.php file. Make sure to back up your wp-config.php file before running this script. | |
# - Requires WP-CLI to be installed and configured on your system. | |
# - this plugin should be installed in the root of your WordPress installation. | |
# | |
# Enable Debugging | |
enable_debug() { | |
wp config set WP_DEBUG true --raw | |
wp config set WP_DEBUG_LOG true --raw | |
wp config set WP_DEBUG_DISPLAY false --raw | |
echo 'Debugging enabled in wp-config.php.' | |
} | |
# Disable Debugging | |
disable_debug() { | |
wp config set WP_DEBUG false --raw | |
wp config set WP_DEBUG_LOG false --raw | |
wp config set WP_DEBUG_DISPLAY false --raw | |
echo 'Debugging disabled in wp-config.php.' | |
} | |
# Install alias | |
install() { | |
echo "alias wpdebug=\"$(pwd)/wpdebug.sh\"" >> ~/.bashrc | |
echo "Alias $(tput bold)wpdebug$(tput sgr0) added. Run $(tput bold)source ~/.bashrc$(tput sgr0) to reload bash configuration and enable alias." | |
} | |
# Uninstall alias | |
uninstall() { | |
if [ $(uname) == 'Darwin' ]; then | |
sed -i '' '/^alias wpdebug=/d' ~/.bashrc | |
else | |
sed -i '/^alias wpdebug=/d' ~/.bashrc | |
fi | |
echo 'Alias removed.' | |
} | |
# Tail log live | |
tail_log() { | |
echo 'Tailing log...' | |
clear | |
tail -f wp-content/debug.log | |
} | |
# Delete log | |
delete_log() { | |
rm wp-content/debug.log | |
echo 'Debug log deleted.' | |
} | |
# Check if WP CLI is installed | |
if ! [ -x "$(command -v wp)" ]; then | |
echo 'Error: WP-CLI is not installed. Please install it.' >&2 | |
exit 1 | |
fi | |
# Check if wp-config.php exists | |
if [ ! -f "wp-config.php" ] && [ "$1" != "install" ] && [ "$1" != "uninstall" ]; then | |
echo 'Error: wp-config.php not found.' | |
exit 1 | |
fi | |
# Check the first argument | |
case "$1" in | |
"install") | |
install | |
;; | |
"uninstall") | |
uninstall | |
;; | |
"enable") | |
enable_debug | |
;; | |
"disable") | |
disable_debug | |
;; | |
"tail") | |
tail_log | |
;; | |
"delete") | |
delete_log | |
;; | |
*) | |
echo "Usage: $0 [install|uninstall|enable|disable|tail|delete]" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment