Allow media uploader while not logged in
-
I am building a custom WordPress plugin. In the admin panel I successfully used the Media Uploader to allow admin to upload photos. I want to do the same on the frontend, for users, even if they are not logged in. It is basically a public guestbook type app.
In my main plugin file I have enqueued the media library for both admin and normal with wp_enqueue_media(), inside of hooks for admin_enqueue_scripts() and wp_enqueue_scripts().
I also have the Media Library tab hidden from the public. Changing that doesn’t affect this bug though.
I have a button that triggers the javascript, which is here:
$('#upload-photo-btn').click(function(e) { e.preventDefault(); var image = wp.media({ title: 'Upload Image', multiple: false }).open() .on('select', function(e){ var uploaded_image = image.state().get('selection').first(); var image_url = uploaded_image.toJSON().url; $('#image_url').val(image_url); $('.thumbnail img').attr('src', image_url); }); }); });
If I am logged into WordPress as admin, and I use the frontend form to upload an image, it works perfectly. However, if I logout and try as a pedestrian user, I get an error, like this:
The image doesn’t upload, I get the red error and the “Search Media” spinner keeps spinning. Is there something I am missing?
[ No bumping please. ]
- The topic ‘Allow media uploader while not logged in’ is closed to new replies.