Here is a simply code inspired by: https://wordpress.org/plugins/paste-as-plain-text-by-default/
But this is a modified version more simply, and can fit you theme functions, or in code snippet so you have control over it.
Here is the code
/**
* Enable paste as text in Classic Editor
*/
add_filter('tiny_mce_before_init', function ($init) {
$init['paste_as_text'] = true;
return $init;
});
add_filter('wpuf_textarea_editor_args', function ($args) {
$args['tinymce']['plugins'] = 'paste';
$args['tinymce']['paste_as_text'] = true;
return $args;
});
add_action('wp_footer', 'custom_paste_as_text', 9999);
add_action('admin_head', 'custom_paste_as_text', 9999);
function custom_paste_as_text()
{
if (is_user_logged_in() && ((isset($_GET['et_fb']) && $_GET['et_fb'] === '1') || (isset($_GET['page']) && $_GET['page'] === 'et_theme_builder'))) {
?>
<script>
document.addEventListener('DOMContentLoaded', function () {
tinymce.on("AddEditor", function (e) {
setTimeout(function () {
plain_text(e);
}, 300);
setTimeout(function () {
plain_text(e);
}, 1000);
setTimeout(function () {
plain_text(e);
}, 2000);
function plain_text(e) {
try {
if (e.editor.plugins.paste.clipboard.pasteFormat.get() !== 'text') {
e.editor.execCommand("mceTogglePlainTextPaste");
var notificationButton = document.querySelector('.mce-notification button');
if (notificationButton) {
notificationButton.click();
}
}
} catch (exception) {
// Prevent JS error originating from execCommand above when tinymce does not have NotificationManager
}
}
});
});
</script>
<?php
}
}
Liked this article? Please follow me on TwitterFollow @baysorensen