function wpv_generate_view_loop_output_callback()
{
    if (!current_user_can('manage_options')) {
        $data = array('type' => 'capability', 'message' => __('You do not have permissions for that.', 'wpv-views'));
        wp_send_json_error($data);
    }
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'layout_wizard_nonce')) {
        $data = array('type' => 'nonce', 'message' => __('Your security credentials have expired. Please reload the page to get new ones.', 'wpv-views'));
        wp_send_json_error($data);
    }
    // @todo better validation
    $view_id = $_POST['view_id'];
    $style = $_POST['style'];
    $fields = json_decode(stripslashes($_POST['fields']), true);
    $args = json_decode(stripslashes($_POST['args']), true);
    // Translate field data from non-associative arrays into something that wpv_generate_view_loop_output() understands.
    $fields_normalized = array();
    foreach ($fields as $field) {
        $fields_normalized[] = array('prefix' => $field[0], 'shortcode' => $field[1], 'suffix' => $field[2], 'field_name' => $field[3], 'header_name' => $field[4], 'row_title' => $field[5]);
    }
    $loop_output = wpv_generate_view_loop_output($style, $fields_normalized, $args);
    // Forward the fail when loop output couldn't have been generated.
    if (null == $loop_output) {
        $data = array('type' => 'error', 'message' => __('Could not generate the Loop Output. PLease reload and try again.', 'wpv-views'));
        wp_send_json_error($data);
    }
    // Merge new settings to existing ones (overwrite keys from $layout_settings but keep the rest).
    $loop_output_settings = $loop_output['loop_output_settings'];
    $prev_settings = get_post_meta($view_id, '_wpv_layout_settings', true);
    if (!is_array($prev_settings)) {
        // Handle missing _wpv_layout_settings for given View.
        $prev_settings = array();
    }
    $loop_output_settings = array_merge($prev_settings, $loop_output_settings);
    // Return the results.
    $data = array('loop_output_settings' => $loop_output_settings, 'ct_content' => $loop_output['ct_content']);
    wp_send_json_success($data);
}
/**
 * Generate default View layout settings.
 *
 * Depending on a View purpose, generate default settings for a View.
 *
 * @param $purpose Purpose of the view: 'all', 'pagination', 'slide', 'parametric' or 'full'. For invalid values
 *     'full' is assumed.
 *
 * @return array Array with desired values.
 *
 * @since 1.7
 */
function wpv_view_default_layout_settings($purpose)
{
    // almost all of this settings are only needed to create the layout on the fly, so they are not needed here
    $defaults = array('additional_js' => '', 'layout_meta_html' => "[wpv-layout-start]\n" . "\t[wpv-items-found]\n" . "\t<!-- wpv-loop-start -->\n" . "\t\t<wpv-loop>\n" . "\t\t</wpv-loop>\n" . "\t<!-- wpv-loop-end -->\n" . "\t[/wpv-items-found]\n" . "\t[wpv-no-items-found]\n" . "\t\t[wpml-string context=\"wpv-views\"]<strong>No items found</strong>[/wpml-string]\n" . "\t[/wpv-no-items-found]\n" . "[wpv-layout-end]\n");
    // Purpose-specific modifications
    switch ($purpose) {
        case 'all':
        case 'pagination':
            // nothing to do here... yet
            break;
        case 'slider':
            // Generate full loop output settings
            $result = wpv_generate_view_loop_output('unformatted', array(), array());
            $defaults = $result['loop_output_settings'];
            break;
        case 'parametric':
        case 'full':
        default:
            // nothing to do here... yet
            break;
    }
    return $defaults;
}