Fix: Rewrite add_meta_box && rest_init

This commit is contained in:
Luca 2022-12-13 01:42:30 +01:00
parent f11d466ff0
commit 79122e6086

View File

@ -81,13 +81,12 @@ if (!class_exists('Soundmap')){
function metaboxes_register_callback(){ 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-map', __("Place the Marker", 'soundmap'), array($this, 'map_meta_box'), 'marker', 'normal', 'high');
add_meta_box('soundmap-media-info', __("Info", 'soundmap'), array($this,'info_meta_box'), 'marker', 'side', 'high'); add_meta_box('soundmap-email', __("Uploader Mail", 'soundmap'), array($this,'soundmap_email_meta_box'), 'marker', 'side', 'low');
add_meta_box('soundmap-media-attachments', __("Media files attached.", 'soundmap'), array($this, 'attachments_meta_box'), 'marker', 'side', 'high'); add_meta_box('soundmap-sound-info', __("Info", 'soundmap'), array($this,'info_meta_box'), 'marker', 'side', 'high');
// Ya no es necesario add_meta_box('soundmap-sound-attachments', __("Media files attached.", 'soundmap'), array($this, 'attachments_meta_box'), 'marker', 'side', 'high');
//add_meta_box('soundmap-email', __("Uploader Mail", 'soundmap'), array($this, 'email_meta_box'), 'marker', 'side', 'low');
} //metaboxes_register_callback } //metaboxes_register_callback
function email_meta_box(){ function soundmap_email_meta_box(){
global $post; global $post;
$mail = get_post_meta($post->ID, 'EMAIL', TRUE); $mail = get_post_meta($post->ID, 'EMAIL', TRUE);
echo "<p>" . $mail . "</p>"; echo "<p>" . $mail . "</p>";
@ -112,11 +111,18 @@ if (!class_exists('Soundmap')){
$out = ''; $out = '';
if ($files){ if ($files){
foreach($files as $file){ foreach($files as $file){
echo $file;
$data = wp_prepare_attachment_for_js( $file ); $data = wp_prepare_attachment_for_js( $file );
$out .= "<div class='soundmap-attach-item'><div class='att-icon'><img src='{$data['icon']}'/></div> echo $data;
<div class='att-info'><a href='{$data['url']}'><strong>{$data['title']}</strong></a><br/> $out .= "<div class='soundmap-attach-item'>
<div class='att-icon'><img src='{$data['icon']}'/></div>
<div class='att-info'>
<a href='{$data['url']}'><strong>{$data['title']}</strong></a><br/>
<span class='att-length'>{$data['fileLength']}</span><br/> <span class='att-length'>{$data['fileLength']}</span><br/>
<a href='#' class='delete-att-item'>Borrar</a></div><div class='clear'></div><input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>"; <a href='#' class='delete-att-item'>Borrar</a>
</div>
<div class='clear'></div>
<input type='hidden' name='soundmap-att-ids[]' value='{$file}' /></div>";
} }
} }
echo '<div id="soundmap-attachments-list">' . $out . '</div>'; echo '<div id="soundmap-attachments-list">' . $out . '</div>';
@ -377,33 +383,38 @@ if (!class_exists('Soundmap')){
add_action('wp_ajax_soundmap-get-content',array($this, 'soundmap_get_content')); add_action('wp_ajax_soundmap-get-content',array($this, 'soundmap_get_content'));
/* REST API Options */ /* REST API Options */
add_action('rest_api_init',
register_rest_field('marker','georeference',
array(
'get_callback' => 'marker_get_georeference',
'schema' => null
)
)
);
add_action('rest_api_init',
register_rest_field('marker','media',
array(
'get_callback' => 'marker_get_media',
'schema' => null
)
)
);
add_action('rest_api_init', add_action('rest_api_init','soinumapa_create_marker_georeference');
register_rest_field('marker','author', function soinumapa_create_marker_georeference() {
array( register_rest_field('marker','georeference',
'get_callback' => 'marker_get_author', array(
'schema' => null '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
)
);
}
function marker_get_georeference ($object, $field_name, $request){ function marker_get_georeference ($object, $field_name, $request){
//return $object['id']; //return $object['id'];