-
Notifications
You must be signed in to change notification settings - Fork 798
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
Stats: Update method for inserting JavaScript #3763
Comments
Hi, I'm trying to tackle this as a PHP-related "Good first bug". However, I'm not sure I fully understand the issues with the current method that is used to load the stats js file. I understand that the stats JS is first attempted to be loaded using a call to What I'm trying to get my head around is what would be a 'more modern' solution to the issue. Is it safe to just presume that a theme will always use I also wondered whether another modernisation would be to switch from the current method of printing the JavaScript block which sets all the An additional issue with using The code that renders the footer also outputs an AMP-specific footer with an 'amp-pixel' so this would have to be accommodated in any code change, I think this would still need to be output via I'd greatly appreciate any thoughts / suggestions anyone has! |
I think that by now, it may be a safe assumption to make. WordPress themes have changed a lot since this was originally implemented, and it has now become quite rare to see a theme that does not include the most basic WordPress hooks that are
Yes, I believe that's a blocker for using Related Trac ticket: |
Thanks @jeherve, so would an improvement for now be to get rid of the workaround / fallback |
I also just noticed that the Jetpack Amp support class (class.jetpack-amp-support.php) has a function |
After discussion on Github issue "Stats: Update method for inserting JavaScript Automattic#3763" it was considered that it was a safe assumption to make that a theme would always have a `wp_footer` action. This update removes code which was used to provide a fallback / workaround in the case of themes which did not contain a `wp_footer` action. The workaround consisted of setting a global variable `$rendered_stats_footer` which would get set to true if the `wp_footer` call was successful, if not successful then the WP Stats JS code would get set via a `wp_head` action instead.
Yes, that'd be nice, all the while making sure we don't break compatibility with AMP as you mentioned. 👍 |
Thanks, I've added a pull request #13182 for this now. |
#13182 is a nice code simplification, but let's leave this issue open for now since we may still need to address the SRI issue. |
This issue has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation. |
This was eventually implemented in #29780. |
We use a global var and a combo of
wp_footer
andshutdown
to insert the stats js, initially as part of a workaround for sites that aren't usingwp_footer
. It's been long enough now that we can likely move to something more modern.h/t fabacab/wp-sri#2 for the report
The text was updated successfully, but these errors were encountered: