WordPress.org

Plugin Directory

jetpack

#1600 closed defect (fixed)

Gravatar Hovercards uses wp_enqueue_script incorrectly.

Reported by: ericmann Owned by: mdawaffe
Priority: normal Severity: normal
Plugin: jetpack Keywords: has-patch
Cc:

Description

The code in the Gravatar Hovercards module uses wp_enqueue_scripts() to queue up its script files and various dependencies. It then uses wp_localize_scripts() to add some PHP variables for use in JS.

But then the system calls wp_print_scripts() directly (hooked onto the wp_footer action) to output its script files to the page. While this works, it's not the right action or the right approach for printing footer scripts. Other plugins/modules cannot hook in to change the execution order or unhook the scripts if needed. Also, the dependency of the module on jQuery can cause the library to be loaded twice in some situations (i.e. when jQuery is automatically concatenated with other scripts by a separate plugin).

Instead of hooking to wp_footer, the code should be using the in_footer parameter of wp_enqueue_scripts() and hooking to the wp_enqueue_scripts action. This is the recommended way of deferring JS files to the footer.

Attachments (1)

jetpack-1600.patch (1.9 KB) - added by ericmann 18 months ago.
Use wp_enqueue_scripts

Download all attachments as: .zip

Change History (2)

ericmann18 months ago

Use wp_enqueue_scripts

comment:1 mdawaffe18 months ago

  • Resolution set to fixed
  • Status changed from new to closed

In 621541:

Gravatar Hovercards: Don't manually call wp_print_script()

Use the correct hooks and wp_enqueue_script() calls to print the Hovercard scripts in the footer instead of manually doing wp_print_scripts() in the footer.

Props ericmann

Fixes #1600

Note: See TracTickets for help on using tickets.