How to disable TinyMce's Paste plugin from turning image URLs into embedded <img>?

TinyMCE's Paste plugin automatically turns pasted image URLs into embedded images. docspluginspasteI need to di

TinyMCE's Paste plugin automatically turns pasted image URLs into embedded images. /docs/plugins/paste/

I need to disable this behavior since I use TinyMCE in a forum on the frontend and I don't want to allow image embedding.

TinyMCE's Paste plugin automatically turns pasted image URLs into embedded images. https://www.tiny.cloud/docs/plugins/paste/

I need to disable this behavior since I use TinyMCE in a forum on the frontend and I don't want to allow image embedding.

Share Improve this question edited Apr 19, 2019 at 21:30 Florian Walther asked Apr 19, 2019 at 21:25 Florian WaltherFlorian Walther 1591 silver badge8 bronze badges 3
  • 1 It works only on image URLs ending with .gif, .jpg, .jpeg or .png (like this image) and it is one of the "smart paste" features in TinyMCE, and you can disable it (the feature) by setting smart_paste to false like this. However, you should know that disabling it will also disable (as of now, two) other "smart paste" features. – Sally CJ Commented Apr 20, 2019 at 4:43
  • @SallyCJ Thank you, it works! Once again you save me when I couldn't find a solution anywhere! How do you know all this stuff? Not even in the TinyMCE community I got an answer to this! – Florian Walther Commented Apr 20, 2019 at 9:56
  • Check my answer. :) – Sally CJ Commented Apr 20, 2019 at 16:56
Add a comment  | 

1 Answer 1

Reset to default 1

automatically turns pasted image URLs into embedded images

Yes, but only for URLs ending with .gif, .jpg, .jpeg and .png.

And that conversion is one of the "smart paste" features in TinyMCE — another one is when you select a text and paste an absolute URL (that begins with http or https), the text is automatically converted to a hyperlink (clickable link).

The relevant code is below which you can find in wp-includes/js/tinymce/plugins/paste/plugin.js which ships with WordPress — and as of writing, WordPress is still using TinyMCE version 4.9.2.

var insertContent = function (editor, html) {
  if (Settings.isSmartPasteEnabled(editor) === false) {
    pasteHtml(editor, html);
  } else {
    smartInsertContent(editor, html);
  }
};

And if you look at the code, the smart paste features are being applied only if the isSmartPasteEnabled function returns true. The function code:

var isSmartPasteEnabled = function (editor) {
  return editor.getParam('smart_paste', true);
};

So that function basically simply checks whether the editor configuration has the smart_paste option enabled — and it is by default enabled.

Therefore, if you'd like to disable the smart paste features, just set the smart_paste option to false. See example below and try a demo here:

tinymce.init({
  smart_paste: false,
  selector: 'textarea',
  plugins: 'paste'
 });

Disable the smart paste features via wp_editor()

It's very easy. Just set smart_paste to false in the tinymce array:

$content = '<p>Paste an image URL:</p>';
wp_editor( $content, 'editor-id', array(
    'tinymce' => array(
        'smart_paste' => false,
    ),
) );

But remember this..

Setting the smart_paste option to false will disable all smart paste features. If you want to disable just the image URL-to-img-tag conversion, then I think you'd have to copy the Paste plugin and edit where necessary.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745570495a4633651.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信