Skip to content

Commit e2d0496

Browse files
jakeparisJake Paris
andauthored
Fix issue where wordpress config isn't read/written in correct directory, fixes #76 (#77)
Co-authored-by: Jake Paris <[email protected]>
1 parent 2e3628b commit e2d0496

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

install.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ removal_actions:
4646
- |
4747
#ddev-nodisplay
4848
#ddev-description:Remove browsersync settings for WordPress if applicable
49-
rm -f "${DDEV_APPROOT}/wp-config-ddev-browsersync.php"
49+
if [ $DDEV_DOCROOT != "" ]; then
50+
DDEV_SITE_PATH="${DDEV_APPROOT}/${DDEV_DOCROOT}" ;
51+
else
52+
DDEV_SITE_PATH=$DDEV_APPROOT
53+
fi
54+
rm -f "${DDEV_SITE_PATH}/wp-config-ddev-browsersync.php"
5055
scripts/remove-wordpress-settings.sh
5156
# Don't automatically renable settings management in case user didn't have it enabled in the first place
5257
- |

scripts/remove-wordpress-settings.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ fi
1111
# exit 0
1212
# fi
1313

14-
SETTINGS_FILE_NAME="${DDEV_APPROOT}/wp-config.php"
14+
if [ $DDEV_DOCROOT != "" ]; then
15+
DDEV_SITE_PATH="${DDEV_APPROOT}/${DDEV_DOCROOT}" ;
16+
else
17+
DDEV_SITE_PATH=$DDEV_APPROOT
18+
fi
19+
20+
SETTINGS_FILE_NAME="${DDEV_SITE_PATH}/wp-config.php"
1521

1622
echo "Removing wp-config-ddev-browsersync.php from: ${SETTINGS_FILE_NAME}"
1723

@@ -20,5 +26,5 @@ awk '
2026
/\/\*\* Include for ddev-browsersync to modify WP_HOME and WP_SITEURL\./ { skip=1 }
2127
skip && /\}.*$/ { skip=0; getline; next }
2228
!skip
23-
' ${DDEV_APPROOT}/wp-config.php > ${DDEV_APPROOT}/wp-config-temp.php
24-
mv ${DDEV_APPROOT}/wp-config-temp.php ${DDEV_APPROOT}/wp-config.php
29+
' ${DDEV_SITE_PATH}/wp-config.php > ${DDEV_SITE_PATH}/wp-config-temp.php
30+
mv ${DDEV_SITE_PATH}/wp-config-temp.php ${DDEV_SITE_PATH}/wp-config.php

scripts/setup-wordpress-settings.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ fi
1111
# exit 0
1212
# fi
1313

14-
cp scripts/wp-config-ddev-browsersync.php $DDEV_APPROOT/
14+
if [ $DDEV_DOCROOT != "" ]; then
15+
DDEV_SITE_PATH="${DDEV_APPROOT}/${DDEV_DOCROOT}" ;
16+
else
17+
DDEV_SITE_PATH=$DDEV_APPROOT
18+
fi
19+
20+
cp scripts/wp-config-ddev-browsersync.php $DDEV_SITE_PATH/
1521

16-
SETTINGS_FILE_NAME="${DDEV_APPROOT}/wp-config.php"
22+
SETTINGS_FILE_NAME="${DDEV_SITE_PATH}/wp-config.php"
1723

1824
echo "Settings file name: ${SETTINGS_FILE_NAME}"
1925

2026
# If wp-config.php already contains the require_once() then exit early.
21-
if grep -q "/\*\* Include for ddev-browsersync to modify WP_HOME and WP_SITEURL. \*/" ${DDEV_APPROOT}/wp-config.php; then
27+
if grep -q "/\*\* Include for ddev-browsersync to modify WP_HOME and WP_SITEURL. \*/" ${DDEV_SITE_PATH}/wp-config.php; then
2228
exit 0
2329
fi
2430

@@ -37,7 +43,7 @@ awk '
3743
next
3844
}
3945
{print}
40-
' ${DDEV_APPROOT}/wp-config.php > ${DDEV_APPROOT}/wp-config-temp.php
46+
' ${DDEV_SITE_PATH}/wp-config.php > ${DDEV_SITE_PATH}/wp-config-temp.php
4147

4248
# Replace the real config file with the modified version in temporary file.
43-
mv ${DDEV_APPROOT}/wp-config-temp.php ${DDEV_APPROOT}/wp-config.php
49+
mv ${DDEV_SITE_PATH}/wp-config-temp.php ${DDEV_SITE_PATH}/wp-config.php

0 commit comments

Comments
 (0)