function wpv_ajax_wpv_insert_view_dialog_callback() {
    
	global $wpdb, $WP_Views;
    
	if ( wp_verify_nonce( $_GET['_wpnonce'], 'wpv_editor_callback' ) ) {

        $view_id = intval( $_GET['view_id'] );
		$view_title = sanitize_text_field( $_GET['view_title'] );
		$orig_id = intval( $_GET['orig_id'] );
		
		$has_extra_attributes = get_view_allowed_attributes( $view_id );
		
		$has_parametric_search = $WP_Views->does_view_have_form_controls( $view_id );
		$has_submit = false;
		$view_settings = $WP_Views->get_view_settings( $view_id );
		if ( ! isset( $view_settings['query_type'][0] ) ) {
			$query_type = 'posts';
		} else {
			$query_type = $view_settings['query_type'][0];
		}
		if ( isset( $view_settings['filter_meta_html'] ) ) {
			$filter_meta_html = $view_settings['filter_meta_html'] ;
		} else {
			$filter_meta_html = '';
		}
		if ( strpos( $filter_meta_html, '[wpv-filter-submit' ) !== false ) {
			$has_submit = true;
		}
        ?>
		<div class="wpv-dialog wpv-shortcode-gui-content-wrapper">
			<input type="hidden" id="js-wpv-view-shortcode-gui-dialog-view-title" value="<?php echo esc_attr( $view_title ); ?>" />
			<div id="js-wpv-insert-view-override-container" class="wpv-insert-view-override-container js-wpv-insert-view-override-container" style="overflow:hidden">
				<h3><?php _e( 'Override some basic View settings', 'wpv-views' ); ?></h3>
				<p>
					<span style="color:red">*</span><?php _e( 'View default settings will be applied for empty inputs.', 'wpv-views' ); ?>
				</p>
				<ul>
					<li>
						<label for="wpv-insert-view-shortcode-limit" class="label-alignleft"><?php _e( 'Limit', 'wpv-views' ); ?></label>
						<input type="text" id="wpv-insert-view-shortcode-limit" class="js-wpv-insert-view-shortcode-limit js-wpv-has-placeholder" data-type="numberextended" placeholder="<?php echo esc_attr( __( 'A number', 'wpv-views' ) ); ?>" data-placeholder="<?php echo esc_attr( __( 'A number', 'wpv-views' ) ); ?>" />
						<span class="wpv-helper-text">
							<?php echo __( 'Get only some results. -1 means no limit', 'wpv-views' ); ?>
						</span>
					</li>
					<li>
						<label for="wpv-insert-view-shortcode-offset" class="label-alignleft"><?php _e( 'Offset', 'wpv-views' ); ?></label>
						<input type="text" id="wpv-insert-view-shortcode-offset" class="js-wpv-insert-view-shortcode-offset js-wpv-has-placeholder" data-type="number" placeholder="<?php echo esc_attr( __( 'A number', 'wpv-views' ) ); ?>" data-placeholder="<?php echo esc_attr( __( 'A number', 'wpv-views' ) ); ?>" />
						<span class="wpv-helper-text">
							<?php echo __( 'Skip some results. 0 means skip nothing', 'wpv-views' ); ?>
						</span>
					</li>
					<li>
						<?php 
						$placeholder = '';
						$helper = '';
						switch ( $query_type ) {
							case 'posts':
								$placeholder = __( 'ID, date, title or field-slug', 'wpv-views' );
								$helper = __( 'You can sort by a custom field simply using the value <em>field-xxx</em> where xxx is the custom field slug.', 'wpv-views' );
								break;
							case 'taxonomy':
								$placeholder = __( 'id, count, name or slug', 'wpv-views' );
								$helper = __( 'Use values like <em>id</em>, <em>count</em>, <em>name</em> or <em>slug</em>.', 'wpv-views' );
								break;
							case 'users':
								$placeholder = __( 'user_email, user_login...', 'wpv-views' );
								$helper = __( 'Use values like <em>user_email</em>, <em>user_login</em>, <em>display_name</em>, <em>user_url</em> or <em>user_registered</em>.', 'wpv-views' );
								break;
						}
						?>
						<label for="wpv-insert-view-shortcode-orderby" class="label-alignleft"><?php _e( 'Orderby', 'wpv-views' ); ?></label>
						<input type="text" id="wpv-insert-view-shortcode-orderby" class="js-wpv-insert-view-shortcode-orderby js-wpv-has-placeholder" data-type="holdon" placeholder="<?php echo esc_attr( $placeholder ); ?>" data-placeholder="<?php echo esc_attr( $placeholder ); ?>" />
						<span class="wpv-helper-text">
							<?php 
							echo __( 'Change how the results will be ordered.', 'wpv-views' ) . '<br />';
							echo $helper;
							?>
						</span>
					</li>
					<li>
						<label for="wpv-insert-view-shortcode-order" class="label-alignleft"><?php _e( 'Order', 'wpv-views' ); ?></label>
						<select id="wpv-insert-view-shortcode-order" class="js-wpv-insert-view-shortcode-order">
							<option value=""><?php _e( 'Default setting', 'wpv-views' ); ?></option>
							<option value="asc"><?php _e( 'Ascending', 'wpv-views' ); ?></option>
							<option value="desc"><?php _e( 'Descending', 'wpv-views' ); ?></option>
						</select>
						<span class="wpv-helper-text">
							<?php echo __( 'Change the order of the results.', 'wpv-views' ); ?>
						</span>
					</li>
				</ul>
			</div>
			<?php if ( ! empty( $has_extra_attributes ) ) { ?>
			<div id="js-wpv-insert-view-extra-attributes-container" class="wpv-insert-view-extra-attributes-container js-wpv-insert-view-extra-attributes-container" style="margin-top:10px;border-top:solid 1px #ccc;">
				<h3><?php _e( 'Extra View settings', 'wpv-views' ); ?></h3>
				<p>
					<?php _e( 'This View can be filtered by the values listed here.', 'wpv-views' ); ?>
				</p>
				<?php 
				foreach ( $has_extra_attributes as $attr_settings ) {
					?>
					<div>
						<label for="wpv-insert-view-shortcode-extra-attribute-<?php echo $attr_settings['filter_type']; ?>" class="label-alignleft"><?php echo $attr_settings['filter_label']; ?></label>
						<input type="text" 
							id="wpv-insert-view-shortcode-extra-attribute-<?php echo $attr_settings['filter_type']; ?>" 
							class="js-wpv-insert-view-shortcode-extra-attribute js-wpv-has-placeholder" 
							placeholder="<?php echo $attr_settings['placeholder']; ?>" 
							data-placeholder="<?php echo $attr_settings['placeholder']; ?>" 
							data-attribute="<?php echo $attr_settings['attribute']; ?>"
							data-type="<?php echo $attr_settings['expected']; ?>" />
						<span class="wpv-helper-text"><?php echo $attr_settings['description']; ?></span>
					</div>
					<?php
				}
				//print_r( $has_extra_attributes ); 
				?>
			</div>
			<?php } ?>
			<?php if ( $has_parametric_search ) { ?>
			<div id="js-wpv-insert-view-parametric-search-container" class="wpv-insert-view-parametric-search-container js-wpv-insert-view-parametric-search-container" style="margin-top:10px;border-top:solid 1px #ccc;">
				<h3><?php _e( 'This View contains a parametric search', 'wpv-views' ); ?></h3>
				<div class="js-wpv-insert-view-form-display-container">
					<p><strong><?php _e( 'What do you want to include here?', 'wpv-views' ); ?></strong></p>
					<ul>
						<li>
							<input id="wpv-filter-form-display-both" value="both" type="radio" name="wpv-insert-view-form-display" class="js-wpv-insert-view-form-display" checked="checked" />
							<label for="wpv-filter-form-display-both"><?php _e('Both the search box and results', 'wpv-views'); ?></label>
							<span class="wpv-helper-text"><?php _e( 'This will display the full View.', 'wpv-views' ); ?></span>
						</li>
						<li>
							<input id="wpv-filter-form-display-form" value="form" type="radio" name="wpv-insert-view-form-display" class="js-wpv-insert-view-form-display" />
							<label for="wpv-filter-form-display-form"><?php _e('Only the search box', 'wpv-views'); ?></label>
							<span class="wpv-helper-text"><?php _e( 'This will display just the form, you can select where to display the results in the next step.', 'wpv-views' ); ?></span>
						</li>
						<li>
							<input id="wpv-filter-form-display-results" value="results" type="radio" name="wpv-insert-view-form-display" class="js-wpv-insert-view-form-display" />
							<label for="wpv-filter-form-display-results"><?php _e('Only the search results', 'wpv-views'); ?></label>
							<span class="wpv-helper-text"><?php _e( 'This will display just the results, you need to add the form elsewhere targeting this page.', 'wpv-views' ); ?></span>
						</li>
					</ul>
				</div>
				<div class="js-wpv-insert-view-form-target-container" style="display:none">
					<p><strong><?php _e( 'Where do you want to display the results of this search?', 'wpv-views' ); ?></strong></p>
					<?php if ( ! $has_submit ) { ?>
					<span class="toolset-alert toolset-error">
						<?php _e( 'The form in this View does not have a submit button, so you can only display the results on this same page.', 'wpv-views' ); ?>
					</span>
					<?php } ?>
					<ul>
						<li>
							<input id="wpv-filter-form-target-self" value="self" type="radio" name="wpv-insert-view-form-target" class="js-wpv-insert-view-form-target" checked="checked" />
							<label for="wpv-filter-form-target-self"><?php _e('In other place on this same page', 'wpv-views'); ?></label>
						</li>
						<li>
							<input id="wpv-filter-form-target-other" <?php disabled( $has_submit, false ); ?> value="other" type="radio" name="wpv-insert-view-form-target" class="js-wpv-insert-view-form-target" />
							<label for="wpv-filter-form-target-other" <?php if ( ! $has_submit ) { ?>style="color:#999"<?php } ?>><?php _e('On another page', 'wpv-views'); ?></label>
						</li>
					</ul>
					<div class="js-wpv-insert-view-form-target-set-container" style="display:none;margin-left:20px;">
						<p><?php _e( 'You can display the results on an existing page or create a new one:', 'wpv-views' ); ?></p>
						<ul>
							<li>
								<input id="wpv-insert-view-form-target-set-existing" value="existing" type="radio" name="wpv-insert-view-form-target-set" class="js-wpv-insert-view-form-target-set" checked="checked" />
								<label for="wpv-insert-view-form-target-set-existing"><?php _e( 'Use an existing page', 'wpv-views' ); ?></label>
								<div class="js-wpv-insert-view-form-target-set-existing-extra" style="margin:5px 0 0 20px;">
									<input class="js-wpv-insert-view-form-target-set-existing-title" type="text" name="wpv-insert-view-form-target-set-existing-title" placeholder="<?php echo esc_attr( __( 'Type the title of the page', 'wpv-views' ) ); ?>" value="" />
									<input class="js-wpv-insert-view-form-target-set-existing-id" type="hidden" name="wpv-insert-view-form-target-set-existing-id" value="" />
									<div class="js-wpv-insert-view-form-target-set-actions" style="display:none;background:#ddd;margin-top: 5px;padding: 5px 10px 10px;">
										<?php _e( 'Be sure to complete the setup:', 'wpv-views' ); ?><br />
										<a href="#" target="_blank" class="button-primary js-wpv-insert-view-form-target-set-existing-link" data-origid="<?php echo $orig_id; ?>" data-viewid="<?php echo $view_id; ?>" data-editurl="<?php echo admin_url( 'post.php' ); ?>?post="><?php _e( 'Add the search results to this page', 'wpv-views' ); ?></a>
										<a href="#" class="button-secondary js-wpv-insert-view-form-target-set-discard"><?php _e( 'Not now', 'wpv-views' ); ?></a>
									</div>
								</div>
							</li>
							<li>
								<input id="wpv-insert-view-form-target-set-create" value="create" type="radio" name="wpv-insert-view-form-target-set" class="js-wpv-insert-view-form-target-set" />
								<label for="wpv-insert-view-form-target-set-create"><?php _e( 'Use one new page', 'wpv-views' ); ?></label>
								<div class="js-wpv-insert-view-form-target-set-create-extra" style="display:none;margin:5px 0 0 20px;">
									<input class="js-wpv-insert-view-form-target-set-create-title" type="text" name="wpv-insert-view-form-target-set-extra-title" placeholder="<?php echo esc_attr( __( 'Type a title of the new page', 'wpv-views' ) ); ?>" value="" />
									<button class="button-secondary js-wpv-insert-view-form-target-set-create-action" disabled="disabled" data-viewid="<?php echo $view_id; ?>" data-nonce="<?php echo wp_create_nonce('wpv_create_form_target_page_nonce'); ?>"><?php _e( 'Create page', 'wpv-views' ); ?></button>
								</div>
							</li>
						</ul>
					</div>
				</div>
			</div>
			<?php } ?>
			<div id="js-wpv-insert-view-cache-attributes-container" class="wpv-insert-view-cache-attributes-container js-wpv-insert-view-cache-attributes-container" style="overflow:hidden">
				<h3><?php _e( 'Views caching', 'wpv-views' ); ?></h3>
				<p>
					<?php 
						echo __( 'Views results can be cached if they meet some requirements, so they are displayed faster in the frontend.', 'wpv-views' )
							//. WPV_MESSAGE_SPACE_CHAR
							//. __( 'We try our best to only cache those Views that have a fixed output, and we clear the cache as soon as there is any change.', 'wpv-views' )
							. WPV_MESSAGE_SPACE_CHAR
							. __( 'However, you might want to disable this feature for the current View', 'wpv-views' )
						; 
					?>
				</p>
				<ul>
					<li>
						<input type="radio" name="wpv-insert-view-shortcode-cache" value="" class="js-wpv-insert-view-shortcode-cache" id="wpv-insert-view-shortcode-cache-on" checked="checked" />
						<label for="wpv-insert-view-shortcode-cache-on"><?php _e( 'Use the cached version if it is available', 'wpv-views' ); ?></label>
						<span class="wpv-helper-text">
							<?php 
							echo __( 'This will return the cached output in case this View supports it.', 'wpv-views' );
							?>
						</span>
					</li>
					<li>
						<input type="radio" name="wpv-insert-view-shortcode-cache" value="off" class="js-wpv-insert-view-shortcode-cache" id="wpv-insert-view-shortcode-cache-off" />
						<label for="wpv-insert-view-shortcode-cache-off"><?php _e( 'Always generate the View output', 'wpv-views' ); ?></label>
						<span class="wpv-helper-text"><?php _e( 'This will perform the whole View query and generate the output on-the-fly.', 'wpv-views' ); ?></span>
					</li>
				</ul>
			</div>
			<div class="wpv-filter-toolset-messages js-wpv-filter-toolset-messages"></div>
		</div>
        <?php
	}   
	die();
}
function wpv_override_view_limit_offset($view_id)
{
    global $WP_Views;
    // Override limit and offset values with the shortcode-provided ones
    $return = array();
    $attributes_allowed = get_view_allowed_attributes($view_id);
    $attributes_used_by_filters = array();
    $view_attrs = $WP_Views->get_view_shortcodes_attributes();
    // Check the attributes allowed to see if 'limit' and 'offset' are already in use
    // If a query filter already uses any of those two words, this override will not be applied
    if (is_array($attributes_allowed)) {
        $attributes_used_by_filters = wp_list_pluck($attributes_allowed, 'attribute');
    }
    // If that is not the case, see if we need to override
    if (isset($view_attrs['limit']) && !in_array('limit', $attributes_used_by_filters)) {
        $return['limit'] = intval($view_attrs['limit']);
    }
    if (isset($view_attrs['offset']) && !in_array('offset', $attributes_used_by_filters)) {
        $return['offset'] = intval($view_attrs['offset']);
    }
    // Return
    return $return;
}