Created
October 23, 2018 21:44
-
-
Save evanre/b0bc4ed0cb935bdc4cbb353334dbdeb5 to your computer and use it in GitHub Desktop.
Contact Form 7 Code Editor
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: Contact Form 7 Code Editor | |
* Version: 1.0.0 | |
* Plugin URI: https://latinandcode.com/ | |
* Author: Eugene Zhuchenko | |
* Author URI: eugenezhuchenko.com | |
* Text Domain: elementor-latinandcode | |
* Domain Path: /languages/ | |
* License: GPL v3 | |
*/ | |
add_action( 'admin_print_styles-toplevel_page_wpcf7', function () { | |
if ( empty( $_GET['post'] ) ) { | |
return; | |
} | |
// Include code editor for HTML. | |
$settings = wp_enqueue_code_editor( array( 'type' => 'text/html' ) ); | |
// Do nothing if CodeMirror is disabled | |
if ( false === $settings ) { | |
return; | |
} | |
// Initialize editor for contact form editing | |
wp_add_inline_script( | |
'code-editor', | |
sprintf( 'jQuery( function() { wp.codeEditor.initialize( "wpcf7-form", %s ); } );', wp_json_encode( $settings ) ) | |
); | |
// Initialize editor for email form editing | |
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