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:
@@ -55,22 +55,30 @@ disable_wpcron_in_config() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if DISABLE_WP_CRON already exists (not commented)
|
# First, remove any existing DISABLE_WP_CRON lines (anywhere in file)
|
||||||
if grep -E "^[^/]*define\s*\(\s*['\"]DISABLE_WP_CRON['\"]" "$wp_config" >/dev/null 2>&1; then
|
# This ensures clean placement even if previously added in wrong location
|
||||||
# Line exists, modify it to set true
|
if grep -q "DISABLE_WP_CRON" "$wp_config" 2>/dev/null; then
|
||||||
sed -i.wpbak "s/^\([^/]*\)define\s*(\s*['\"]DISABLE_WP_CRON['\"]\s*,\s*[^)]*)/\1define('DISABLE_WP_CRON', true)/" "$wp_config"
|
sed -i.wpbak "/define\s*(\s*['\"]DISABLE_WP_CRON['\"]/d" "$wp_config"
|
||||||
else
|
else
|
||||||
# Line doesn't exist, add it after <?php
|
# Create backup even if no existing line
|
||||||
# First, check if <?php exists
|
cp "$wp_config" "${wp_config}.wpbak"
|
||||||
if ! grep -q "<?php" "$wp_config"; then
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add the define right after <?php, but only if not already present
|
# Now add it in the proper location - before "stop editing" comment
|
||||||
if ! grep -q "DISABLE_WP_CRON" "$wp_config"; then
|
if grep -q "stop editing" "$wp_config" 2>/dev/null; then
|
||||||
sed -i.wpbak "/<?php/a \\
|
# Add before "stop editing" line (proper WordPress convention)
|
||||||
|
sed -i "/stop editing/i \\
|
||||||
define('DISABLE_WP_CRON', true);" "$wp_config"
|
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
|
fi
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Verify the change was successful
|
# Verify the change was successful
|
||||||
|
|||||||
Reference in New Issue
Block a user