更新到WordPress 4.5后,在控制台中出现令人讨厌的“ JQMIGRATE:正在迁移...”
-
-
+1非常有用的强迫症.这可能来自jquery迁移/向后兼容性脚本.您有机会使用它的未缩小/开发版本吗?+1 to your very useful OCD. This probably come from the jquery migration/backward compatibility script. Any chance you use unminified/dev version of it?
- 0
- 2016-04-24
- Mark Kaplun
-
未缩小版本的迁移?据我所知,不,可能是某些插件,但是经检查,我没有看到任何插件:\Unminified version of migrate? Not to my knowledge no, it could be some plugins, but upon inspection I don't see any of it :\
- 0
- 2016-04-24
- dingo_d
-
请注意,两个版本均在WP目录中:`/wp-admin/js/jquery/jquery-migrate.js`和`/wp-admin/js/jquery/jquery-migrate.min.js`note both versions are in WP dirs: `/wp-admin/js/jquery/jquery-migrate.js` and `/wp-admin/js/jquery/jquery-migrate.min.js`
- 1
- 2016-04-25
- majick
-
6 个回答
- 投票数
-
- 2016-04-24
WordPress使用jQuery迁移脚本来确保您可能正在使用的任何插件或主题的向后兼容性,这些插件或主题使用的功能是从较新版本的jQuery中删除的.
随着WordPress 4.5的发布,他们似乎已经从 v1.2.1 " rel="nofollownoreferrer"> v1.4.0 -快速浏览代码会发现v1.4.0记录了脚本的加载情况,无论是否在未压缩的和缩小版本.
删除通知的唯一方法是确保所有插件/主题代码都不依赖任何旧的jQuery功能,然后删除迁移脚本.有一个插件可以这样做,但这是一个非常简单的方法,可以将其放置在主题的功能文件或类似文件中:
add_action('wp_default_scripts',函数($ scripts){ if(!empty($ scripts-> registered ['jquery'])){ $ scripts-> registered ['jquery']-> deps=array_diff($ scripts-> registered ['jquery']-> deps,['jquery-migrate']); } });
请注意,这不是WordPress开发的最佳做法,在我看来,不应仅出于保持开发人员控制台整洁的目的而删除迁移脚本.
WordPress uses the jQuery migrate script to ensure backwards compatibility for any plugins or themes you might be using which use functionality removed from newer versions of jQuery.
With the release of WordPress 4.5, it appears they have upgraded the version of jQuery migrate from v1.2.1 to v1.4.0 - Having a quick scan through the code reveals that v1.4.0 logs that the script is loaded regardless of whether or not the
migrateMute
option is set, in both the uncompressed and minified versions.The only way to remove the notice is to ensure all your plugins/theme code don't rely on any old jQuery functionality, and then remove the migrate script. There's a plugin out there to do this, but it's quite a simple method that can just be placed in your theme's functions file or similar:
add_action('wp_default_scripts', function ($scripts) { if (!empty($scripts->registered['jquery'])) { $scripts->registered['jquery']->deps = array_diff($scripts->registered['jquery']->deps, ['jquery-migrate']); } });
Please note that this is not considered best practice for WordPress development and in my opinion the migrate script should not be removed just for the sake of keeping the developer console clean.
-
因此,基本上我的一个插件依赖于旧jQuery版本中的一部分功能?有没有办法找出该功能是什么?或者我可以安全地将迁移脚本静音吗?So basically one of my plugins is depending on a functionality that was a part of the old jQuery version? Is there a way to find out what that functionality is? Or am I safe to just mute the migrate script?
- 0
- 2016-04-24
- dingo_d
-
我不能肯定地说您的任何插件是否都依赖于旧功能,如果您的安装中有一段时间未更新任何插件,WordPress只是将迁移脚本作为安全默认值包含在内.如果是我,我将在站点的本地安装上删除迁移脚本,然后检查一切是否仍按预期进行,确保控制台等没有错误.I can't say for sure whether any of your plugins depend on old functionality, WordPress just includes the migrate script as a safe default in case your install has any plugins which haven't been updated in a while. If it were me I'd remove the migrate script on a local install of the site and then check everything still works as expected, ensuring there are no errors in the console etc.
- 1
- 2016-04-24
- Andy
-
我反对这个.这种向后兼容性是有原因的.它与删除WordPress中已弃用的功能文件的jQuery等效.验证您的* current *设置是否完全兼容的所有麻烦甚至都没有考虑到设置或插件添加的更改,并且鉴于您将要创建的潜在问题,因此无法与删除控制台的完全可疑的好处相平衡.日志消息.I recommend against this. This backwards compatibility is there for a reason. It is the jQuery equivalent of deleting deprecated functions file in WordPress. Going to all the trouble of verifying whether your *current* setup is fully compatible does not even account for changes of setup or plugin additions, and given the potential problems you'd be creating does not balance against the completely dubious benefit of removing a console log message.
- 0
- 2016-04-25
- majick
-
@majick讨论删除脚本是否是一个好主意,超出了此答案的范围,它专门解决了如何在控制台中删除消息的问题.FWIW,我认为删除脚本也是一个坏主意.我认为毫无必要,因为我的回答很好地回答了OP的问题.@majick It's beyond the scope of this answer to discuss whether removing the script is a good idea or not, this specifically addresses the issue of how to remove the message in the console. FWIW, I think removing the script is a bad idea also. I think the downvote is uncalled for, as my answer perfectly answers the OPs question.
- 2
- 2016-04-25
- Andy
-
抱歉,我不经常投票,但是没有必要警告说这可能不是一个好主意,这与开发中的最佳实践相反(添加警告,我将删除投票).相信问题在询问如何仅删除控制台消息,而不是如何删除jquery本身.如果有人问如何在WordPress中删除更新the消息,您将不会回答"仅卸载WordPress".sorry I don't downvote often, but felt it was needed here as there is no warning that this may not be a good idea and is the opposite of best practice in development (add a warning and i'll remove the downvote.) I believe the question is asking how to remove just the console message not how to remove jquery migrate itself. if someone asked how to remove the update nag message in WordPress you wouldn't answer "just uninstall WordPress."
- 1
- 2016-04-25
- majick
-
@majick警告已添加.您是对的,问题是询问如何删除控制台消息,我的回答是,删除消息的唯一方法是删除脚本,这是正确的,除非您按照以下方法重写本机浏览器功能你的答案.@majick warning added. You're right in that the question is asking how to remove the console message, my answer states that the only way to remove the message is to remove the script, which is true unless you go down the route of rewriting native browser functions as per your answer.
- 0
- 2016-04-25
- Andy
-
没有问题,downvote被删除.对我自己而言,如果确实让我感到烦恼,那么我宁愿在每次WP升级时仅在migrationjs文件中注释掉该消息,而不是将其完全删除.仅仅因为javascript很气质,有时候一件事不合时宜,几乎所有东西都坏了..如果专门避免这种情况的话,那是太大的风险,没有收益.no probs, downvote removed. for myself, if it really annoyed me, I'd prefer to just comment out the message in the migrate js file each WP upgrade over removing it entirely anyway. just because javascript is pretty temperamental, sometimes one thing out of place and almost everything breaks.. that is just too much of a risk with no gain when this is specifically in place to avoid that.
- 1
- 2016-04-25
- majick
-
该错误消息很烦人,但是在每个新站点上删除它都是浪费时间.如果在某个地方我们可以请开发人员将消息放入Wordpress中以在下一发行版中将其删除,那将是很棒的:)This error message is annoying but removing it on every new site is a waste of time. It would be great if somewhere we could kindly ask a developer whoever put the message there in Wordpress to remove it in next release :)
- 0
- 2016-07-21
- Ivan Topić
-
@IvanTopić它不是由任何WordPress开发人员添加的,而是由jQuery团队添加的.从外观上看,它们也不是要删除的东西:https://github.com/jquery/jquery-migrate/issues/149@IvanTopić It wasn't added by any WordPress developers, it was added by the jQuery team. By the looks of things it's not something they're going to remove either: https://github.com/jquery/jquery-migrate/issues/149
- 0
- 2016-07-21
- Andy
-
- 2016-04-25
您可以在
jquery-migrate.min.js
中将日志消息文本更改为空白,但这不会在核心更新中保留.另一种方法是在迁移脚本加载之前,将
console.log
的传递/过滤器功能副本添加到迁移脚本中,并告诉它忽略包含"Migrate is installed
".这样做也会保留其他"迁移"警告:// silencer script function jquery_migrate_silencer() { // create function copy $silencer = '<script>window.console.logger = window.console.log; '; // modify original function to filter and use function copy $silencer .= 'window.console.log = function(tolog) {'; // bug out if empty to prevent error $silencer .= 'if (tolog == null) {return;} '; // filter messages containing string $silencer .= 'if (tolog.indexOf("Migrate is installed") == -1) {'; $silencer .= 'console.logger(tolog);} '; $silencer .= '}</script>'; return $silencer; } // for the frontend, use script_loader_tag filter add_filter('script_loader_tag','jquery_migrate_load_silencer', 10, 2); function jquery_migrate_load_silencer($tag, $handle) { if ($handle == 'jquery-migrate') { $silencer = jquery_migrate_silencer(); // prepend to jquery migrate loading $tag = $silencer.$tag; } return $tag; } // for the admin, hook to admin_print_scripts add_action('admin_print_scripts','jquery_migrate_echo_silencer'); function jquery_migrate_echo_silencer() {echo jquery_migrate_silencer();}
结果是在前端和后端都添加了一行HTML脚本,从而达到了预期的效果(防止安装的消息).
You could change the log message text to blank in
jquery-migrate.min.js
but this will not be preserved on core update.The alternative is to add passthrough/filter function copy of
console.log
to just before the migrate script is loaded, and tell it to ignore logging messages that contain 'Migrate is installed
'. Doing it this way will preserve other Migrate warnings too:// silencer script function jquery_migrate_silencer() { // create function copy $silencer = '<script>window.console.logger = window.console.log; '; // modify original function to filter and use function copy $silencer .= 'window.console.log = function(tolog) {'; // bug out if empty to prevent error $silencer .= 'if (tolog == null) {return;} '; // filter messages containing string $silencer .= 'if (tolog.indexOf("Migrate is installed") == -1) {'; $silencer .= 'console.logger(tolog);} '; $silencer .= '}</script>'; return $silencer; } // for the frontend, use script_loader_tag filter add_filter('script_loader_tag','jquery_migrate_load_silencer', 10, 2); function jquery_migrate_load_silencer($tag, $handle) { if ($handle == 'jquery-migrate') { $silencer = jquery_migrate_silencer(); // prepend to jquery migrate loading $tag = $silencer.$tag; } return $tag; } // for the admin, hook to admin_print_scripts add_action('admin_print_scripts','jquery_migrate_echo_silencer'); function jquery_migrate_echo_silencer() {echo jquery_migrate_silencer();}
The result is a one line of HTML script added to both frontend and backend that achieves the desired effect (prevents the installed message.)
-
+1,但如果是您的网站,最好确保所有脚本都与最新版本兼容并删除迁移器;)+1 for the idea, but if it is your site, it is probably better to just make sure all your scripts are compatible to the latest version and remove the migrator ;)
- 1
- 2016-04-25
- Mark Kaplun
-
是的,但是我完全不同意将迁移器作为一种实践来删除,因为它没有考虑安装可能与最新jQuery不兼容的主题/插件.作为一个并行工具,有许多插件仍然可以正常工作,即使它们可能尚未在此处意识到WordPress功能或已"正式"弃用.就软件外壳和软件而言,向后兼容性是预防措施,胜于解决方案.yes but I just don't agree with removing the migrator as a practice at all because it doesn't take into account installing themes/plugins which may not be compatible with the latest jQuery yet. as a parrallel there are plenty of plugins that still work fine even though they may not have realized a WordPress function here or there is "officially" deprecated. backwards compatibility is prevention and better than a cure when it comes to both cases and well, software in general.
- 0
- 2016-04-25
- majick
-
您是对的,但是IMO错误不支持最新的jquery版本.4.5大约一个月前进入了RC,如果未经过测试代码对其所有更改的支持,那么主题/插件并不是真正兼容的.在外部,wordpress弃用消息有时会变成实际弃用,并且您不希望在必须尽快升级的情况下处理它们.IMO迁移器应该是一个临时解决方案,而不是永久性功能.You are right, but not supporting the latest jquery version is a bug IMO. 4.5 went into RC about a month ago, and if code wasn't tested to work with all the changes it introduced, then the theme/plugin are not truly compatible. In the world outside wordpress deprecation messages turn into actual deprecation at some point, and you don't want to leave handling them to the time where you have to upgrade ASAP. The migrator IMO should be a temporary solution, not a permanent feature.
- 2
- 2016-04-25
- Mark Kaplun
-
我同意这是一个权宜之计,但是因此,现在实际上是最重要的时间.当然可以优化WordPress中的弃用过程,但由于deprecated.php的大小很小,因此对旧函数别名(引用新函数别名)的破坏几乎不会对性能产生影响.每天都给我一个编码良好但"旧"的插件,而不是"新"但编码不佳的插件."新的更好"的思想不应仅仅因为"哦,我们更改了该功能的名称"等而破坏了其他可以正常工作的软件.I agree it is a stop gap solution, but because of that, now is actually the time when it is most important,.! Sure the deprecation process within WordPress could be optimized but with the small size of `deprecated.php` it really has little performance impact keeping old function aliases that refer to new ones and stops things from breaking. Give me a well-coded but "old" plugin over a "new" but badly-coded plugin anyday. The ideology of "new is better" should not break otherwise good working software this way just because "oh we changed the name of that function" etc.
- 0
- 2016-04-25
- majick
-
我在这里不同意校长,互联网是一个快速发展的目标,而且格局一直在变化.(例如,在将网站徽标功能升级到4.5所需的时间之前,网站已经从仅拥有一个徽标的想法转移到了现在).仅当应用于非常具体且稳定的利基市场时,Old才是好的,但是例如jQuery被认为是一个相对移动的目标.I disagree on principals here, the internet is a fast moving target and the landscape is changing all the time. (by the time it took to get the site logo feature to 4.5 for example, sites had move on from the idea of having only one logo). Old is good only when applied to very specific and stable niches but jQuery for example is know to be a relatively moving target.
- 2
- 2016-04-25
- Mark Kaplun
-
我可以同意不同意.仅仅因为有进步和新功能,没有理由放弃旧的东西,不管它是jQuery,WordPress还是主题,插件或其他任何东西.任何代码的测试都应该是"是否可行"或"效果如何"是"不是"它有多少年历史...",而将"它有多少年历史"用作工作软件的量尺直接导致不必要地以这种方式破坏它……当新代码**是最笨拙的时候!实际上,期望开发人员跟上那些仍然可以完美运行的更新,这实在太多了–它杀死了整个企业.I can agree to disagree. Just because there is progress and new features is no reason to abandon old stuff that works, whether it's jQuery, WordPress or a theme or a plugin or whatever... The test of any code should be "does it work" or "how good is it" not "how old is it"... and using "how old is it" as a measuring stick for working software directly results in breaking it unnecessarily this way... when new code **is** the buggiest! realistically, expecting developers to keep up with updates for something that would still work perfectly otherwise is just too much - it kills entire businesses.
- 0
- 2016-04-25
- majick
-
主题不是孤立的产品.如果一个主题包装了wordpress和jquery等,那么该主题的年龄将是完全相关的.由于没有主题,如果没有针对使用的wordpress版本对主题进行测试,那么还不清楚会发现哪种错误.这只是静态与动态链接困境的另一种体现.在静态链接世界中,您的主张大体上是正确的,但wordpress是动态链接,仅因为某些东西曾与3.5一起工作并不意味着它即使在向后兼容的情况下也能与4.5一起工作.A theme is not an isolated product. If a theme was packaging wordpress and jquery etc, then the age of the theme would have been totally relevant. As no theme does that, if the theme was not tested against the version of wordpress being used, then it is not clear enough what kind of bugs will be discovered. This is just another manifestation of the static vs dynamic linking dilemma. In a static linking world your claim is mostly true, but wordpress is dynamic linking and just because something had worked with 3.5 do not mean it will work with 4.5 even with the attempt to be backcompatible
- 1
- 2016-04-25
- Mark Kaplun
-
但是让我们在这里停止讨论:),SE对它的长度不满意:)but lets stop this discussion here :), SE is not happy about the length of it :)
- 0
- 2016-04-25
- Mark Kaplun
-
- 2016-04-25
这里只是一个小测试.
我偷看了jquery-migrate.js 并注意到了这一部分:
// Set to true to prevent console output; migrateWarnings still maintained // jQuery.migrateMute = false;
所以我用新的
wp_add_inline_script()
,在版本4.5中引入:add_action( 'wp_enqueue_scripts', function() { wp_add_inline_script( 'jquery-migrate', 'jQuery.migrateMute = true;', 'before' ); } );
这将更改:
JQMIGRATE:迁移与 活动日志记录,版本1.4.0
收件人:
JQMIGRATE:已安装迁移版本1.4.0
因此,它实际上并没有阻止所有控制台输出,就像
jquery-migrate.js
中的这一部分:// Show a message on the console so devs know we're active if ( window.console && window.console.log ) { window.console.log( "JQMIGRATE: Migrate is installed" + ( jQuery.migrateMute ? "" : " with logging active" ) + ", version " + jQuery.migrateVersion ); }
Just a little test here.
I peeked into jquery-migrate.js and noticed this part:
// Set to true to prevent console output; migrateWarnings still maintained // jQuery.migrateMute = false;
so I tested the following with the newly
wp_add_inline_script()
, introduced in version 4.5:add_action( 'wp_enqueue_scripts', function() { wp_add_inline_script( 'jquery-migrate', 'jQuery.migrateMute = true;', 'before' ); } );
This will change:
JQMIGRATE: Migrate is installed with logging active, version 1.4.0
to:
JQMIGRATE: Migrate is installed, version 1.4.0
So it doesn't actually prevent all console output, like this part in
jquery-migrate.js
:// Show a message on the console so devs know we're active if ( window.console && window.console.log ) { window.console.log( "JQMIGRATE: Migrate is installed" + ( jQuery.migrateMute ? "" : " with logging active" ) + ", version " + jQuery.migrateVersion ); }
-
所以底部的代码只是删除了消息,对吗?我的意思是,迁移仍然存在,但消息被抑制了,对吗?这比绝对删除迁移要好So the bottom code just removes the message, right? I mean, the migrate stays but the message is supressed, right? This is better than removing the migrate definitely
- 1
- 2016-04-25
- dingo_d
-
不,这是产生控制台日志消息的代码的副本,该控制台日志消息确实输出.它显示仅对控制台消息的后半部分测试了migrateMute-不管是否输出前半部分... *删除*该代码块都将删除控制台消息,但是您需要重做每个WP更新.no, that is a copy of the code producing the console log message that *does* output. it shows that migrateMute is only tested for the second half of the console message - the first half is output regardless... *removing* this code block will remove the console message, but you would need to redo that each WP update.
- 1
- 2016-04-25
- majick
-
感谢您的研究和细节!IMO是最佳选择,因为删除JQmigrate并不总是一个好主意,因为许多WP插件都依赖不推荐使用的jQuery函数.该解决方案有助于清理控制台输出!Thanks for the research and details! IMO the best option, since removing JQmigrate is not always a good idea, because many WP plugins depend on deprecated jQuery functions. This solution helps to clean up the console output a bit!
- 2
- 2017-04-28
- Philipp
-
- 2018-09-21
解决方案:
将此添加到functions.php:
function remove_jquery_migrate_notice() { $m= $GLOBALS['wp_scripts']->registered['jquery-migrate']; $m->extra['before'][]='temp_jm_logconsole = window.console.log; window.console.log=null;'; $m->extra['after'][]='window.console.log=temp_jm_logconsole;'; } add_action( 'init', 'remove_jquery_migrate_notice', 5 );
当使用标准钩子(其输出
jquery-migrate
)调用<link rel=stylesheet....>
而不是使用load-scripts.php
(例如在管理控制台中).Solution:
add this to functions.php:
function remove_jquery_migrate_notice() { $m= $GLOBALS['wp_scripts']->registered['jquery-migrate']; $m->extra['before'][]='temp_jm_logconsole = window.console.log; window.console.log=null;'; $m->extra['after'][]='window.console.log=temp_jm_logconsole;'; } add_action( 'init', 'remove_jquery_migrate_notice', 5 );
It works when
jquery-migrate
is called with standard hook (which outputs<link rel=stylesheet....>
) and not withload-scripts.php
in bulk (like in admin-dashboard).-
这对我来说很好.谢谢!This works fine for me. Thank you!
- 1
- 2020-01-31
- Didierh
-
-
那对我没有用.That did not work for me.
- 3
- 2018-10-04
- Serj Sagan
-
-
- 2018-04-26
正如Andy 先前提到的那样,WordPress使用jQuery迁移脚本来确保向后兼容性 ,这就是默认情况下会自动加载它的原因.
这是删除JQuery Migrate模块的安全方法,从而摆脱了烦人的JQMIGRATE通知,同时加快了客户端页面的加载速度.只需将此代码复制/粘贴到您的functions.php 文件中,即可完成操作:
<?php /** * Disable jQuery Migrate in WordPress. * * @author Guy Dumais. * @link https://en.guydumais.digital/disable-jquery-migrate-in-wordpress/ */ add_filter( 'wp_default_scripts', $af = static function( &$scripts) { if(!is_admin()) { $scripts->remove( 'jquery'); $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' ); } }, PHP_INT_MAX ); unset( $af );
更多详细信息
要获取有关我使用静态函数的原因的更多详细信息,请在此处阅读我的文章:
►► https://en.guydumais.digital/disable-jquery-migrate -in-wordpress/As mentionned previously by Andy WordPress uses the jQuery migrate script to ensure backwards compatibility and this is why it is automatically loaded by default.
Here's a safe way to remove the JQuery Migrate module and thus get rid of the annoying JQMIGRATE notice while speeding up the loading of your page on the client side. Simply copy/paste this code in your functions.php file and you're done:
<?php /** * Disable jQuery Migrate in WordPress. * * @author Guy Dumais. * @link https://en.guydumais.digital/disable-jquery-migrate-in-wordpress/ */ add_filter( 'wp_default_scripts', $af = static function( &$scripts) { if(!is_admin()) { $scripts->remove( 'jquery'); $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' ); } }, PHP_INT_MAX ); unset( $af );
More details
To get more details about the reason I'm using a static function, read my article here:
►► https://en.guydumais.digital/disable-jquery-migrate-in-wordpress/-
拒绝投票的原因是:1.这闻起来太多了垃圾邮件,只是付出了最小的努力才觉得自己像个答案.2.硬编码使缓存无效化的版本.downvoted because 1. this smells too much of a spam and just does the minimal effort to feel like an answer. 2. You hard code the version nullifying cache busting.
- 2
- 2018-04-26
- Mark Kaplun
-
很遗憾,因为这是一种不错的方法,即使您实际上在执行操作时也使用了add_filter.its a shame because its a nice approach, even tho you're using `add_filter` when its actually an action.
- 0
- 2018-09-20
- pcarvalho
为什么会有持续的通知,
当我将主题更新为WordPress 4.5时,它指向控制台中的
load-scripts.php
,并且如何将其删除?这不是错误,但是它始终存在于控制台中,我真的看不出它的意义是什么.我应该更新某些内容还是对我的代码进行一些更改?
也许我有一些OCD,但是通常当我检查站点时,我喜欢看到错误和真实的提示,这些提示和错误提示指向控制台中的问题...
编辑
WordPress 5.5删除了jQuery Migrate脚本,作为将jQuery更新到5.6中最新版本的准备步骤.所以通知应该消失了.
https://make.wordpress.org/core/2020/06/29/updating-jquery-version-shipped-with-wordpress/