Guest User

Untitled

a guest
Sep 22nd, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. // Process the edit form
  2. add_action('wp_ajax_process_edit_form', 'process_edit_form');
  3. function process_edit_form() {
  4.  
  5. require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  6. require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  7. require_once(ABSPATH . "wp-admin" . '/includes/media.php');
  8.  
  9. $image_file = $_POST['imageFile'];
  10. $image_file_name = $_POST['imageFileName'];
  11.  
  12. $post_to_edit = get_post($_POST['postId']);
  13.  
  14. // Set Image File
  15. if ($image_file["size"] > 0) {
  16. $cover_art_id = media_handle_sideload( $album_cover, $pid );
  17. wp_set_object_terms( $cover_art_id, 'cover_art', 'category');
  18. update_post_meta($pid,'music_art',$cover_art_id);
  19. }
  20.  
  21.  
  22. }
  23.  
  24. <form enctype="multipart/form-data">
  25. <input type="file" name="image_file" id="image_file" />
  26. <input type="submit" value="Save Changes" tabindex="6" id="submit" name="submit" data-id="<?php echo $post->ID; ?>" />
  27. </form>
  28.  
  29. $(document).on("click","#submit", function(e) {
  30. e.preventDefault();
  31. $this = $(this);
  32. postId = $this.data("id");
  33. imageFile = $this.closest("form").find("#image_file").val();
  34. if (imageFile != "") {
  35. imageFileName = $this.closest("form").find("#image_file").val().split('\').pop();
  36. } else {
  37. imageFileName = "none";
  38. };
  39. data = {
  40. action: 'process_edit_form',
  41. postId : postId,
  42. imageFile : imageFile,
  43. imageFileName : imageFileName
  44. };
  45. $.post(ajaxurl, data, function (response) {
  46. });
  47. });
  48.  
  49. $ajaxurl = "<?php echo admin_url('admin-ajax.php');? >";
  50.  
  51. var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
  52. var formData = new FormData();
  53.  
  54. formData.append('$Parent_Post_ID', $Parent_Post_ID;
  55. formData.append('$thevideo', $thevideo);
  56. formData.append('action', 'watermark'); // action should be the name of the function you want to call in your functions.php
  57.  
  58. $.ajax({
  59. url: ajaxurl,
  60. type: 'POST',
  61. data:formData,
  62. cache: false,
  63. //async: false,
  64. processData: false, // Don't process the files
  65. contentType: false, // Set content type to false as jQuery will tell the server its a query string request
  66. success:function(data) {
  67. //alert(data);
  68. //data can consist of anything you want to retrieve from the process
  69.  
  70. var datarray = data.split(',');
  71.  
  72. $attach_id = datarray[0];
  73. $whatever = datarray[1];
  74. $whatever = datarray[2];
  75.  
  76.  
  77. alert('All Done :)');
  78.  
  79. } // END Ajax Success
  80.  
  81. }); // END Ajax Request
  82.  
  83. $attach_id = media_handle_upload($file_handler,$Parent_Post_ID );
Add Comment
Please, Sign In to add comment