• 0
    down vote
    favorite
    I have a button on my site (front-end) that triggers the WordPress Media Uploader, whether or not the user is logged in. It’s basically a guestbook where people can post photos. It works flawlessly if I am logged in as admin, but if I log out and use it, I get an error that simply says: “An error occurred in the upload. Please try again later.”

    I have done a bunch of reading about this on Google but have found nothing that helps. The thing is, it works great if I am logged in to WordPress.

    The files are jpg and only 150k and 300px x 300px.

    Here’s the error: https://imgur.com/a/k5ULg

    Here’s the jquery that calls the media Uploader:

    $('#upload-photo-btn').click(function(e) {
        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').css('background-image', "url("+image_url+")");
            e.preventDefault();
        });
    });

    I have wp_enqueue_media() called using the ‘wp_enqueue_scripts’ hook in my main plugin file.

    What else can be causing this?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Anything coming up in your console?

    Thread Starter poptartgun

    (@poptartgun)

    Nothing. It’s clean. I see other people have this issue all over the forums but there’s no solutions. Is it systemic?

    Thread Starter poptartgun

    (@poptartgun)

    Go to this link, click the Photos tab then Share a Photo to see what I mean:

    https://www.northernfjell.com/clients/cremation-demo/obituary/mark-anthony-piper-tyler-07172016/

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    How did you investigate that all people have this issue? It is really difficult to identify that. What people often do is see the same symptom and assume that the underlying issue is the same.

    Thread Starter poptartgun

    (@poptartgun)

    This is how I enqued it:

    /**
         * Register plugin assets
         */
        add_action( 'admin_enqueue_scripts', 'gsob_load_admin_assets' );
        add_action( 'wp_enqueue_scripts', 'gsob_load_assets' );
    
        /**
         * Enqueue admin panel plugin assets
         */
        function gsob_load_admin_assets() {
            // plugin specific CSS
            wp_enqueue_style( 'gsob-admin-style', plugins_url('css/gsob-admin-style.css', __FILE__));
            wp_enqueue_style('font-awesome', plugins_url('css/font-awesome.min.css', __FILE__));
            wp_enqueue_style('e2b-admin-ui-css','https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false);
    
            // plugin specific javascript
            wp_enqueue_media();
            wp_enqueue_script('jquery-ui-datepicker');
            wp_enqueue_script('gsob-admin-script', plugins_url('js/gsob-admin-script.js', __FILE__), array('jquery'));
        }
    
        /**
         * Enqueue admin panel plugin assets
         */
        function gsob_load_assets() {
            // plugin specific CSS
            wp_enqueue_style( 'gsob-style', plugins_url('css/gsob-style.css', __FILE__));
            wp_enqueue_style('font-awesome', plugins_url('css/font-awesome.min.css', __FILE__));
            wp_enqueue_style('e2b-admin-ui-css','https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false);
    
            // plugin specific javascript
            wp_enqueue_media();
            wp_enqueue_script('jquery-ui-datepicker');
            wp_enqueue_script('gsob-script', plugins_url('js/gsob-script.js', __FILE__), array('jquery'));
        }
    Thread Starter poptartgun

    (@poptartgun)

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Thread Starter poptartgun

    (@poptartgun)

    Yeah one second.

    Thread Starter poptartgun

    (@poptartgun)

    ok its in debug, I see a few errors.

    Thread Starter poptartgun

    (@poptartgun)

    AFAIK my stuff is enqued correctly, I posted it above.

    Thread Starter poptartgun

    (@poptartgun)

    I have cleared all the errors and the problem persists. The site is currently in debug mode. I have disabled all other plugins and the problem persists.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘WordPress media upload causes errors when not logged in’ is closed to new replies.