Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Process the edit form
- add_action('wp_ajax_process_edit_form', 'process_edit_form');
- function process_edit_form() {
- require_once(ABSPATH . "wp-admin" . '/includes/image.php');
- require_once(ABSPATH . "wp-admin" . '/includes/file.php');
- require_once(ABSPATH . "wp-admin" . '/includes/media.php');
- $image_file = $_POST['imageFile'];
- $image_file_name = $_POST['imageFileName'];
- $post_to_edit = get_post($_POST['postId']);
- // Set Image File
- if ($image_file["size"] > 0) {
- $cover_art_id = media_handle_sideload( $album_cover, $pid );
- wp_set_object_terms( $cover_art_id, 'cover_art', 'category');
- update_post_meta($pid,'music_art',$cover_art_id);
- }
- }
- <form enctype="multipart/form-data">
- <input type="file" name="image_file" id="image_file" />
- <input type="submit" value="Save Changes" tabindex="6" id="submit" name="submit" data-id="<?php echo $post->ID; ?>" />
- </form>
- $(document).on("click","#submit", function(e) {
- e.preventDefault();
- $this = $(this);
- postId = $this.data("id");
- imageFile = $this.closest("form").find("#image_file").val();
- if (imageFile != "") {
- imageFileName = $this.closest("form").find("#image_file").val().split('\').pop();
- } else {
- imageFileName = "none";
- };
- data = {
- action: 'process_edit_form',
- postId : postId,
- imageFile : imageFile,
- imageFileName : imageFileName
- };
- $.post(ajaxurl, data, function (response) {
- });
- });
- $ajaxurl = "<?php echo admin_url('admin-ajax.php');? >";
- var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
- var formData = new FormData();
- formData.append('$Parent_Post_ID', $Parent_Post_ID;
- formData.append('$thevideo', $thevideo);
- formData.append('action', 'watermark'); // action should be the name of the function you want to call in your functions.php
- $.ajax({
- url: ajaxurl,
- type: 'POST',
- data:formData,
- cache: false,
- //async: false,
- processData: false, // Don't process the files
- contentType: false, // Set content type to false as jQuery will tell the server its a query string request
- success:function(data) {
- //alert(data);
- //data can consist of anything you want to retrieve from the process
- var datarray = data.split(',');
- $attach_id = datarray[0];
- $whatever = datarray[1];
- $whatever = datarray[2];
- alert('All Done :)');
- } // END Ajax Success
- }); // END Ajax Request
- $attach_id = media_handle_upload($file_handler,$Parent_Post_ID );
Add Comment
Please, Sign In to add comment