Closed joshfeck closed 6 years ago
Another report here:
I created a snippet that will include that file for specific actions, right now it checks for elementor:
https://gist.github.com/Pebblo/eb77e0c3ce13e52afb4482f52aa642cf
@mnelson4 is this something you feel comfortable looking into? Can we add @Pebblo's code to core or look into @joshfeck's suggestions?
This is more Brent's domain, but if you really want to offload stuff from him, I can attempt it.
I'm torn between just always including template_tags.php
and using a filter only load the file when a known page builder needs it.
Reasons to always include template_tags.php
:
Reasons to have a filter to only load template_tags.php
when a known page builder needs it:
I'm inclined to just always include template tags, even on the back-end.
I think we want to not distract Brent with this, so Darren do you have any thoughts on this?
So template_tags.php
is just a bunch of function definitions. I'm assuming that that means there shouldn't be any issue just loading it everywhere because any usage of those functions in the backend or other contexts would cause problems anyways (such as what triggered this issue)! So, I think your assessment seems sound and we probably could get away with just loading it everywhere.
The only concern I have with loading it everywhere is with functions like espresso_get_events
which call:
wp_reset_query();
wp_reset_postdata();
I wonder if the function is called somewhere in a cpt editor or wp-list-table context if that could cause things to blow up.
Yeah using functions meant for the front-end from the back-end does seem problematic... yes, things might blow up further down the road. In that particular example, wp_reset_query()
and wp_reset_postdata
first check if global $wp_query
is defined. I'd think the page builders would define it if it's needed, and even if they don't, those particular functions shouldn't blow up.
So I think this is worth trying, but ya, it's possible this will be a rabbit hole. I'm just going to put one foot in...
PR merged to master that addresses this
@sethshoultes mentioned this in Slack:
I've seen something similar while working with the Elementor page builder plugin:
One possible solution would be to tweak the conditionals that determine whether to include the template tags file.
The underlying issue is the page builders are trying to load content as if it was the front end of the site, but it’s not the front end of the site. Here’s the conditional from EE_System.core.php:
so one idea could be to look at tweaking what’s defined as
isFrontend()
and/or add a filter switch to that conditional to be used by a compatibility shim.