Blueprints: Wrap define() calls in if(!defined()) in wp-config.php #901
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.
Rewrites
wp-config,.php
and wraps alldefine()
calls in a conditionalif(!defined())
. The goal is to avoid conflicts between the constants defined via thedefineWpConfigConsts
Blueprint step and the ones defined inwp-config.php
.Related to WordPress/playground-tools#135
Open questions
This PR changes the contents of
wp-content.php
which is fine in the in-browser Playground environment, but may be unexpected when Playground is used for local development e.g. via local Directory Sync orwp-now
. In particular, these changes would show up ingit diff
and could confuse the developer. One workaround could be to also add an explanatory comment like:However, I don't see any other solution here. If a constant is already defined, the
define()
call will issue a warning. Therefore, we must avoid conflictingdefine()
calls inwp-config.php
.Two alternative ideas:
defineWpConfigConsts()
step is called and only then wrap the specific constants definitions that would trigger a warning.defineWpConfigConsts()
step either add adefine()
call inwp-config.php
or rewrite the second argument of an existingdefine()
call. This makes the constant values apparent as all the values are available for inspection in the single location that the developer already knows about and will inspect for debugging. Also, it solves the problem of including the Blueprint-defined constants in the exported Playground.Either way, we're rewriting
wp-config.php
as we cannot leave the conflictingdefine()
call as it is.Thinking about it more, I'm leaning towards closing this PR and exploring the second alternative above. It wouldn't handle dynamic calls like
define($wpdebug, true)
, but it could wrap them in anif()
and add an inline comment to explain the wrapping.cc @dmsnell @danielbachhuber @swissspidy
Testing Instructions
Go to the following URL without this PR applied and confirm there are warnings like
Warning: Constant WP_DEBUG already defined
:http://localhost:5400/website-server/#{%22landingPage%22:%22/%22,%22phpExtensionBundles%22:[%22kitchen-sink%22],%22preferredVersions%22:{%22php%22:%228.0%22,%22wp%22:%225.9%22},%22steps%22:[{%22step%22:%22defineWpConfigConsts%22,%22consts%22:{%22WP_DEBUG%22:true}},{%22step%22:%22defineWpConfigConsts%22,%22consts%22:{%22WP_DEBUG_ONLY%22:%22a%22}}]}
Now go there with this PR applied and confirm the warnings are gone.