Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda