关于如何在内置WordPress代码编辑器中配置linting规则的猫,下面有个小注释。
从
4.9版开始,
CodeMirror已集成在WordPress中。 它支持超过100种语言的语法高亮显示,并且还具有内置的代码分析器。
因此,
wp_code_editor_settings过滤器将帮助我们更改参数
。第一个参数,它使用代码编辑器的选项数组。 在其中,我们仅对一些属性感兴趣。
有关详细信息,请参见文档 。
add_filter( 'wp_code_editor_settings', 'change_code_editor_settings'); function change_code_editor_settings( $settings ) { $settings['codemirror'] $settings['csslint'] $settings['jshint'] $settings['htmlhint'] return $settings; }
例子
关闭CSSLint检查,同时保留语法突出显示 。 (如果在css主题中使用变量,这可能会很有用。
#720 )
add_filter( 'wp_code_editor_settings', 'disable_csslint' ); function disable_csslint( $settings ){ if ($settings['codemirror']['mode'] === 'css') { $settings['codemirror']['lint'] = false; } return $settings; }
注册全局变量。 add_filter( 'wp_code_editor_settings', 'change_code_editor_settings'); function change_code_editor_settings( $settings ) { $settings['jshint']['globals']['axios'] = false
禁止使用无值的反引导 add_filter( 'wp_code_editor_settings', 'change_code_editor_settings'); function change_code_editor_settings( $settings ) { $settings['htmlhint']['attr-value-not-empty'] = true return $settings; }