[wp-trac] [WordPress Trac] #37110: Update to jQuery 3.*
WordPress Trac
noreply at wordpress.org
Sun Nov 24 09:47:24 UTC 2019
#37110: Update to jQuery 3.*
-------------------------------------------------+-------------------------
Reporter: jorbin | Owner: (none)
Type: task (blessed) | Status: new
Priority: normal | Milestone: Future
| Release
Component: External Libraries | Version:
Severity: critical | Resolution:
Keywords: early has-patch needs-testing | Focuses: javascript
needs-dev-note needs-screenshots needs- |
refresh |
-------------------------------------------------+-------------------------
Comment (by remzicavdar):
Hi @jacklinkers
You're right about adding a plugin, but I think this is different when
you're able to see the source code. The plugin is completely open source:
https://github.com/Remzi1993/jquery-manager and
https://wordpress.org/plugins/jquery-manager/
I take security very seriously, that's why we made a WP plugin at my
previous job/company and decided to make this open source, so others are
also able to benefit. Other devs have also contributed to the code and
even someone has patched older versions of jQuery.
I hope you're able to change/patch jQuery by yourself or should some code
from the plugin yourself. See example code:
{{{#!php
<?php
// Front-end not excuted in the wp admin and the wp customizer (for
compatibility reasons)
// See: https://core.trac.wordpress.org/ticket/45130 and
https://core.trac.wordpress.org/ticket/37110
function wp_jquery_manager_plugin_front_end_scripts() {
$wp_admin = is_admin();
$wp_customizer = is_customize_preview();
// jQuery
if ( $wp_admin || $wp_customizer ) {
// echo 'We are in the WP Admin or in the WP Customizer';
return;
}
else {
// Deregister WP core jQuery, see https://github.com/Remzi1993/wp-
jquery-manager/issues/2 and
https://github.com/WordPress/WordPress/blob/91da29d9afaa664eb84e1261ebb916b18a362aa9
/wp-includes/script-loader.php#L226
wp_deregister_script( 'jquery' ); // the jquery handle is just an
alias to load jquery-core with jquery-migrate
// Deregister WP jQuery
wp_deregister_script( 'jquery-core' );
// Deregister WP jQuery Migrate
wp_deregister_script( 'jquery-migrate' );
// Register jQuery in the head
wp_register_script( 'jquery-core',
'https://code.jquery.com/jquery-3.3.1.min.js', array(), null, false );
/**
* Register jquery using jquery-core as a dependency, so other
scripts could use the jquery handle
* see https://wordpress.stackexchange.com/questions/283828/wp-
register-script-multiple-identifiers
* We first register the script and afther that we enqueue it, see
why:
* https://wordpress.stackexchange.com/questions/82490/when-
should-i-use-wp-register-script-with-wp-enqueue-script-vs-just-wp-enque
* https://stackoverflow.com/questions/39653993/what-is-diffrence-
between-wp-enqueue-script-and-wp-register-script
*/
wp_register_script( 'jquery', false, array( 'jquery-core' ), null,
false );
wp_enqueue_script( 'jquery' );
}
}
add_action( 'wp_enqueue_scripts',
'wp_jquery_manager_plugin_front_end_scripts' );
function add_jquery_attributes( $tag, $handle ) {
if ( 'jquery-core' === $handle ) {
return str_replace( "type='text/javascript'",
"type='text/javascript'
integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8='
crossorigin='anonymous'", $tag );
}
return $tag;
}
add_filter( 'script_loader_tag', 'add_jquery_attributes', 10, 2 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37110#comment:82>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list