public function save_template(array $args)
{
$validate_args = $this->ensure_args(['source', 'data'], $args);
if (is_wp_error($validate_args)) {
return $validate_args;
}
$source = $this->get_source($args['source']);
if (!$source) {
return new \WP_Error('template_error', 'Template source not found.');
}
$args['data'] = json_decode(stripslashes(html_entity_decode($args['data'])), true);
$template_id = $source->save_item($args);
if (is_wp_error($template_id)) {
return $template_id;
}
return $source->get_item($template_id);
}