title: User become logged out when upload image from wp media wordpress
body: <p>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 </p>
  
  <blockquote>
    <p>An error occurred in the upload. Please try again later.</p>
  </blockquote>
  
  <p>And if i refresh page, it logged out the user.</p>
  
  <p>The same procedure if followed by admin user then everything works fine.</p>
  
  <p>Here is the code for the image uploading:</p>
  
  <pre><code> &lt;i class="fa fa-cloud-upload" &gt;&lt;/i&gt;
   &lt;input class="criteria-file button" id="your_image_url_button" type="button" value="Upload File"/&gt;
   &lt;script&gt;
  
                                  var image_custom_uploader_file;
  
                                  var $thisItem = '';
  
  
  
                                  jQuery(document).on('click','.criteria-file', function(e) {
  
                                      e.preventDefault();
  
  
  
                                      $thisItem = jQuery(this);
  
  
  
                                      //If the uploader object has already been created, reopen the dialog
  
                                      if (image_custom_uploader) {
  
                                          image_custom_uploader.open();
  
                                          return;
  
                                      }
  
  
  
                                      //Extend the wp.media object
  
                                      image_custom_uploader_file = wp.media.frames.file_frame = wp.media({
  
                                          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-image-url').val(url);
  
                                          $thisItem.parent().parent().parent().find('.criteria-image-url-name').val(filename);
  
                                          $thisItem.parent().parent().parent().find('.file-name').val(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
  
                                      image_custom_uploader_file.open();
  
                                   });
  
  
  
                                   jQuery(document).on('click','.criteria-file-remove', function(e) {
  
                                      jQuery(this).parent().parent().parent().find('.criteria-image-url').val('');
  
                                      jQuery(this).parent().parent().parent().find('.criteria-image-url-name').val('');
  
                                      jQuery(this).parent().parent().parent().find('.file-name').val('');
  
                                      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");
  
                                   });
  
                              &lt;/script&gt;
  </code></pre>
  
  <p>I tried to increase define( 'WP_MEMORY_LIMIT', '512M' ); but didn't work.</p>
  
  <p>Anyone can suggest me how i can fix this issue.</p>
  
  <p>Thanks in Advance.</p>