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,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
|
||||
|
||||
Reference in New Issue
Block a user