0

I am using wp_edior.

Here is the scenario :

  1. Click bold, italic, bullets and write 1 line.
  2. Now press enter

Bold and italic buttons gets unchecked.

enter image description here

I tried below solution but it did not work for me.

add_filter( 'tiny_mce_before_init', 'wpse24113_tiny_mce_before_init' );
function wpse24113_tiny_mce_before_init( $initArray )
{
    $initArray['setup'] = <<<JS
[function(ed) {
    ed.onKeyDown.add(function(ed, e) {
        //your function goes here
        console.log('Key down event: ' + e.keyCode);
        if($(".mce-container.mce-btn-group .mce-btn:nth-child(2)").hasClass("mce-active") && (e.keyCode == 13)){
            console.log("active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(2)").addClass("mce-active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(2)").attr("aria-pressed","true");
        }
        if($(".mce-container.mce-btn-group .mce-btn:nth-child(3)").hasClass("mce-active") && (e.keyCode == 13)){
            console.log("active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(3)").addClass("mce-active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(3)").attr("aria-pressed","true");
        }
        if($(".mce-container.mce-btn-group .mce-btn:nth-child(4)").hasClass("mce-active") && (e.keyCode == 13)){
            console.log("active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(4)").addClass("mce-active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(4)").attr("aria-pressed","true");
        }
        if($(".mce-container.mce-btn-group .mce-btn:nth-child(5)").hasClass("mce-active") && (e.keyCode == 13)){
            console.log("active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(5)").addClass("mce-active");
            $(".mce-container.mce-btn-group .mce-btn:nth-child(5)").attr("aria-pressed","true");
        }
    });

}][0]
JS;
    return $initArray;
}

Need a proper solution.

2
  • I managed to replicate this using the text widget in the admin area. You should probably open a bug report with WP Core on their trac instance, this doesn't look like something you should ask for a quickfix online in communities, but something WP itself needs to fix
    – Tom J Nowell
    Apr 7 '20 at 15:45
  • @TomJNowell will do that. Thank you for this suggestion. Apr 8 '20 at 5:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.