Add revert functionality to WordPress Cron Manager
New Revert Options: - Option 6: Re-enable wp-cron for specific domain - Option 7: Re-enable wp-cron for specific user (all sites) - Option 8: Re-enable wp-cron server-wide (all sites) Revert Function Features: ✅ Safely removes DISABLE_WP_CRON from wp-config.php ✅ Automatic backup before changes ✅ Verification of successful removal ✅ Auto-rollback on failure ✅ Removes cron jobs from user crontabs ✅ Batch processing for multiple sites ✅ Summary reporting Menu Organization: - Grouped options by function (Enable/Revert/Status) - Color-coded sections (Green/Yellow/Cyan) - Clear labeling of what each option does Revert Process: 1. Backup wp-config.php 2. Remove DISABLE_WP_CRON line completely 3. Verify removal was successful 4. Remove wp-cron.php entries from user crontab 5. Provide feedback and summary Safety Features: - Won't break sites if DISABLE_WP_CRON not found - Preserves other cron jobs when removing wp-cron entries - Individual site failures don't stop batch operations - Clear feedback on what was changed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -87,17 +87,58 @@ define('DISABLE_WP_CRON', true);" "$wp_config"
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to safely re-enable wp-cron (revert changes)
|
||||||
|
# Returns 0 on success, 1 on failure
|
||||||
|
enable_wpcron_in_config() {
|
||||||
|
local wp_config="$1"
|
||||||
|
|
||||||
|
# Check if file exists and is writable
|
||||||
|
if [ ! -f "$wp_config" ] || [ ! -w "$wp_config" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if DISABLE_WP_CRON exists and is set to true
|
||||||
|
if grep -E "^[^/]*define\s*\(\s*['\"]DISABLE_WP_CRON['\"]\s*,\s*true\s*\)" "$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"
|
||||||
|
|
||||||
|
# Verify removal was successful
|
||||||
|
if ! grep -E "^[^/]*define\s*\(\s*['\"]DISABLE_WP_CRON['\"]\s*,\s*true\s*\)" "$wp_config" >/dev/null 2>&1; then
|
||||||
|
rm -f "${wp_config}.wpbak"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
# Restore backup if removal failed
|
||||||
|
if [ -f "${wp_config}.wpbak" ]; then
|
||||||
|
mv "${wp_config}.wpbak" "$wp_config"
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# DISABLE_WP_CRON not found or already disabled
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
clear
|
clear
|
||||||
print_banner "WordPress Cron Manager"
|
print_banner "WordPress Cron Manager"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${BOLD}What would you like to do?${NC}"
|
echo -e "${BOLD}What would you like to do?${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo -e "${GREEN}Enable System Cron:${NC}"
|
||||||
echo " 1) Scan for WordPress installations"
|
echo " 1) Scan for WordPress installations"
|
||||||
echo " 2) Disable wp-cron for specific domain"
|
echo " 2) Disable wp-cron for specific domain"
|
||||||
echo " 3) Disable wp-cron for specific user (all their WP sites)"
|
echo " 3) Disable wp-cron for specific user (all their WP sites)"
|
||||||
echo " 4) Disable wp-cron server-wide (all WordPress sites)"
|
echo " 4) Disable wp-cron server-wide (all WordPress sites)"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}Revert to WP-Cron:${NC}"
|
||||||
|
echo " 6) Re-enable wp-cron for specific domain"
|
||||||
|
echo " 7) Re-enable wp-cron for specific user (all their WP sites)"
|
||||||
|
echo " 8) Re-enable wp-cron server-wide (all WordPress sites)"
|
||||||
|
echo ""
|
||||||
|
echo -e "${CYAN}Status & Information:${NC}"
|
||||||
echo " 5) Check wp-cron status for domain/user"
|
echo " 5) Check wp-cron status for domain/user"
|
||||||
|
echo ""
|
||||||
echo " 0) Return to menu"
|
echo " 0) Return to menu"
|
||||||
echo ""
|
echo ""
|
||||||
echo -n "Select option [0]: "
|
echo -n "Select option [0]: "
|
||||||
@@ -493,6 +534,199 @@ case "$choice" in
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
6)
|
||||||
|
# Re-enable wp-cron for specific domain
|
||||||
|
echo ""
|
||||||
|
echo -n "Enter domain name: "
|
||||||
|
read -r domain
|
||||||
|
|
||||||
|
if [ -z "$domain" ]; then
|
||||||
|
print_error "Domain cannot be empty"
|
||||||
|
press_enter
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find WordPress installation
|
||||||
|
wp_config=""
|
||||||
|
for userdata_file in /var/cpanel/userdata/*/main; do
|
||||||
|
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
|
||||||
|
|
||||||
|
if [ -z "$wp_config" ]; then
|
||||||
|
print_error "WordPress installation not found for $domain"
|
||||||
|
press_enter
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "${GREEN}Found WordPress:${NC} $wp_config"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Backup wp-config.php
|
||||||
|
cp "$wp_config" "${wp_config}.backup-$(date +%Y%m%d-%H%M%S)"
|
||||||
|
echo -e "${GREEN}✓${NC} Backed up wp-config.php"
|
||||||
|
|
||||||
|
# Re-enable wp-cron
|
||||||
|
if enable_wpcron_in_config "$wp_config"; then
|
||||||
|
echo -e "${GREEN}✓${NC} Removed DISABLE_WP_CRON from wp-config.php"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}⚠${NC} DISABLE_WP_CRON not found or already enabled"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove cron job
|
||||||
|
site_path=$(dirname "$wp_config")
|
||||||
|
user=$(echo "$site_path" | cut -d'/' -f3)
|
||||||
|
|
||||||
|
if crontab -u "$user" -l 2>/dev/null | grep -q "$site_path.*wp-cron.php"; then
|
||||||
|
crontab -u "$user" -l 2>/dev/null | grep -v "$site_path.*wp-cron.php" | crontab -u "$user" -
|
||||||
|
echo -e "${GREEN}✓${NC} Removed cron job from user crontab"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}⚠${NC} No cron job found for this site"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
print_success "WordPress cron reverted to default for $domain"
|
||||||
|
;;
|
||||||
|
|
||||||
|
7)
|
||||||
|
# Re-enable wp-cron for specific user
|
||||||
|
echo ""
|
||||||
|
echo -n "Enter cPanel username: "
|
||||||
|
read -r target_user
|
||||||
|
|
||||||
|
if [ -z "$target_user" ]; then
|
||||||
|
print_error "Username cannot be empty"
|
||||||
|
press_enter
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "/home/$target_user" ]; then
|
||||||
|
print_error "User $target_user does not exist"
|
||||||
|
press_enter
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Reverting WordPress installations for user: $target_user"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
wp_configs=$(find "/home/$target_user" -name "wp-config.php" -type f 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -z "$wp_configs" ]; then
|
||||||
|
print_error "No WordPress installations found for $target_user"
|
||||||
|
press_enter
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
count=0
|
||||||
|
echo "$wp_configs" | while IFS= read -r wp_config; do
|
||||||
|
count=$((count + 1))
|
||||||
|
site_path=$(dirname "$wp_config")
|
||||||
|
|
||||||
|
echo -e "${BOLD}Site $count:${NC} $site_path"
|
||||||
|
|
||||||
|
# Backup
|
||||||
|
cp "$wp_config" "${wp_config}.backup-$(date +%Y%m%d-%H%M%S)" 2>/dev/null
|
||||||
|
echo " • Backed up wp-config.php"
|
||||||
|
|
||||||
|
# Re-enable wp-cron
|
||||||
|
if enable_wpcron_in_config "$wp_config"; then
|
||||||
|
echo " • Removed DISABLE_WP_CRON"
|
||||||
|
else
|
||||||
|
echo " • Already using default wp-cron"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
done
|
||||||
|
|
||||||
|
# Remove all wp-cron jobs for this user
|
||||||
|
if crontab -u "$target_user" -l 2>/dev/null | grep -q "wp-cron.php"; then
|
||||||
|
crontab -u "$target_user" -l 2>/dev/null | grep -v "wp-cron.php" | crontab -u "$target_user" -
|
||||||
|
echo -e "${GREEN}✓${NC} Removed all wp-cron jobs from user crontab"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "All WordPress sites for $target_user reverted to default wp-cron"
|
||||||
|
;;
|
||||||
|
|
||||||
|
8)
|
||||||
|
# Server-wide revert
|
||||||
|
echo ""
|
||||||
|
echo -e "${RED}${BOLD}WARNING: Server-Wide Revert${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "This will:"
|
||||||
|
echo " • Find ALL WordPress installations on the server"
|
||||||
|
echo " • Remove DISABLE_WP_CRON from each wp-config.php"
|
||||||
|
echo " • Remove all wp-cron system cron jobs"
|
||||||
|
echo ""
|
||||||
|
echo -n "Are you sure? Type 'yes' to confirm: "
|
||||||
|
read -r confirm
|
||||||
|
|
||||||
|
if [ "$confirm" != "yes" ]; then
|
||||||
|
echo "Cancelled"
|
||||||
|
press_enter
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Scanning entire server for WordPress installations..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
total=0
|
||||||
|
reverted=0
|
||||||
|
|
||||||
|
wp_configs=$(find /home/*/public_html -name "wp-config.php" -type f 2>/dev/null)
|
||||||
|
|
||||||
|
if [ -z "$wp_configs" ]; then
|
||||||
|
echo -e "${YELLOW}No WordPress installations found${NC}"
|
||||||
|
press_enter
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
while IFS= read -r wp_config; do
|
||||||
|
total=$((total + 1))
|
||||||
|
site_path=$(dirname "$wp_config")
|
||||||
|
user=$(echo "$site_path" | cut -d'/' -f3)
|
||||||
|
|
||||||
|
echo -e "${BOLD}Processing:${NC} $site_path (user: $user)"
|
||||||
|
|
||||||
|
# Backup
|
||||||
|
cp "$wp_config" "${wp_config}.backup-$(date +%Y%m%d-%H%M%S)" 2>/dev/null
|
||||||
|
|
||||||
|
# Re-enable wp-cron
|
||||||
|
if enable_wpcron_in_config "$wp_config"; then
|
||||||
|
reverted=$((reverted + 1))
|
||||||
|
echo -e "${GREEN}✓${NC} Reverted"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}⚠${NC} Already using default wp-cron"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
done <<< "$wp_configs"
|
||||||
|
|
||||||
|
# Remove all wp-cron jobs from all users
|
||||||
|
echo ""
|
||||||
|
echo "Removing wp-cron jobs from user crontabs..."
|
||||||
|
for user_home in /home/*; do
|
||||||
|
user=$(basename "$user_home")
|
||||||
|
if crontab -u "$user" -l 2>/dev/null | grep -q "wp-cron.php"; then
|
||||||
|
crontab -u "$user" -l 2>/dev/null | grep -v "wp-cron.php" | crontab -u "$user" - 2>/dev/null
|
||||||
|
echo " • Removed cron jobs for user: $user"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
print_success "Server-wide revert complete"
|
||||||
|
echo ""
|
||||||
|
echo "Summary:"
|
||||||
|
echo " • Total WordPress sites found: $total"
|
||||||
|
echo " • Successfully reverted: $reverted"
|
||||||
|
;;
|
||||||
|
|
||||||
0)
|
0)
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user