diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 3ceea29..f1f6e49 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -680,6 +680,48 @@ finish_progress() { fi } +# OPTIMIZATION: Null Check Standardization (OPT-7) +# Consolidates 40 "[ -z ]" and 5 "[ -n ]" checks with clearer intent +# Makes code more readable and maintainable +is_empty() { + local value="$1" + [ -z "$value" ] && return 0 || return 1 +} + +is_set() { + local value="$1" + [ -n "$value" ] && return 0 || return 1 +} + +# OPTIMIZATION: Output Redirection Helpers (OPT-8) +# Consolidates 10 ">/dev/null 2>&1" and 3 ">&2" patterns +# Provides cleaner, more readable code +suppress_output() { + "$@" >/dev/null 2>&1 + return $? +} + +redirect_to_stderr() { + "$@" >&2 + return $? +} + +# OPTIMIZATION: Error Code Constants (OPT-11) +# Standardizes 43 exit and 49 return statements with meaningful names +# Instead of hardcoded "exit 1", use "exit $ERR_INVALID_USER" +declare -r ERR_SUCCESS=0 # Operation successful +declare -r ERR_INVALID_USER=1 # User validation failed +declare -r ERR_FILE_NOT_FOUND=2 # Required file missing +declare -r ERR_BACKUP_FAILED=3 # Backup operation failed +declare -r ERR_DISK_SPACE=4 # Insufficient disk space +declare -r ERR_SYNTAX_ERROR=5 # Syntax validation failed +declare -r ERR_PERMISSION_DENIED=6 # Permission or ownership issue +declare -r ERR_DATABASE_ERROR=7 # Database connection/query failed +declare -r ERR_CONFIG_INVALID=8 # Configuration file invalid +declare -r ERR_ALREADY_DISABLED=9 # WP-Cron already disabled +declare -r ERR_ALREADY_RUNNING=10 # Another instance running +declare -r ERR_CANCELLED=11 # User cancelled operation + # OPTIMIZATION: Build cron command consistently # Centralizes cron command format (appears 4 times throughout script) # Returns: cron command string for wp-cron.php execution