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