generated from ddev/ddev-addon-template
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding WordPress config additions (based on a similar approach by ddev-redis addon) * Replace the actual config file with the temp file * Replace the actual config file with the temp file * Include addon files in the project * Add ${DDEV_APPROOT} to shell script. Added some additional notes to README. * Added some wp-config notes to the README * Revert formatting changes to README * Changed approach so the script modified wp-config.php instead of wp-config-ddev.php * Missing " mark * Improving the removal process to do a better job of cleaning up wp-config.php
- Loading branch information
1 parent
5f52127
commit a721f5a
Showing
5 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
#ddev-generated | ||
set -e | ||
|
||
if [[ $DDEV_PROJECT_TYPE != wordpress ]] ; | ||
then | ||
exit 0 | ||
fi | ||
|
||
if ( ddev debug configyaml 2>/dev/null | grep 'disable_settings_management:\s*true' >/dev/null 2>&1 ) ; then | ||
exit 0 | ||
fi | ||
|
||
SETTINGS_FILE_NAME="${DDEV_APPROOT}/wp-config.php" | ||
|
||
echo "Removing wp-config-ddev-browsersync.php from: ${SETTINGS_FILE_NAME}" | ||
|
||
# Remove the ddev-browsersync config that we added. | ||
awk ' | ||
/\/\*\* Include for ddev-browsersync to modify WP_HOME and WP_SITEURL\./ { skip=1 } | ||
skip && /\}.*$/ { skip=0; getline; next } | ||
!skip | ||
' ${DDEV_APPROOT}/wp-config.php > ${DDEV_APPROOT}/wp-config-temp.php | ||
mv ${DDEV_APPROOT}/wp-config-temp.php ${DDEV_APPROOT}/wp-config.php |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env bash | ||
#ddev-generated | ||
set -e | ||
|
||
if [[ $DDEV_PROJECT_TYPE != wordpress ]] ; | ||
then | ||
exit 0 | ||
fi | ||
|
||
if ( ddev debug configyaml 2>/dev/null | grep 'disable_settings_management:\s*true' >/dev/null 2>&1 ) ; then | ||
exit 0 | ||
fi | ||
|
||
cp scripts/wp-config-ddev-browsersync.php $DDEV_APPROOT/ | ||
|
||
SETTINGS_FILE_NAME="${DDEV_APPROOT}/wp-config.php" | ||
|
||
echo "Settings file name: ${SETTINGS_FILE_NAME}" | ||
|
||
# If wp-config.php already contains the require_once() then exit early. | ||
if grep -q "/\*\* Include for ddev-browsersync to modify WP_HOME and WP_SITEURL. \*/" ${DDEV_APPROOT}/wp-config.php; then | ||
exit 0 | ||
fi | ||
|
||
echo "Adding wp-config-ddev-browsersync.php to: ${SETTINGS_FILE_NAME}" | ||
|
||
# Append our code before the ddev config comment. | ||
awk ' | ||
/\/\/ Include for ddev-managed settings in wp-config-ddev.php./ { | ||
print "/** Include for ddev-browsersync to modify WP_HOME and WP_SITEURL. */" | ||
print "$ddev_browsersync_settings = dirname( __FILE__ ) . \"/wp-config-ddev-browsersync.php\";" | ||
print "" | ||
print "if ( is_readable( $ddev_browsersync_settings ) ) {" | ||
print " require_once( $ddev_browsersync_settings );" | ||
print "}" | ||
print "" | ||
print "// Include for ddev-managed settings in wp-config-ddev.php." | ||
next | ||
} | ||
{print} | ||
' ${DDEV_APPROOT}/wp-config.php > ${DDEV_APPROOT}/wp-config-temp.php | ||
|
||
# Replace the real config file with the modified version in temporary file. | ||
mv ${DDEV_APPROOT}/wp-config-temp.php ${DDEV_APPROOT}/wp-config.php |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
// #ddev-generated | ||
/** Allow any domain/port so WordPress allows browsersync's :3000 URLs */ | ||
if ( ! empty( $_SERVER['SERVER_PORT'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { | ||
// phpcs:ignore | ||
$domain = sprintf( '%s://%s', $_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https', $_SERVER['SERVER_NAME'] ); | ||
|
||
/** WP_HOME URL */ | ||
define( 'WP_HOME', $domain ); | ||
|
||
/** WP_SITEURL location */ | ||
define( 'WP_SITEURL', $domain ); | ||
} |