Repository navigation
Stop adding wp-config.php lines inside another plugin's marker block - #1114
Open
kurtisbradley wants to merge 1 commit into
Open
kurtisbradley wants to merge 1 commit into
kurtisbradley wants to merge 1 commit into
Conversation
wp_cache_replace_line() adds a missing line above the first define it finds. When a plugin such as Kadence Security (formerly Solid Security and iThemes Security) keeps its settings at the top of wp-config.php between "// BEGIN" and "// END" marker comments, the first define is inside that block, so WP_CACHE and WPCACHEHOME end up inside it too and are erased the next time that plugin rewrites its block. Treat a BEGIN marker comment as an insertion point as well, so the new line goes above the block instead of into it. Fixes Automattic#859
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #859
wp_cache_replace_line()adds a missing line above the firstdefineit finds. Kadence Security (formerly Solid Security, and iThemes Security before that) keeps its settings at the top of wp-config.php between marker comments:The first
defineis inside that block, soWP_CACHEandWPCACHEHOMEare written into it and erased the next time the security plugin rewrites its block. Caching then silently stops until the settings page is visited again.The fix
Treat a
// BEGIN/# BEGINmarker comment as an insertion point too, so the new line goes above the block rather than into it. It is a one-line change to the existing regex. Files without marker blocks are written exactly as before, and replacing or removing an existing line is untouched.I kept it generic rather than matching the plugin by name: it has been renamed twice since the issue was opened, and other plugins use the same marker convention. Happy to narrow it or take a different approach if you prefer.
Testing
Added
tests/php/smoke/WpCacheReplaceLineTest.php: Kadence Security, Solid Security, iThemes Security and#-style blocks, plus the no-marker case to show existing behaviour is unchanged. The four marker cases fail on trunk and pass with this change.composer test-phpandcomposer lintpass.Also verified on a live site running Kadence Security Basic 10.0.5:
WP_CACHEandWPCACHEHOMEwere written inside the Kadence block and erased the next time Kadence Security saved its settings.WP_CACHEwas written above the block, and both constants survived repeated Kadence Security rewrites.Release Notes
WP_CACHEandWPCACHEHOMEare no longer added inside another plugin's marker block in wp-config.php (e.g. Kadence Security, formerly Solid Security / iThemes Security), where they were being erased.