diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index e2699da..538cc62 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -336,24 +336,26 @@ extract_user_from_path() { cpanel) # Extract user from /home/username/public_html pattern user=$(echo "$site_path" | awk -F'/' '{print $3}') - [ -z "$user" ] && user="www-data" ;; interworx) # Extract user from /home/username/domain/html pattern user=$(echo "$site_path" | awk -F'/' '{print $3}') - [ -z "$user" ] && user="www-data" ;; plesk) # Extract domain from path and lookup user local domain=$(echo "$site_path" | grep -oE '/vhosts/[^/]+' | sed 's|/vhosts/||') user=$(plesk bin subscription --info "$domain" 2>/dev/null | grep "Owner" | awk '{print $2}') - [ -z "$user" ] && user="www-data" # Plesk fallback ;; *) - user="www-data" # Standalone fallback + user="www-data" ;; esac + # CRITICAL FIX: Validate user is not empty - prevents adding cron to wrong user + if [ -z "$user" ]; then + user="www-data" # Fallback only if extraction completely failed + fi + echo "$user" } @@ -370,7 +372,8 @@ disable_wpcron_in_config() { # First, remove any existing DISABLE_WP_CRON lines (anywhere in file) # This ensures clean placement even if previously added in wrong location if grep -q "DISABLE_WP_CRON" "$wp_config" 2>/dev/null; then - sed -i.wpbak "#define\s*(\s*['\"]DISABLE_WP_CRON['\"]\s*,\s*true\s*)#d" "$wp_config" + # CRITICAL FIX: Use -E flag for extended regex patterns with \s + sed -i.wpbak -E '#define[[:space:]]*\([[:space:]]*['\''"]DISABLE_WP_CRON['\''"][[:space:]]*,[[:space:]]*true[[:space:]]*\)#d' "$wp_config" else # Create backup even if no existing line cp "$wp_config" "${wp_config}.wpbak" @@ -379,12 +382,12 @@ disable_wpcron_in_config() { # Now add it in the proper location - before "stop editing" comment if grep -q "stop editing" "$wp_config" 2>/dev/null; then # Add before "stop editing" line (proper WordPress convention) - sed -i "#stop editing#i\\ -define('DISABLE_WP_CRON', true);" "$wp_config" + sed -i '#stop editing#i\ +define('"'"'DISABLE_WP_CRON'"'"', true);' "$wp_config" elif grep -q "/dev/null 2>&1; then + if grep -E "^[^/]*define[[:space:]]*\([[:space:]]*['\"]DISABLE_WP_CRON['\"][[:space:]]*,[[:space:]]*true[[:space:]]*\)" "$wp_config" >/dev/null 2>&1; then # Remove or comment out the line - sed -i.wpbak "#^[^/]*define\s*(\s*['\"]DISABLE_WP_CRON['\"]\s*,\s*true\s*)#d" "$wp_config" + # CRITICAL FIX: Use -E flag for extended regex patterns and proper character classes + sed -i.wpbak -E '#^[^/]*define[[:space:]]*\([[:space:]]*['\''"]DISABLE_WP_CRON['\''"][[:space:]]*,[[:space:]]*true[[:space:]]*\)#d' "$wp_config" # Verify removal was successful if ! grep -E "^[^/]*define\s*\(\s*['\"]DISABLE_WP_CRON['\"]\s*,\s*true\s*\)" "$wp_config" >/dev/null 2>&1; then @@ -521,24 +525,30 @@ case "$choice" in site_path=$(dirname "$config_file") # Extract user and domain based on control panel - user="(unknown)" - domain="(unknown domain)" + user="$(extract_user_from_path "$site_path")" + domain="" case "$SYS_CONTROL_PANEL" in cpanel) - user=$(extract_user_from_path "$site_path") userdata_dir="${SYS_CPANEL_USERDATA_DIR:-/var/cpanel/userdata}" if [ -f "$userdata_dir/$user/main" ]; then domain=$(grep -m1 "^servername:" "$userdata_dir/$user/main" 2>/dev/null | awk '{print $2}') fi + # CRITICAL FIX: Fallback if domain extraction failed + if [ -z "$domain" ]; then + domain="$user.local" # Use user@hostname fallback + fi ;; interworx) - user=$(extract_user_from_path "$site_path") domain=$(echo "$site_path" | cut -d'/' -f4) + # CRITICAL FIX: Fallback if domain extraction failed + if [ -z "$domain" ]; then + domain="$user.local" # Use user@hostname fallback + fi ;; plesk) domain=$(echo "$site_path" | grep -oE '/vhosts/[^/]+' | sed 's|/vhosts/||') user=$(plesk bin subscription --info "$domain" 2>/dev/null | grep "Owner" | awk '{print $2}') - [ -z "$user" ] && user="(unknown)" + [ -z "$user" ] && user="plesk-user" ;; *) user="standalone" @@ -546,6 +556,10 @@ case "$choice" in ;; esac + # Final validation: ensure neither is empty (prevents display issues) + [ -z "$user" ] && user="unknown" + [ -z "$domain" ] && domain="unknown-domain" + # Check if wp-cron is disabled if grep -q "define.*DISABLE_WP_CRON.*true" "$config_file" 2>/dev/null; then status="${GREEN}✓ Disabled (using system cron)${NC}"