[wp-trac] [WordPress Trac] #45130: Defer jQuery WordPress Admin & Customizer doesn't work properly

WordPress Trac noreply at wordpress.org
Tue Oct 30 13:03:33 UTC 2018


#45130: Defer jQuery WordPress Admin & Customizer doesn't work properly
----------------------------+------------------------------
 Reporter:  remzicavdar     |       Owner:  (none)
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Administration  |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  needs-patch     |     Focuses:  javascript
----------------------------+------------------------------

Comment (by remzicavdar):

 Hi @dlh

 I have made a WordPress plugin to deal with these problems, see:
 https://github.com/Remzi1993/wp-jquery-updater

 My plugin is adds the latest stable version of jQuery and jQuery Migrate
 to WordPress and only on the frontend.
 {{{#!php
 <?php
 // Front-end not executed in the admin and the customizer (for
 compatibility reasons)
 // See: https://core.trac.wordpress.org/ticket/45130 and
 https://core.trac.wordpress.org/ticket/37110
 function wpj_updater_plugin_front_end_scripts() {
     $wp_admin = is_admin();
     $wp_customizer = is_customize_preview();

     if ( $wp_admin || $wp_customizer ) {
         // echo 'We are in the WP Admin or in the WP Customizer';
     }
     else {
         $plugin = new wpj_updater_plugin;

         // Deregister WP core jQuery
         wp_deregister_script('jquery');
         // Enqueue jQuery in the footer
         wp_enqueue_script( 'jquery', $plugin->jquery, array(), null, true
 );

         // Deregister WP core jQuery Migrate
         wp_deregister_script('jquery-migrate');
         // Enqueue jQuery Migrate in the footer
         wp_enqueue_script( 'jquery-migrate', $plugin->jquery_migrate,
 array(), null, true );
     }

 }
 add_action( 'wp_enqueue_scripts', 'wpj_updater_plugin_front_end_scripts'
 );
 }}}

 Before that I used jQuery Updater plugin: https://wordpress.org/plugins
 /jquery-updater/
 This is considered bad practice, because it's also affecting WP backend
 and WP customizer:

 {{{#!php
 <?php
 function rw_jquery_updater()
 {

     // jQuery
     // Deregister core jQuery
     wp_deregister_script('jquery');
     // Register
     wp_enqueue_script('jquery', plugins_url('/js/jquery-3.3.1.min.js',
 __FILE__), false, '3.3.1');

     // jQuery Migrate
     // Deregister core jQuery Migrate
     wp_deregister_script('jquery-migrate');
     // Register
     wp_enqueue_script('jquery-migrate', plugins_url('/js/jquery-
 migrate-3.0.0.min.js', __FILE__), array(
         'jquery'
     ), '3.0.0'); // require jquery, as loaded above
 }

 /**
  * Front-End
  */
 add_action('wp_enqueue_scripts', 'rw_jquery_updater');
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45130#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list