WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 5 months ago

#47419 new defect (bug)

If emojis or embeds JavaScript is not loaded, variable wp is undefined in the front-end.

Reported by: Shelob9 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:
PR Number:

Description

In my plugin I am using wp.createElement in the front-end and using wp_enqueue_scripts( 'wp-element' ) to load it. If emojis are disabled, the error "uncaught reference error, variable wp not defined" happens when trying to access wp.createElement.

I could be wrong, but I think the problem is that if emojis are disabled, this line, which sets up the wp variable does not run.

https://github.com/WordPress/WordPress/blob/master/wp-includes/js/wp-emoji.js#L290-L295

Related bugs:

Change History (1)

#1 @swissspidy
5 months ago

One should always use window.wp = window.wp || {}; when working with global variables like that in a plugin. Not sure if we can add this in core by default as an inline script or something.

Note: See TracTickets for help on using tickets.