diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 5eb8c8e..1f7026b 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -55,22 +55,30 @@ disable_wpcron_in_config() { return 1 fi - # Check if DISABLE_WP_CRON already exists (not commented) - if grep -E "^[^/]*define\s*\(\s*['\"]DISABLE_WP_CRON['\"]" "$wp_config" >/dev/null 2>&1; then - # Line exists, modify it to set true - sed -i.wpbak "s/^\([^/]*\)define\s*(\s*['\"]DISABLE_WP_CRON['\"]\s*,\s*[^)]*)/\1define('DISABLE_WP_CRON', true)/" "$wp_config" + # First, remove any existing DISABLE_WP_CRON lines (anywhere in file) + # This ensures clean placement even if previously added in wrong location + if grep -q "DISABLE_WP_CRON" "$wp_config" 2>/dev/null; then + sed -i.wpbak "/define\s*(\s*['\"]DISABLE_WP_CRON['\"]/d" "$wp_config" else - # Line doesn't exist, add it after /dev/null; then + # Add before "stop editing" line (proper WordPress convention) + sed -i "/stop editing/i \\ define('DISABLE_WP_CRON', true);" "$wp_config" + elif grep -q "