Guest User

Untitled

a guest
Apr 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. add_action( 'wp_default_scripts', function( $scripts ) {
  2. if ( ! empty( $scripts->registered['jquery'] ) ) {
  3. $scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) );
  4. }
  5. } );
  6.  
  7. // silencer script
  8. function jquery_migrate_silencer() {
  9. // create function copy
  10. $silencer = '<script>window.console.logger = window.console.log; ';
  11. // modify original function to filter and use function copy
  12. $silencer .= 'window.console.log = function(tolog) {';
  13. // bug out if empty to prevent error
  14. $silencer .= 'if (tolog == null) {return;} ';
  15. // filter messages containing string
  16. $silencer .= 'if (tolog.indexOf("Migrate is installed") == -1) {';
  17. $silencer .= 'console.logger(tolog);} ';
  18. $silencer .= '}</script>';
  19. return $silencer;
  20. }
  21.  
  22. // for the frontend, use script_loader_tag filter
  23. add_filter('script_loader_tag','jquery_migrate_load_silencer', 10, 2);
  24. function jquery_migrate_load_silencer($tag, $handle) {
  25. if ($handle == 'jquery-migrate') {
  26. $silencer = jquery_migrate_silencer();
  27. // prepend to jquery migrate loading
  28. $tag = $silencer.$tag;
  29. }
  30. return $tag;
  31. }
  32.  
  33. // for the admin, hook to admin_print_scripts
  34. add_action('admin_print_scripts','jquery_migrate_echo_silencer');
  35. function jquery_migrate_echo_silencer() {echo jquery_migrate_silencer();}
  36.  
  37. // Set to true to prevent console output; migrateWarnings still maintained
  38. // jQuery.migrateMute = false;
  39.  
  40. add_action( 'wp_enqueue_scripts', function()
  41. {
  42. wp_add_inline_script(
  43. 'jquery-migrate', 'jQuery.migrateMute = true;',
  44. 'before'
  45. );
  46. } );
  47.  
  48. // Show a message on the console so devs know we're active
  49. if ( window.console && window.console.log ) {
  50. window.console.log( "JQMIGRATE: Migrate is installed" +
  51. ( jQuery.migrateMute ? "" : " with logging active" ) +
  52. ", version " + jQuery.migrateVersion );
  53. }
  54.  
  55. console.clear();
  56.  
  57. <?php
  58. /**
  59. * Disable jQuery Migrate in WordPress.
  60. *
  61. * @author Guy Dumais.
  62. * @link https://en.guydumais.digital/disable-jquery-migrate-in-wordpress/
  63. */
  64. add_filter( 'wp_default_scripts', $af = static function( &$scripts) {
  65. if(!is_admin()) {
  66. $scripts->remove( 'jquery');
  67. $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );
  68. }
  69. }, PHP_INT_MAX );
  70. unset( $af );
Add Comment
Please, Sign In to add comment