Fix domain lookup in WordPress Cron Manager
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.
This commit is contained in:
@@ -221,8 +221,30 @@ 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 "^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
|
||||
wp_config="$potential_config"
|
||||
break
|
||||
fi
|
||||
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"
|
||||
@@ -232,6 +254,7 @@ case "$choice" in
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$wp_config" ]; then
|
||||
print_error "WordPress installation not found for $domain"
|
||||
@@ -463,7 +486,27 @@ 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 "^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
|
||||
wp_config="$potential_config"
|
||||
break
|
||||
fi
|
||||
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"
|
||||
@@ -473,6 +516,7 @@ case "$choice" in
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$wp_config" ]; then
|
||||
print_error "WordPress not found for $domain"
|
||||
@@ -573,7 +617,27 @@ 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 "^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
|
||||
wp_config="$potential_config"
|
||||
break
|
||||
fi
|
||||
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"
|
||||
@@ -583,6 +647,7 @@ case "$choice" in
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$wp_config" ]; then
|
||||
print_error "WordPress installation not found for $domain"
|
||||
|
||||
Reference in New Issue
Block a user