User become logged out when upload image from wp media wordpress

I have a website where user can register and update their profile info. Subscriber user role assigned to them. For updating image i am using wp media uploader. When a subscriber user upload their profile image using and choose file locally, it show me error

An error occurred in the upload. Please try again later.

And if i refresh page, it logged out the user.

The same procedure if followed by admin user then everything works fine.

Here is the code for the image uploading:

 <i class="fa fa-cloud-upload" ></i>
 <input class="criteria-file button" id="your_image_url_button" type="button" value="Upload File"/>

                                var image_custom_uploader_file;

                                var $thisItem = '';

                                jQuery(document).on('click','.criteria-file', function(e) {


                                    $thisItem = jQuery(this);

                                    //If the uploader object has already been created, reopen the dialog

                                    if (image_custom_uploader) {




                                    //Extend the object

                                    image_custom_uploader_file = ={

                                        title: 'Choose File',

                                        button: {

                                            text: 'Choose File'


                                        multiple: false


                                    //When a file is selected, grab the URL and set it as the text field's value

                                    image_custom_uploader_file.on('select', function() {

                                        attachment = image_custom_uploader_file.state().get('selection').first().toJSON();

                                        var url = '';

                                        url = attachment['url'];

                                        var filename ='';

                                        filename = attachment['filename'];




                                        $thisItem.parent().parent().parent().find('.criteria-file').css("display", "none");

                                        $thisItem.parent().parent().parent().find('.criteria-file-remove').css("display", "block");

                                        $thisItem.parent().parent().parent().find(".fa-cloud-upload").css("display", "none");

                                        $thisItem.parent().parent().parent().find(".fa-trash-o").css("display", "block");


                                    //Open the uploader dialog



                                 jQuery(document).on('click','.criteria-file-remove', function(e) {




                                    jQuery(this).parent().parent().parent().find('.criteria-file').css("display", "block");

                                    jQuery(this).parent().parent().parent().find(".fa-cloud-upload").css("display", "block");

                                    jQuery(this).parent().parent().parent().find(".fa-trash-o").css("display", "none");

                                    jQuery(this).css("display", "none");



I tried to increase define( ‘WP_MEMORY_LIMIT’, ‘512M’ ); but didn’t work.

Anyone can suggest me how i can fix this issue.

Thanks in Advance.

Read more here: User become logged out when upload image from wp media wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *