Forked from campusboy87/code_editor_for_contact_form_7.php
Created
July 17, 2018 19:51
-
-
Save sxidsvit/07f07a10de7f0ab7e0d2a21887609b7b to your computer and use it in GitHub Desktop.
Code Editor for Contact Form 7 (WordPress / CodeMirror).
This file contains 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