Skip to content

Instantly share code, notes, and snippets.

@evanre
Created October 23, 2018 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanre/b0bc4ed0cb935bdc4cbb353334dbdeb5 to your computer and use it in GitHub Desktop.
Save evanre/b0bc4ed0cb935bdc4cbb353334dbdeb5 to your computer and use it in GitHub Desktop.
Contact Form 7 Code Editor
<?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