-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
User global styles: should we save relative paths to the database for uploaded assets? #61809
Comments
cc. @creativecoder for a Font Library expert's perspective but this sounds good to me and will help with theme portability. |
This is a tricky one! I'm unsure of the best answer, but I can share what I learned when implementing the font library, which is based on media uploads. In the databse, uploads use:
We followed the same conventions for I fear changing some urls be relative in the database is only a bandaid that we'll regret later... I think we need a solution for site portability that addresses all urls saved to the database (media, fonts, and even site/home urls).
Related to the discussions in this issue, in the context of theme.json, I think we should probably keep |
Thanks for the feedback @creativecoder There are some update/migration plugins that handle a site 'domain change' scenario as well I see, i.e., updating all instances of a URL with another in the database. Maybe WordPress needs such a tool 🤷🏻 |
I just stumbled across it during a project. I set up and prepared the project without SSL. I also installed fonts via the font library. When I then switched to SSL, the fonts were no longer loaded - http vs. https. I then found the entries in the database in which the URLs were still with http. In the end I was able to solve it using Better Search & Replace. But it's not nice for normal users. Relative paths would be better here or an adjustment of the existing URLs if the main URL of the project changes. |
I definitely get this concern (and think it's worth talking about making all references relative in the future), but Global Styles assets present a newer, more immediate challenge than other URLs in the database. As @ramonjd mentioned, there are existing migration tools that handle domain changes, but the way that URLs are stored in the database for Global Styles breaks those tools because the slashes are escaped. We use WP Local and push/pull sites to/from WP Engine on a regular basis during development. These tools do an automatic We love the ease of installing fonts via Global Styles, but we're abandoning it in favor of the older |
Yeah, and here we're explicitly talking about the contents of a global styles CPT. At present, WordPress will export a theme with absolute URLs if any fonts/background images have been added to global styles by a user. This is perhaps where we could start: by doing a search and replace on the theme.json assets output before we bundle it. This would ensure portability, which is one of the promises of theme.json. _wp_get_attachment_relative_path() could come in handy in that case. The same functionality could then be tested for the other case — ensuring that styles are portable across hosts — however with a manual trigger, or perhaps some frontend monitoring that compares hosts and would prompt the admin to "update" the current CPT. All this is highly speculative of course. However, if we try something out for the exporting side at least, maybe it'll spark ideas for a more robust solution. |
We're definitely supportive of anything that will restore the functionality of long-standing migration tools that have existed for years as a priority. As you mentioned, only URLs stored in the global styles CPT are currently affected, but that prevents us from using a variety of features unless we're ok with complicating our workflow. |
+1 to this issue being solved. When migrating between environments, font URLs are not updated. When running I'm not sure the best solution here (regenerating the URLs on a cache clear?), but relying on tricky moves to clean up slashed URLs for common assets like fonts feels hacky. |
Thanks for keeping this one alive, folks. I guess it'd be not much of a stretch to create a helper class to do string replace and update on Theme.json could also contain absolute URLs to external hosts, not just the new site host. Therefore, I'm thinking it might be safer to specify a path to search for and also the replace value.
I imagine upload paths could change in site migrations too? So it should be able to handle hosts, e.g., It could also be a user-facing tool in the admin. Making it user friendly is another question 😄 |
On a related note, I think it would be rather convenient to have absolute paths to uploaded files converted to theme assets when exporting a theme from the site editor: |
What problem does this address?
When adding a background image or a web font via the site editor global styles tools, the absolute path is saved in the global styles post content to the database.
For example:
Web fonts post theme.json in the database:
And background images:
This means that if the host changes, e.g., when viewing a site via a test portal as with WordPress Studio, the assets will return 404s.
What is your proposed solution?
Remove the host and save relative paths, e.g.,
Related:
cc @andrewserong @noisysocks @autumnfjeld
The text was updated successfully, but these errors were encountered: