I want to upload images in my custom plugin options page.
<form action="?page=slideshow_options" method="post">
<input type="file" name="async-upload" id="async-upload">
<input type="submit" name="html-upload" id="html-upload" class="button" value="Upload">
</form>
If I try to check wether submit button was clicked with isset I get some weird errors. How can I get it to call a function uploadimages() for example?
Wow… this one is not a simple one… it’s not a matter of calling the magic function
uploadimages()
… I wish it would 🙂I’ve learned from a tutorial I cannot seem to find (but this one seems fair) and from analyzing other plugins.
The following is just a general orientation, sorry for not making a detailed manual. There may be flaws but hopefully you’ll manage to join the pieces and find the way to do your magic.
You’ll need to enqueue the following scripts and styles in your plugin’s page:
The upload button and the image container.
And finally, the jQuery inside the file
uploader.js
where the trick happens:These snippets were taken from a plugin of mine (which needs an update, as I learned quite a few things after releasing it).
Good luck!
File Upload using WordPress Settings API
The
register_setting
function saves the value attribute on form submission directly into the database. We can also alter or validate the value based on our choice. Theregister_setting
function takes a third argument which is a callback, this callback is fired before it saves the settings into the database.For uploading files through settings pages we can handle the uploads via the callback and then store the URL to the file in DB. Here is example code showing how to do that:
Here is a screenshot of the settings page:
Answer based on this article http://qnimate.com/file-upload-using-wordpress-settings-api/