Custom Wordpress Plugin - How do I insert content

2019-08-07 04:07发布

问题:

I've created my own plugin for WordPress, but it's not completely functional. My goal is to add an additional button to the Post Editor that allows you to insert an image (that you upload from your computer, and automatically gets modified after upload) into the post.

When you click on the button, my popup that I created in my plugin shows up. I go through the upload process and the image is uploaded and modified. Now, how do I insert the image into the post?

This is my code so far:

function insertHeader(imageURL){
    text = '<div style="text-align:center;"><img src="'+imageURL+'"/></div>';
    tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, text);
}

But obviously it doesn't work. I can't seem to find a good tutorial that shows you how. I've got this far just by looking at other plugins.

回答1:

try getting idea from the media-upload.php and upload.php of wp-admin