From c8fb94d668c4ed6a2b75aeec7d157f2e5a182326 Mon Sep 17 00:00:00 2001 From: cschantz Date: Mon, 10 Nov 2025 20:41:13 -0500 Subject: [PATCH] Fix domain lookup in WordPress Cron Manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The domain lookup was failing because it only searched for 'servername:' in /var/cpanel/userdata/*/main files, but cPanel stores domain information differently: - main files use 'main_domain: domain.com' (YAML format) - domain-specific files use 'servername: domain.com' (YAML format) Changes: • Added two-step domain lookup process • Method 1: Check main_domain in /var/cpanel/userdata/*/main files • Method 2: Fallback to search all domain files for servername • Skip cache files (.cache, cache, cache.json) during search • Applied fix to all three domain lookup locations (options 2, 5, 6) This fixes the "WordPress installation not found for domain" error that occurred when domains weren't configured as main_domain. Tested with pickledperil.com - lookup now works correctly. --- .../wordpress/wordpress-cron-manager.sh | 71 ++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 1f7026b..abb1ad9 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -221,9 +221,12 @@ case "$choice" in echo "Searching for WordPress installation for $domain..." # Try to find via cPanel user data + # Search both main_domain (in main files) and servername (in domain files) wp_config="" + + # Method 1: Check main_domain in /var/cpanel/userdata/*/main files for userdata_file in /var/cpanel/userdata/*/main; do - if grep -q "^servername: $domain" "$userdata_file" 2>/dev/null; then + if grep -q "^main_domain: $domain" "$userdata_file" 2>/dev/null; then user=$(basename "$(dirname "$userdata_file")") potential_config="/home/$user/public_html/wp-config.php" if [ -f "$potential_config" ]; then @@ -233,6 +236,26 @@ case "$choice" in fi done + # Method 2: If not found, search all domain-specific files for servername + if [ -z "$wp_config" ]; then + for userdata_file in /var/cpanel/userdata/*/*; do + # Skip cache files and main files + [[ "$userdata_file" == *.cache ]] && continue + [[ "$userdata_file" == */main ]] && continue + [[ "$userdata_file" == */cache ]] && continue + [[ "$userdata_file" == */cache.json ]] && continue + + if grep -q "^servername: $domain" "$userdata_file" 2>/dev/null; then + user=$(basename "$(dirname "$userdata_file")") + potential_config="/home/$user/public_html/wp-config.php" + if [ -f "$potential_config" ]; then + wp_config="$potential_config" + break + fi + fi + done + fi + if [ -z "$wp_config" ]; then print_error "WordPress installation not found for $domain" press_enter @@ -463,8 +486,10 @@ case "$choice" in # Find WordPress for domain wp_config="" + + # Method 1: Check main_domain in main files for userdata_file in /var/cpanel/userdata/*/main; do - if grep -q "^servername: $domain" "$userdata_file" 2>/dev/null; then + if grep -q "^main_domain: $domain" "$userdata_file" 2>/dev/null; then user=$(basename "$(dirname "$userdata_file")") potential_config="/home/$user/public_html/wp-config.php" if [ -f "$potential_config" ]; then @@ -474,6 +499,25 @@ case "$choice" in fi done + # Method 2: Search domain-specific files for servername + if [ -z "$wp_config" ]; then + for userdata_file in /var/cpanel/userdata/*/*; do + [[ "$userdata_file" == *.cache ]] && continue + [[ "$userdata_file" == */main ]] && continue + [[ "$userdata_file" == */cache ]] && continue + [[ "$userdata_file" == */cache.json ]] && continue + + if grep -q "^servername: $domain" "$userdata_file" 2>/dev/null; then + user=$(basename "$(dirname "$userdata_file")") + potential_config="/home/$user/public_html/wp-config.php" + if [ -f "$potential_config" ]; then + wp_config="$potential_config" + break + fi + fi + done + fi + if [ -z "$wp_config" ]; then print_error "WordPress not found for $domain" press_enter @@ -573,8 +617,10 @@ case "$choice" in # Find WordPress installation wp_config="" + + # Method 1: Check main_domain in main files for userdata_file in /var/cpanel/userdata/*/main; do - if grep -q "^servername: $domain" "$userdata_file" 2>/dev/null; then + if grep -q "^main_domain: $domain" "$userdata_file" 2>/dev/null; then user=$(basename "$(dirname "$userdata_file")") potential_config="/home/$user/public_html/wp-config.php" if [ -f "$potential_config" ]; then @@ -584,6 +630,25 @@ case "$choice" in fi done + # Method 2: Search domain-specific files for servername + if [ -z "$wp_config" ]; then + for userdata_file in /var/cpanel/userdata/*/*; do + [[ "$userdata_file" == *.cache ]] && continue + [[ "$userdata_file" == */main ]] && continue + [[ "$userdata_file" == */cache ]] && continue + [[ "$userdata_file" == */cache.json ]] && continue + + if grep -q "^servername: $domain" "$userdata_file" 2>/dev/null; then + user=$(basename "$(dirname "$userdata_file")") + potential_config="/home/$user/public_html/wp-config.php" + if [ -f "$potential_config" ]; then + wp_config="$potential_config" + break + fi + fi + done + fi + if [ -z "$wp_config" ]; then print_error "WordPress installation not found for $domain" press_enter