Guest User

Untitled

a guest
Mar 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks.
  2.  
  3. wp_enqueue_script('dropzone','wp-content/themes/storefront/assets/js/dropzone.js', array('jquery'));
  4. wp_enqueue_script('my-script','wp-content/themes/storefront/footer.php', array('jquery','dropzone'));
  5. $drop_param = array(
  6. 'upload'=>admin_url( 'admin-ajax.php?action=handle_dropped_media' ),
  7. 'delete'=>admin_url( 'admin-ajax.php?action=handle_delete_media' ),
  8. );
  9. wp_localize_script('my-script','dropParam', $drop_param);
  10.  
  11.  
  12.  
  13. add_action( 'wp_ajax_handle_dropped_media', 'BMP_handle_dropped_media' );
  14. add_action( 'wp_ajax_nopriv_handle_dropped_media', 'BMP_handle_dropped_media' );
  15.  
  16. function BMP_handle_dropped_media() {
  17. // status_header(200);
  18. $upload_dir = wp_upload_dir();
  19. $upload_path = $upload_dir['path'] . DIRECTORY_SEPARATOR;
  20. $num_files = count($_FILES['file']['tmp_name']);
  21. $post_id = get_the_ID();
  22.  
  23. $newupload = 0;
  24.  
  25. if ( !empty($_FILES) ) {
  26. $files = $_FILES;
  27. foreach($files as $file) {
  28. $newfile = array (
  29. 'name' => $file['name'],
  30. 'type' => $file['type'],
  31. 'tmp_name' => $file['tmp_name'],
  32. 'error' => $file['error'],
  33. 'size' => $file['size']
  34. );
  35.  
  36. $_FILES = array('upload'=>$newfile);
  37. foreach($_FILES as $file => $array) {
  38. $newupload = my_handle_attachment( $file, $post_id );
  39. }
  40. }
  41. }
  42.  
  43. echo $newupload;
  44. die();
  45. }
  46.  
  47. add_action( 'wp_ajax_handle_delete_media', 'BMP_handle_delete_media' );
  48. add_action( 'wp_ajax_nopriv_handle_delete_media', 'BMP_handle_delete_media' );
  49. function BMP_handle_delete_media(){
  50.  
  51. if( isset($_REQUEST['media_id']) ){
  52.  
  53. $post_id = absint( $_REQUEST['media_id'] );
  54.  
  55. $status = wp_delete_attachment($post_id, true);
  56.  
  57. if( $status )
  58. echo json_encode(array('status' => 'OK'));
  59. else
  60. echo json_encode(array('status' => 'FAILED'));
  61. }
  62.  
  63. die();
  64. }
Add Comment
Please, Sign In to add comment