[wp-trac] [WordPress Trac] #48098: ReferenceError: jQuery is not defined even if it is enqueued ('wp_display_script_once' needed)
WordPress Trac
noreply at wordpress.org
Tue Oct 22 17:48:41 UTC 2019
#48098: ReferenceError: jQuery is not defined even if it is enqueued
('wp_display_script_once' needed)
-------------------------------------+-------------------------
Reporter: KestutisIT | Owner: (none)
Type: defect (bug) | Status: reopened
Priority: normal | Milestone:
Component: Script Loader | Version: 5.2.3
Severity: normal | Resolution:
Keywords: 2nd-opinion needs-patch | Focuses: javascript
-------------------------------------+-------------------------
Comment (by KestutisIT):
A note for those who a Googling and ending up at this bug (unexpected
behavior) page.
Even a @peterwilsoncc reply does not fix a bug for jQuery in
TwentyNineteen theme. As TwentyNineteen does not use jQuery at all.
So you have to pay attention that scripts are printed with the '20'
priority at the footer, meaning, that the workaround until the
'wp_display_script_once' function will be added to WP core, in all your
plugin's HTML templates (with .php extension), you have to use this VERY
UGLY WORKAROUND by also setting a loading priority to 100 to make it
(jQuery and jQuery DATEPICKER) to work:
{{{#!php
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies, please!' );
// Scripts
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-datepicker'); // Plugin-specific
wp_enqueue_script('jquery-ui-datepicker-locale'); // Plugin-specific
// Styles
wp_enqueue_style('jquery-ui-theme'); // Plugin-specific for datepicker
?>
<?php
// Global variable are needed here, because only then we will be able to
access them inside the 'add_action' hook
$GLOBALS['MIN_DATE'] = $minDate; // Variable is set in the current view's
controller
$GLOBALS['CONF_DATEPICKER_DATE_FORMAT'] =
$settings['conf_datepicker_date_format']; // Plugin-specific
?>
<?php add_action('wp_footer', function() { // A workaround until #48098
will be resolved ( https://core.trac.wordpress.org/ticket/48098 ). Scripts
are printed with the '20' priority. ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('.special-plugin-wrapper .pickup-date').datepicker({
minDate: "+<?=esc_js($GLOBALS['MIN_DATE']);?>D",
maxDate: "+1035D",
dateFormat:
'<?=esc_js($GLOBALS['CONF_DATEPICKER_DATE_FORMAT']);?>',
// <...> further code
});
});
</script>
<?php }, 100); ?>
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48098#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list