Automattic / Automattic/jetpack
Calling sharing_add_footer after (!) wp_print_footer_scripts in wp_footer to ensure jQuery dependancy
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
Currently `sharing_add_footer` is being attached to `wp_footer` with priority 10 which is **before** WordPress has printed the footer scripts as `wp_print_footer_scripts` is attached to `wp_footer` with priority 20.
`sharing_add_footer` echoes inline Javascript during [`display_footer()`](https://github.com/Automattic/jetpack/blob/8ec83606e531c70d963291b591c8aff682775e6e/modules/sharedaddy/sharing-service.php#L548) ([here is an example](https://github.com/Automattic/jetpack/blob/6c49efab93f08f68780575f43936b546db477d54/modules/sharedaddy/sharing-sources.php#L499)) which depends on jQuery being already available. This fails in cases when jQuery is enqueued in the footer.

The solution is to move [`sharing_add_footer`](https://github.com/Automattic/jetpack/blob/4ae9a0e4fe15877340da66edabb3235548e328c2/modules/sharedaddy/sharing-service.php#L618) to a later priority:
```
add_action( 'wp_footer', 'sharing_add_footer', 25 );
```
Contributor guide
Research direction
Start in modules/sharedaddy/sharing-service.php at display_footer() and sharing_add_footer(), then review their wp_footer priorities alongside wp_print_footer_scripts. Reproduce a footer-enqueued jQuery case and verify that the inline JavaScript runs after the dependency is available; done means sharing_add_footer uses the later priority described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100