From 66cfd8dff4014d994b40321b1c8d315182858fb5 Mon Sep 17 00:00:00 2001 From: Luca Rullo Date: Tue, 13 Dec 2022 22:59:00 +0100 Subject: [PATCH] Fix: Failed Remove Media Item --- js/soundmap.add.js | 9 ++-- soundmap.php | 107 +++++++++++++++++++-------------------------- 2 files changed, 51 insertions(+), 65 deletions(-) diff --git a/js/soundmap.add.js b/js/soundmap.add.js index 53deb68..98c9551 100644 --- a/js/soundmap.add.js +++ b/js/soundmap.add.js @@ -63,15 +63,15 @@ initEvents: function(){ $('#add_files').bind('click', this.openMediaManager); wp.media.frames.file_frame.on('select',this.mediaSelected, this); - $('.delete-att-item').live('click', this.removeMedia); - setTimeout(() => { this.map.invalidateSize(); }, 0); + $('.att-info').on('click','.delete-att-item', this.removeMedia); + setTimeout(() => { this.map.invalidateSize(); }, 0); }, removeMedia: function(event){ $(event.currentTarget).parents('.soundmap-attach-item').remove(); }, openMediaManager: function(event){ - this.file_frame = wp.media.frames.file_frame + this.file_frame = wp.media.frames.file_frame event.preventDefault(); if ( this.file_frame ){ this.file_frame.open(); @@ -90,6 +90,7 @@ id: attachment.id }); $('#soundmap-attachments-list').append(_o); + $('.att-info').on('click','.delete-att-item', this.removeMedia); }, @@ -115,7 +116,7 @@ $(document).ready(function(){ - console.log($('#map_canvas').width()); + //console.log($('#map_canvas').width()); // Add Timeout for wait load metabox setTimeout(function() { soundmap.initMap(); diff --git a/soundmap.php b/soundmap.php index f57e3e8..0259871 100644 --- a/soundmap.php +++ b/soundmap.php @@ -81,12 +81,13 @@ if (!class_exists('Soundmap')){ function metaboxes_register_callback(){ add_meta_box('soundmap-map', __("Place the Marker", 'soundmap'), array($this, 'map_meta_box'), 'marker', 'normal', 'high'); - add_meta_box('soundmap-email', __("Uploader Mail", 'soundmap'), array($this,'soundmap_email_meta_box'), 'marker', 'side', 'low'); - add_meta_box('soundmap-sound-info', __("Info", 'soundmap'), array($this,'info_meta_box'), 'marker', 'side', 'high'); - add_meta_box('soundmap-sound-attachments', __("Media files attached.", 'soundmap'), array($this, 'attachments_meta_box'), 'marker', 'side', 'high'); + add_meta_box('soundmap-media-info', __("Info", 'soundmap'), array($this,'info_meta_box'), 'marker', 'side', 'high'); + add_meta_box('soundmap-media-attachments', __("Media files attached.", 'soundmap'), array($this, 'attachments_meta_box'), 'marker', 'side', 'high'); + // Ya no es necesario + //add_meta_box('soundmap-email', __("Uploader Mail", 'soundmap'), array($this, 'email_meta_box'), 'marker', 'side', 'low'); } //metaboxes_register_callback - function soundmap_email_meta_box(){ + function email_meta_box(){ global $post; $mail = get_post_meta($post->ID, 'EMAIL', TRUE); echo "

" . $mail . "

"; @@ -106,23 +107,19 @@ if (!class_exists('Soundmap')){ global $post; $files = get_post_meta($post->ID, 'soundmap_attachments_id', FALSE); - echo '
'; - echo '
'; + echo '
'; + echo '
'; $out = ''; if ($files){ foreach($files as $file){ - echo $file; - $data = wp_prepare_attachment_for_js( $file ); - echo $data; - $out .= "
-
-
- {$data['title']}
- {$data['fileLength']}
- Borrar -
-
-
"; + $data = wp_prepare_attachment_for_js( $file ); + $out .= ""; } } echo '
' . $out . '
'; @@ -357,21 +354,17 @@ if (!class_exists('Soundmap')){ wp_localize_script( 'soundmap', 'WP_Soundmap', $params); } - function register_hooks(){ + function register_hooks(){ + add_action('init', array($this, 'init')); add_action('admin_menu', array($this, 'admin_menu')); add_action('save_post', array($this,'save_post')); add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts')); - //add_action('wp_print_footer_scripts', array($this, 'wp_print_footer_scripts'),1); - add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); add_action('init', array($this, 'add_feed')); - /*add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); - add_action('admin_init', array($this, 'register_admin_scripts'));*/ - - //AJAX ACTIONS + //AJAX ACTIONS add_action('wp_ajax_soundmap_JSON_load_markers',array($this, 'JSON_load_markers')); add_action('wp_ajax_nopriv_soundmap_JSON_load_markers',array($this, 'JSON_load_markers')); add_action('wp_ajax_nopriv_soundmap_load_infowindow', array($this, 'load_infowindow')); @@ -379,43 +372,35 @@ if (!class_exists('Soundmap')){ add_action('wp_ajax_soundmap-get-markers',array($this, 'soundmap_get_markers')); add_action('wp_ajax_nopriv_soundmap-get-markers',array($this,'soundmap_get_markers')); - //add_action('wp_ajax_nopriv_soundmap-get-markers',array($this, 'soundmap_get_markers')); add_action('wp_ajax_soundmap-get-content',array($this, 'soundmap_get_content')); + /* REST API Options */ + add_action('rest_api_init', function() { + register_rest_field('marker','georeference', + array( + 'get_callback' => 'marker_get_georeference', + 'schema' => null + ) + ); + }); + add_action('rest_api_init',function() { + register_rest_field('marker','media', + array( + 'get_callback' => 'marker_get_media', + 'schema' => null + ) + ); + }); - /* REST API Options */ - - - add_action('rest_api_init','soinumapa_create_marker_georeference'); - function soinumapa_create_marker_georeference() { - register_rest_field('marker','georeference', - array( - 'get_callback' => 'marker_get_georeference', - 'schema' => null - ) - ); - } - - add_action('rest_api_init','soinumapa_create_marker_media'); - function soinumapa_create_marker_media() { - register_rest_field('marker','media', - array( - 'get_callback' => 'marker_get_media', - 'schema' => null - ) - ); - } - - add_action('rest_api_init','soinumapa_create_marker_author'); - function soinumapa_create_marker_author() { - register_rest_field('marker','author', - array( - 'get_callback' => 'marker_get_author', - 'schema' => null - ) - ); - } - + add_action('rest_api_init', function() { + register_rest_field('marker','author', + array( + 'get_callback' => 'marker_get_author', + 'schema' => null + ) + ); + }); + function marker_get_georeference ($object, $field_name, $request){ //return $object['id']; $lat = get_post_meta($object['id'], 'soundmap_marker_lat', true); @@ -431,7 +416,7 @@ if (!class_exists('Soundmap')){ $files = get_post_meta($object['id'], 'soundmap_attachments_id', FALSE); $files_str = []; if ($files) : - foreach($files as $file){ + foreach($files as $file){ $data = wp_prepare_attachment_for_js( $file ); array_push($files_str,$data); } @@ -444,7 +429,7 @@ if (!class_exists('Soundmap')){ add_action('wp_ajax_nopriv_soundmap_verify_captcha', array($this, 'verify_captcha'));*/ } - + function add_feed(){ global $wp_rewrite;