Paste image from clipboard to upload

Would be very helpful if we could simply paste image into the media library uploader, and it would automatically upload it and set randomly generated file name.


Read-only archive: Issues · ClassicPress/ClassicPress · GitHub

Author: Viktor Nagornyy

Vote count: 4

Status: open

No comments posted.

I take a lot of screenshots or copy images to the clipboard, so I can paste them wherever I need it. This includes this forum. It saves me a TON of time. I really wish we could do this with ClassicPress, be it inside TinyMCE or media library uploader.

1 Like

I’m very against core features, because almost everything is actually plugin area. But something that I miss when editing stuff is being able to paste images into the editor and letting 'em be autouploaded for me, instead of going to Add Media → Select → Blahblahblah.

I worked on this feature for some minutes and already got it working. Thanks for @joyously for the hint of creating a TinyMCE plugin for that.

See the screenshot for a working example:

I know that now it’s a priority to make TinyMCE get integrated into core. I started looking into the issues and it’s a mess (not the issues, the issues are perfect, I mean the whole editor implementation). I am not motivated to do that. But if I have the motivation to add a new feature (find my way around the messy code and implement new clean code to satisfy a need that isn’t satisfied yet), why not doing it?

So the thing is that I got that working and I have to do some adjustments to keep stuff secure and also make it work for clipboard images (currently only works by copying an actual file from the system). But that shouldn’t be difficult.

Are you interested in having this added to the Classic Editor TinyMCE v5?

I also wanted to tweak it to be able to decide the file name via a prompt or something, that’s gonna be suppauseful for SEO purposes.

@alvarofranz I’ve merged your petition with my old petition about pasting images. I would like that feature that’s for sure. I think any time user is given an option to upload images, pasting should work too.

1 Like

Cool, so yeah I hereby ask for community feedback about adding this feature as a PR to the current ClassicEditor that is under research on GitHub, being aware that the first priority is to make the editor work 100%, but considering this a second priority that can fit the case.

1 Like

Does it attach image to the post where it is uploaded?

Sorry Viktor, I don’t know exactly what that means. It listens to the paste event on the TinyMCE editor and checks if the pasted content is an image.

If that’s the case, it uploads said image to CP via AJAX and then inserts the image into the post.

I don’t know if that’s what you mean by “attaching” it to “the post”. Note that it doesn’t always have to be “a post”. It can be any place where the TinyMCE editor is initialized: a post, a page, a custom content area, …

Attachment is in database. When you upload inside a post/page/CPT, CP will attach them to those post types. So you can filter them by images attached to that post type.

Uploading images to media library directly, uploads them unattached. Which I assume is the case here.

I believe it’s handled by wp_insert_attachment

1 Like

I disagree with this one. A randomly generated name is not optimal for SEO, and since CP is business oriented, a good business always values good SEO. And naming images properly is a must in that case. So yeah, a prompt to select the name would be the best. It can be prepopulated with a random string too.

Ahh, well that’s cool. Thanks for the info bro. I will handle that in the PHP callback that handles the AJAX upload :wink:

1 Like

Specifying name would be ideal, since we can’t rename it later. Or at least give users an option in media settings to either generate random name or keep original name.

1 Like

It seems like a good plugin.
Even if you get votes and it should go into core, it would start as a plugin in order to get everything working and testing all possibilities.

2 Likes

Definitely. It also has to be tested for security. Should only work if the user has media upload capability, should check format, filesize and so on.

My idea is to PR this into the current research plugin and work on it from there, instead of creating a new repo just for this. Is that okay?

No, please make your own plugin. It should work with the existing editor (also Media Library according to this petition) since v5.x might not make it.

1 Like

Why would v5.x not make it? It has to make it :slight_smile: The rest of issues don’t seem to be hyper major issues, and we can always work on the 100% required ones and include it for CP v2+ only and not v1. (But yeah that’s out of topic here)

According to Viktor’s command decision to merge your two petitions, it should work in several places, so that is totally different to updating the editor to a new version…so it should be a different plugin.
And with it independent, it wouldn’t have to wait for the 5.x update to be done to be considered for core.

1 Like

I’ll see how manu if/else I need to make it work for both v4 and v5. It’s just that I hate exaggerated retrocompatibility. But if it’s not a big drama, I’ll go for multiversion plugin :wink:

That part of the editor didn’t change much, so it should be no big deal.
What you have to consider is the Media Library part which doesn’t have the editor at all.

1 Like

I started creating the plugin but it’s a waste of time. I’m open to PR the functionality into the current plugin, so it can stay there ready to be merged into core. There isn’t any hurry :slight_smile:

My original petition asked for a feature to upload pasted images. I didn’t specify if it’s a TinyMCE plugin or some other integration.

Alvaro’s petition asked to add this feature using TinyMCE plugin. Which satisfies my needs in my petition.

I asked for green apples, Alvaro offered red apples. We’re still getting apples.

Petitions don’t have to be executed 100% to a T of the original request. We have petitions that morphed from the original request.

1 Like