您可以在中将日志消息文本更改为空白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脚本,以达到所需的效果(防止安装消息)