Template_root not updated by env?


#1

After transferring the database + files from development to staging server,
the child theme (parent theme is the default Twenty Seventeen theme)
doesn’t load correctly anymore (parent theme functions are missing).

Opening the Theme options page shows a notice that the (child) theme malfunctioned and that the default theme has been activated.
Re-activating the theme afterwards fixes the issue and the child theme loads correctly again.
However, this is not practical when transferring between servers, also there will be always a period where the wrong theme is loaded, it requires extra fixes like re-positioning all the widgets and also doesn’t fix the underlying issue.

The reason is the template_root option (wp @development option get template_root, wp @staging option get template_root) which stays the same between servers although the paths changed. The paths in .env file have been adjusted for each system (otherwise WordPress wouldn’t work at all).

template_root on development server:
/srv/www/web/wp/wp-content/themes

template_root on staging/production servers:
/srv/www/example.com/releases/20170602132328/web/wp/wp-content/themes

Trellis uses timestamped release folders and symlinks for fast switching between them.

template_root is not set by Bedrock using the environment settings but is stored statically in database as a WordPress option and not updated/shimmed by Bedrock.

Edit: There was an issue reported in the past when Bedrock still used Capistrano for deploying:


Multisite subsite using TwentyFifteen theme
#2

Are you using Trellis? This should already be handled by https://github.com/roots/trellis/blob/f948df133c92cf13516c5f0cc00cdde773068e47/roles/deploy/hooks/finalize-after.yml#L22


#3

Yes, I use Trellis. The reason for this issue was because I transferred the whole database and the transfer script only replaces the hostname/domains but doesn’t update the template_root option.

Would it be better to let Bedrock update the template_root option by environment variable on page load?


#4

This might be a good idea :eyes:

If we implement it in Bedrock, or at least offer it as a mu-plugin package, then all deploys would be gravy instead of just Trellis.

Just realized the syncing script I use also suffers from this, although I have yet to run into it since I’m not usually dealing with child themes. Thanks for bringing it up.

+@swalkinshaw


#5

So we’d need Bedrock/plugin to basically do update_option('template_root', env('template_root') on every page load?


#6

Or even more high level and let the option value appear differently using a hook?:
https://codex.wordpress.org/Plugin_API/Filter_Reference/option_(option_name)

There seems to be no filter for template_root setting itself, like
https://developer.wordpress.org/reference/functions/get_raw_theme_root/
The function for example uses the option directly without filtering first.


#7

@benword: Apparently this issue also occurs when I just deploy (without transferring database or files) to server.


#8

:star2: @strarsis Thanks for reporting the trouble with deploys and child themes.

Could you see if roots/trellis#848 resolves the issue of deploys causing trouble with child themes’ template_root? (database syncing aside)


As for the issue of DB sync scripts not addressing a template_root that differs between development and production while addressing other per-environment differences, I don’t understand why the solution would be to expect Bedrock to modify template_root on every single page load. Why not just adjust the DB sync script to be complete, adjusting the wp-content/themes parent path while adjusting other environment differences?


#9

I just tried it out (merged from master) and it seems to work now.