Added basic support for linking DatasetBuilder datasets to lcp-data-collection CPT, and support for deleting datasets and datapoint in the DatasetBuilder.
This commit is contained in:
@ -99,26 +99,29 @@ add_action('init', 'lcp_register_data_collection_post_type');
|
||||
// Register meta field for datasets
|
||||
function lcp_register_meta_fields() {
|
||||
register_post_meta('lcp-data-collection', 'lcp_datasets', array(
|
||||
'show_in_rest' => true,
|
||||
'show_in_rest' => array(
|
||||
'schema' => array(
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'dataset_name' => array(
|
||||
'type' => 'string'
|
||||
),
|
||||
'dataset_source' => array(
|
||||
'type' => 'string'
|
||||
),
|
||||
'dataset_json' => array(
|
||||
'type' => 'array'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
'single' => true,
|
||||
'type' => 'array',
|
||||
'auth_callback' => function() {
|
||||
return current_user_can('edit_posts');
|
||||
},
|
||||
'sanitize_callback' => function($meta_value) {
|
||||
if (!is_array($meta_value)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$sanitized = array();
|
||||
foreach ($meta_value as $key => $dataset) {
|
||||
$sanitized[$key] = array(
|
||||
'dataset_name' => sanitize_text_field($dataset['dataset_name']),
|
||||
'dataset_source' => sanitize_text_field($dataset['dataset_source']),
|
||||
'dataset_json' => json_decode(wp_unslash($dataset['dataset_json']), true)
|
||||
);
|
||||
}
|
||||
return $sanitized;
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user