Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
contact form 7 mail body with CodeMirror and TinyMCE

i try add wp_enqueue_code_editor (codemirror) and wp_editor (tinymce) in editor mail body and switch between them through checkbox "Use HTML content type".

tinymce connected to form

add_action( 'admin_enqueue_scripts', 'cf7_email_editor_scripts' );
function cf7_email_editor_scripts(){
    if( isset( $_GET['page'], $_GET['post'] ) ){
        if( $_GET['page'] == 'wpcf7' ){
            wp_enqueue_script( 'jquery' );
            wp_enqueue_script( 'wp-tinymce' );
            wp_enqueue_script( 'editor_js', admin_url('js/editor.js'), array(), false, true );
            wp_enqueue_script( 'cf7_email_editor', plugin_dir_url( __FILE__ ) . '/tinymce-init.js', array(), 1, true );
            wp_enqueue_style( 'tinymce_css', includes_url('css/editor.css') );
        }
    }
}

html switch work via js

jQuery( document ).ready(function($){
    $(window).on('load', function(){
        init_cf7ee_tinyMCE();
    });
    $('#wpcf7-mail-use-html, #wpcf7-mail-2-use-html').change(function(event) {
        init_cf7ee_tinyMCE();
    });
});
function init_cf7ee_tinyMCE(){
    tinyMCE.remove();
    var tinymce_elements = [];
    if( jQuery('#wpcf7-mail-use-html').prop('checked') ) tinymce_elements.push('wpcf7-mail-body');
    if( jQuery('#wpcf7-mail-2-use-html').prop('checked') ) tinymce_elements.push('wpcf7-mail-2-body');
    tinyMCE.init({
        mode: 'exact',
        elements: tinymce_elements.join(','),
        menubar: true
    });
}

this construction works fine
have two elements: DIV tinymce and textarea wpcf7
and switches between them
but if add wp_enqueue_code_editor appears third element DIV CodeMirror's and tiny stops switching

add_action( 'admin_print_styles-toplevel_page_wpcf7', function () {
    $settings = wp_enqueue_code_editor( array( 'type' => 'text/html' ) );
    wp_add_inline_script('code-editor', sprintf( 'jQuery( function() { wp.codeEditor.initialize( "wpcf7-mail-body", %s ); } );', wp_json_encode( $settings ) ));
    wp_add_inline_script('code-editor', sprintf( 'jQuery( function() { wp.codeEditor.initialize( "wpcf7-mail-2-body", %s ); } );', wp_json_encode( $settings ) ));
} );

can someone have a "contact form 7" nearby and tell me what my mistake is

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda