Sometimes we want to just stick with the text mode while writing content. For me, the visual mode is less helpful specially when i write tutorials like this. Switching to visual mode will ruin the code embedded intended to show up in the front-end.

To avoid mistake of switching the editor to visual mode, i disable the Visual mode of the text editor. The code snippet below successfully ends up my headache.

add_filter( 'user_can_richedit', 'disable_my_visual_editor');
function disable_my_visual_editor( $rich ) {
    
    return false;

}

Custom Post Type

If you only want to disable the visual mode when editing post of a custom post type, this is what you need.

add_filter( 'user_can_richedit', 'disable_my_visual_editor');
function disable_my_visual_editor( $rich ) {
    global $post_type;

    if( 'post' == $post_type )
        return false;

    return $rich;
}