Forked from campusboy87/code_editor_for_contact_form_7.php
Created
December 7, 2020 23:42
-
-
Save farik92/0d68b36207e97002f1a6020fe255d49f to your computer and use it in GitHub Desktop.
Code Editor for Contact Form 7 (WordPress / CodeMirror).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Code Editor for Contact Form 7 | |
| * Plugin URI: https://gist.github.com/campusboy87/2daad24e45116721759991549b626977 | |
| * Author: Campusboy (wp-plus) | |
| * Author URI: https://www.youtube.com/wp-plus | |
| */ | |
| add_action( 'admin_print_styles-toplevel_page_wpcf7', function () { | |
| if ( empty( $_GET['post'] ) ) { | |
| return; | |
| } | |
| // Подключаем редактор кода для HTML. | |
| $settings = wp_enqueue_code_editor( array( 'type' => 'text/html' ) ); | |
| // Ничего не делаем, если CodeMirror отключен. | |
| if ( false === $settings ) { | |
| return; | |
| } | |
| // Инициализация редактора для редактирования шаблона формы | |
| wp_add_inline_script( | |
| 'code-editor', | |
| sprintf( 'jQuery( function() { wp.codeEditor.initialize( "wpcf7-form", %s ); } );', wp_json_encode( $settings ) ) | |
| ); | |
| // Инициализация редактора для редактирования шаблона письма | |
| wp_add_inline_script( | |
| 'code-editor', | |
| sprintf( 'jQuery( function() { wp.codeEditor.initialize( "wpcf7-mail-body", %s ); } );', wp_json_encode( $settings ) ) | |
| ); | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment