Improve DISABLE_WP_CRON placement in wp-config.php

Changes:
- Modified disable_wpcron_in_config() to place DISABLE_WP_CRON before "stop editing" comment
- This follows WordPress convention for custom constants
- Removes any existing DISABLE_WP_CRON lines first (clean placement)
- Falls back to after <?php if "stop editing" not found

Placement Logic:
1. Remove any existing DISABLE_WP_CRON (anywhere in file)
2. Add before "/* That's all, stop editing! */" comment (line ~93)
3. Fallback: Add after <?php if no "stop editing" found

Example Placement:
```
if ( ! defined( 'WP_DEBUG' ) ) {
    define( 'WP_DEBUG', false );
}

define('DISABLE_WP_CRON', true);  ← Added here
/* That's all, stop editing! Happy publishing. */
```

Benefits:
- Follows WordPress conventions
- Placed with other custom constants
- Clean, predictable location
- Easy to find for manual edits

https://claude.com/claude-code
This commit is contained in:
cschantz
2025-11-07 18:03:58 -05:00
parent c464b51ed7
commit c78ff2ccd7
@@ -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 <?php
# First, check if <?php exists
if ! grep -q "<?php" "$wp_config"; then
return 1
# Create backup even if no existing line
cp "$wp_config" "${wp_config}.wpbak"
fi
# Add the define right after <?php, but only if not already present
if ! grep -q "DISABLE_WP_CRON" "$wp_config"; then
sed -i.wpbak "/<?php/a \\
# Now add it in the proper location - before "stop editing" comment
if grep -q "stop editing" "$wp_config" 2>/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 "<?php" "$wp_config"; then
# Fallback: if no "stop editing" found, add after opening PHP tag
sed -i "/<?php/a \\
define('DISABLE_WP_CRON', true);" "$wp_config"
else
# Restore backup if file format is unexpected
if [ -f "${wp_config}.wpbak" ]; then
mv "${wp_config}.wpbak" "$wp_config"
fi
return 1
fi
# Verify the change was successful