public function save_layout_data_callback()
 {
     global $wpddlayout;
     if (user_can_edit_layouts() === false) {
         die(WPDD_Utils::ajax_caps_fail(__METHOD__));
     }
     if ($_POST && wp_verify_nonce($_POST['save_layout_nonce'], 'save_layout_nonce')) {
         if ($_POST['layout_model'] && $_POST['layout_id']) {
             $raw = stripslashes($_POST['layout_model']);
             $json = json_decode($raw, true);
             $children_to_delete = $json['children_to_delete'];
             $child_delete_mode = $json['child_delete_mode'];
             unset($json['children_to_delete']);
             unset($json['child_delete_mode']);
             $post = get_post($_POST['layout_id']);
             $msg = array();
             if ($post->post_title != $json['name'] || $post->post_name != $json['slug']) {
                 if ($this->slug_exists($json['slug'], $_POST['layout_id'])) {
                     echo wp_json_encode(array("Data" => array('error' => __(sprintf('The layout %s cannot be saved, the post name  %s is already taken. Please try with a different name.', $json['name'], $json['slug']), 'wpv-views'))));
                     die;
                 } else {
                     if ($post->post_name != $json['slug']) {
                         $slug = get_sample_permalink($_POST['layout_id'], $json['name'], $json['slug']);
                         $slug = $slug[1];
                     } else {
                         $slug = $json['slug'];
                     }
                     $postarr = apply_filters('ddl_layout_post_save', array('ID' => $_POST['layout_id'], 'post_title' => $json['name'], 'post_name' => $slug), $json, $raw);
                     $updated_id = wp_update_post($postarr);
                     //TODO: we probably can remove this call to get_post to save memory
                     $updated_post = get_post($updated_id);
                     $json['slug'] = $updated_post->post_name;
                     if ($this->normalize_layout_slug_if_changed($_POST['layout_id'], $json, $post->post_name)) {
                         $msg['slug'] = urldecode($updated_post->post_name);
                     }
                 }
             }
             if ($raw === WPDD_Layouts::get_layout_settings($_POST['layout_id'])) {
                 // no need to save as it hasn't changed.
                 $up = false;
             } else {
                 $json = apply_filters('ddl_layout_settings_save', $json, $post, $raw);
                 $up = WPDD_Layouts::save_layout_settings($_POST['layout_id'], $json);
             }
             // I commented out !empty( $_POST['layout_css'] ) to allow users to erase css entirely
             if (isset($_POST['layout_css'])) {
                 $css = $this->handle_layout_css(stripslashes($_POST['layout_css']));
                 if ($css !== false) {
                     $msg['css_saved'] = $css;
                 } else {
                     $msg['css_saved'] = 'no';
                 }
             }
             if ($children_to_delete && !empty($children_to_delete)) {
                 $delete_children = $this->purge_layout_children($children_to_delete, $child_delete_mode);
                 if ($delete_children) {
                     $msg['layout_children_deleted'] = $delete_children;
                 }
             }
             $wpddlayout->register_strings_for_translation($_POST['layout_id']);
             $msg['message']['layout_changed'] = $up;
             if (isset($_POST['silent']) && $_POST['silent'] == true) {
                 $msg['message']['silent'] = true;
             } else {
                 $msg['message']['silent'] = false;
             }
             $msg['message']['display_cache_message'] = $this->display_refresh_cache_message;
             $send = wp_json_encode(array('Data' => $msg));
             WPDD_Layouts::set_toolset_edit_last($_POST['layout_id'], $up);
             // Update Visual Editor (Text Cell) preferred editor for new cells
             if (isset($_POST['preferred_editor']) && preg_match('/^(codemirror|tinymce)$/', $_POST['preferred_editor'])) {
                 update_user_option(get_current_user_id(), 'ddl_preferred_editor', $_POST['preferred_editor']);
             }
         }
     } else {
         $send = wp_json_encode(array("Data" => array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts'))));
     }
     echo $send;
     die;
 }