Example #1
0
function wpv_ct_bulk_delete_callback() {
	wpv_ajax_authenticate( 'wpv_view_listing_actions_nonce', array( 'parameter_source' => 'post', 'type_of_death' => 'data' ) );

	if( !isset( $_POST['ids'] ) ) {
		$ct_ids = array();
	} else if( is_string( $_POST['ids'] ) ) {
		$ct_ids = array( $_POST['ids'] );
	} else {
		$ct_ids = $_POST['ids'];
	}

    global $WPV_settings;

    foreach( $ct_ids as $ct_id ) {
		wpv_replace_views_template_options( $ct_id, 0, $WPV_settings );
		wp_delete_post( $ct_id );
	}
	
	$WPV_settings->save();

	wp_send_json_success();
}
function wpv_loop_wizard_add_field() {
	wpv_ajax_authenticate( 'wpv_loop_wizard_nonce', array( 'parameter_source' => 'post', 'type_of_death' => 'data' ) );
	
	if (
		! isset( $_POST["view_id"] )
		|| ! is_numeric( $_POST["view_id"] )
		|| intval( $_POST['view_id'] ) < 1 
	) {
		$data = array(
			'type' => 'id',
			'message' => __( 'Wrong or missing View ID.', 'wpv-views' )
		);
		wp_send_json_error( $data );
	}

	$menus = wpv_loop_wizard_get_available_field_menus( $_POST["view_id"] );
		
	$views_shortcodes_with_api_obj = apply_filters( 'wpv_filter_wpv_shortcodes_gui_data', array() );
	$views_shortcodes_with_api = array_keys( $views_shortcodes_with_api_obj );
	$user_fields_with_head = array(
		'user_email', 'display_name', 'user_login', 'user_url', 'user_registered'
	);
	
    ob_start();
	?>
	<div id="layout-wizard-style___wpv_layout_count_placeholder__" class="wpv-loop-wizard-item-container js-wpv-loop-wizard-item-container">
		<i class="icon-move js-layout-wizard-move-field"></i>
		<select name="layout-wizard-style" class="wpv-layout-wizard-item js-wpv-select2 js-wpv-layout-wizard-item js-layout-wizard-item">
		<?php
		foreach ( $menus as $group_title => $group_items ) {
			?>
			<optgroup label="<?php echo $group_title; ?>">
			<?php foreach ( $group_items as $current_item_title => $current_item ) {
				if ( 'css' == $current_item_title ) {
					// For some reason Types field bleed this css entry everywhere! Related to the editor_addon_menus_ filter
					continue;
				}
				$current_shortcode_name = $current_item[0];
				list($current_shortcode_handle) = explode( ' ', $current_item[1] );
				$current_shortcode_handle_corrected = $current_shortcode_handle; // needed to separate wpv-post-body from CT entries
				$current_shortcode_to_insert = $current_item[1];
				$current_shortcode_head = ''; // for table layouts
				$current_shortcode_is_types = false;
				$current_shortcode_types_name = '';
				
				if (
					'wpv-post-body' == $current_shortcode_handle 
					&& __( 'Basic', 'wpv-views' ) == $group_title
				) {
					$current_shortcode_to_insert = 'wpv-post-body view_template="None"';
				}
			
				// Head value for table layouts
				if ( $current_shortcode_handle === "wpv-post-taxonomy" ) {
					$current_shortcode_head = 'wpv-post-taxonomy';
					$current_shortcode_head = '';
				} else if ( $current_shortcode_handle === "wpv-post-field" ) {
					$current_shortcode_handle_corrected = $current_shortcode_handle . '_corrected';
					$current_shortcode_head = 'post-field-' . $current_shortcode_name;
					// if it is a new WooCommerce Views field
					if ( preg_match('/name="views_woo(.*?)"/', $current_shortcode_to_insert, $woo_match) ) {
						$current_shortcode_head = 'post-field-views_woo' . $woo_match[1];
					}
				} else if ( substr( $current_shortcode_to_insert, 0, 8 ) === "wpv-post" ) {
					if (
						'wpv-post-body' == $current_shortcode_handle
						&& __( 'Basic', 'wpv-views' ) != $group_title
					) {
						$current_shortcode_handle_corrected = $current_shortcode_handle . '_corrected';
					}
					$current_shortcode_head = substr( $current_shortcode_handle, 4 );
					if ( 
						$current_shortcode_handle === "wpv-post-status" 
						|| $current_shortcode_handle === "wpv-post-class" 
						|| $current_shortcode_handle === "wpv-post-body" 
						|| $current_shortcode_handle === "wpv-post-featured-image" 
					) {
						$current_shortcode_head = '';
					}
				} else if ( $current_shortcode_handle === "wpv-view" ) {
					$current_shortcode_head = 'post-view';
					$current_shortcode_head = '';
				} else if ( $current_shortcode_handle === "types" ) {
					if ( preg_match( '/field="(.*?)"/', $current_shortcode_to_insert, $field_in_loop ) !== 0 ) {
						$current_shortcode_head = 'types-field-' . $field_in_loop[1];
						$current_shortcode_is_types = true;
						$current_shortcode_types_name = $field_in_loop[1];
					} else if ( preg_match( '/usermeta="(.*?)"/', $current_shortcode_to_insert, $field_in_loop ) !== 0 ) {
						$current_shortcode_head = '';
						$current_shortcode_is_types = true;
						$current_shortcode_types_name = $field_in_loop[1];
					}
				} else if ( substr( $current_shortcode_to_insert, 0, 12 ) === "wpv-taxonomy" ) { // heading table solumns for wpv-taxonomy-* shortcodes
					if ( in_array( $current_shortcode_handle, array( 'wpv-taxonomy-link', 'wpv-taxonomy-title' ) ) ) {
						$current_shortcode_head = substr( $current_shortcode_handle, 4 );
					}
					if ( $current_shortcode_handle == 'wpv-taxonomy-post-count' ) {
						$current_shortcode_head = 'taxonomy-post_count';
					}
				} else if ( $current_shortcode_handle === "wpv-user" ) { // heaading table columns for wpv-user shortcodes
					preg_match( '/field="(.*?)"/', $current_shortcode_to_insert, $view_user_field );
					if ( 
						isset( $view_user_field[1] ) 
						&& in_array( $view_user_field[1], $user_fields_with_head ) 
					) {
						$current_shortcode_head = $view_user_field[1];
					} else {
						$current_shortcode_head = '';
					}
				}
				?>
				<option value="<?php echo base64_encode('['.$current_shortcode_to_insert.']'); ?>" 
					data-shortcodehandle="<?php echo esc_attr( $current_shortcode_handle_corrected ); ?>" 
					data-fieldname="<?php echo esc_attr( $current_shortcode_name ); ?>"
					data-headename="<?php echo esc_attr( $current_shortcode_head ); ?>" 
					data-rowtitle="<?php echo esc_attr( $current_shortcode_name ); ?>" 
					data-istype="<?php echo $current_shortcode_is_types ? '1' : '0'; ?>" 
					data-typename="<?php echo esc_attr( $current_shortcode_types_name ); ?>" 
					data-hasattributesgui="<?php echo ( in_array( $current_shortcode_handle_corrected, $views_shortcodes_with_api ) && ! in_array( $current_shortcode_handle_corrected, array( 'wpv-post-body', 'wpv-post-field' ) ) ) ? '1' : '0'; ?>" 
					data-onclick="<?php echo isset( $current_item[3] ) ? $current_item[3] : ''; ?>" 
					>
					<?php echo $current_shortcode_name; ?>
				</option>
			<?php } ?>
			</optgroup>
		<?php } ?>
		</select>
		<p class="wpv-helper-text js-layout-wizard-body-template-text hidden" style="margin-left: 33px;">
			<?php echo __('Using the Content Template', 'wpv-views'); ?>
			<select name="layout-wizard-body-template" class="layout-wizard-body-template js-wpv-layout-wizard-body-template">
				<option value="<?php echo base64_encode( '[wpv-post-body view_template="None"]' ); ?>" data-rowtitle="<?php echo esc_attr( __( 'None', 'wpv-views' ) ); ?>"><?php _e( 'None', 'wpv-views' ); ?></option>
				<?php
				if ( isset( $menus[__('Content Template', 'wpv-views')] ) ) {
					foreach ( $menus[__('Content Template', 'wpv-views')] as $ct_item ) { ?>
						<option value="<?php echo base64_encode('['.$ct_item[1].']'); ?>" data-rowtitle="<?php echo $ct_item[0]; ?>"><?php echo $ct_item[0]; ?></option>
					<?php 
					}
				}
				?>
			</select>
		</p>
		<button class="button-secondary js-custom-types-fields" style="display: none">
			<i class="icon-edit"></i> <?php _e('Edit', 'wpv-views'); ?>
		</button>
	
		<button class="button-secondary js-wpv-loop-wizard-shortcode-ui" style="display: none" data-nonce="<?php echo wp_create_nonce('wpv_editor_callback'); ?>">
			<i class="icon-edit"></i> <?php _e('Edit', 'wpv-views'); ?>
		</button>
	
		<button class="button-secondary js-layout-wizard-remove-field" style="position: absolute; top: 5px; right: 5px;"><i class="icon-remove"></i></button>
	</div>
	<?php
	$result_html = ob_get_clean();
	$data = array(
		'html' => $result_html
	);
	wp_send_json_success( $data );
}