バージョン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 ) { /** * codemirror * @see https://codemirror.net/doc/manual.html#config */ $settings['codemirror'] /** * CSSLint * @see https://github.com/CSSLint/csslint/wiki */ $settings['csslint'] /** * JSHint * @see https://jshint.com/docs/options */ $settings['jshint'] /** * HTMLHint * @see https://github.com/htmlhint/HTMLHint/wiki/Rules */ $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 // $settings['jshint']['globals']['user_rates'] = true // return $settings; }
値のないアンチブートの使用を禁止する
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; }