Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set WP constants via vvv JSON file. #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EHLOVader
Copy link
Contributor

Adds the ability to set the WP constants through the json file and fixes issue #30

Safely handles boolean or text value configurations.

@EHLOVader
Copy link
Contributor Author

Actually running into some issues with the previously defined constants.

What do you think?

  • Removing them from the top and defining them explicitly in the vvv.json only?
/*Caching*/
define( 'WP_CACHE_KEY_SALT', '<%= site.id %>' );

<% if (wordpress.constants) {
%>/* Constants */
<% _.each(wordpress.constants, function(value, key, field){
        if(!_.contains([true,false],value)){
            value = "'" + value + "'";
        }
        %>define( '<%= key %>', <%= value %> );
<%  })
} %>
  • Removing them only if they are set in the vvv.json?
/* Debug */
<% if (wordpress.constants && typeof wordpress.constants.WP_DEBUG == 'undefined') { 
%>define( 'WP_DEBUG', true );
<% } %>
<% if (wordpress.constants && typeof wordpress.constants.WP_DEBUG_DISPLAY == 'undefined') {
%>define( 'WP_DEBUG_DISPLAY', true );
<% } %>
<% if (wordpress.constants && typeof wordpress.constants.WP_DEBUG_LOG == 'undefined') { 
%>define( 'WP_DEBUG_LOG', false );
<% } %>
<% if (wordpress.constants && typeof wordpress.constants.SCRIPT_DEBUG == 'undefined') { 
%>define( 'SCRIPT_DEBUG', true );
<% } %> 
<% if (wordpress.constants && typeof wordpress.constants.SAVEQUERIES == 'undefined') { 
%>define( 'SAVEQUERIES', true );
<% } %>
<% if (wordpress.constants && typeof wordpress.constants.JETPACK_DEV_DEBUG == 'undefined') { 
%>define( 'JETPACK_DEV_DEBUG', true );
<% } %>

/*Caching*/
define( 'WP_CACHE_KEY_SALT', '<%= site.id %>' );

<% if (wordpress.constants) {
%>/* Constants */
<% _.each(wordpress.constants, function(value, key, field){
        if(!_.contains([true,false],value)){
            value = "'" + value + "'";
        }
        %>define( '<%= key %>', <%= value %> );
<%  })
} %>
  • Moving them below the config defined constants and adding if( !defined()) blocks around it?
/*Caching*/
define( 'WP_CACHE_KEY_SALT', '<%= site.id %>' );

<% if (wordpress.constants) {
%>/* Constants */
<% _.each(wordpress.constants, function(value, key, field){
        if(!_.contains([true,false],value)){
            value = "'" + value + "'";
        }
        %>define( '<%= key %>', <%= value %> );
<%  })
} %>

/* Debug Defaults*/
if(!defined('WP_DEBUG'){
    define( 'WP_DEBUG', true );
}
if( !defined('WP_DEBUG_DISPLAY') ) {
    define( 'WP_DEBUG_DISPLAY', true );
}
if( !defined('WP_DEBUG_LOG') ) {
    define( 'WP_DEBUG_LOG', false );
}
if( !defined('SCRIPT_DEBUG') ) {
    define( 'SCRIPT_DEBUG', true );
}
if( !defined('SAVEQUERIES') ) {
    define( 'SAVEQUERIES', true );
}
if( !defined('JETPACK_DEV_DEBUG') ) {
    define( 'JETPACK_DEV_DEBUG', true );
}

I am testing these options locally. May push a fix later today. But wanted to start a discussion.

EDITED: to include examples of each.

Use ifndef pattern in php instead of leading with debug constants.
@EHLOVader
Copy link
Contributor Author

I just wanted to report I favor the ifndef pattern. Tested it and fixed a typo and rebased to one commit.

The ifndef allows you to later comment out portions of the config files at a later point to revert to the debug values.

@EHLOVader
Copy link
Contributor Author

bump

@lkwdwrd
Copy link
Owner

lkwdwrd commented Feb 13, 2015

Thanks @EHLOVader, really appreciate the effort here!

What I would love to see is a system of sensible defaults that get overridden by values set in the json file. This way there is no artifacting left over in the wp-config.php, give overall control of the values to the project maintainer, but doesn't put an undue burden on the maintainer to always have them in the json file.

Basically, if nothing is set for WP_DEBUG, then it would output as true. But if it IS defined in the json file, it would get output as whatever was specified, overriding the default.

@EHLOVader
Copy link
Contributor Author

Exactly. That is what I was trying to do with the latter two cases.

It has been awhile now, but I feel like I ran into a case where editing the json would result in the line being removed from the config, but not having a sensible default to fall back on in there already.

@EHLOVader EHLOVader mentioned this pull request Jun 11, 2015
@EHLOVader
Copy link
Contributor Author

This is an important one for me too. Like #37 I use it regularly because of old or improperly created themes or plugins.

screenshot of common errors

@EHLOVader EHLOVader mentioned this pull request Feb 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants