function wpv_filter_make_intersection_filters() { if (!current_user_can('manage_options')) { die("Security check"); } if (!wp_verify_nonce($_POST["nonce"], 'wpv_view_make_intersection_filters')) { die("Security check"); } if (!isset($_POST["id"]) || !is_numeric($_POST["id"]) || intval($_POST['id']) < 1) { die("Security check"); } $view_array = get_post_meta($_POST["id"], '_wpv_settings', true); $view_array['taxonomy_relationship'] = 'AND'; $view_array['custom_fields_relationship'] = 'AND'; $view_array['usermeta_fields_relationship'] = 'AND'; update_post_meta($_POST["id"], '_wpv_settings', $view_array); do_action('wpv_action_wpv_save_item', $_POST["id"]); $return_result = array(); // Filters list $filters_list = ''; ob_start(); wpv_display_filters_list($view_array['query_type'][0], $view_array); $filters_list = ob_get_contents(); ob_end_clean(); $return_result['wpv_filter_update_filters_list'] = $filters_list; $return_result['success'] = $_POST['id']; echo json_encode($return_result); die; }
function wpv_remove_filter_missing_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"], 'wpv_view_filter_missing_delete' ) ) { $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 ); } if ( ! isset( $_POST["id"] ) || ! is_numeric( $_POST["id"] ) || intval( $_POST['id'] ) < 1 ) { $data = array( 'type' => 'id', 'message' => __( 'Wrong or missing ID.', 'wpv-views' ) ); wp_send_json_error( $data ); } $view_array = get_post_meta( $_POST["id"], '_wpv_settings', true ); if ( isset( $_POST['cf'] ) && is_array( $_POST['cf'] ) ) { foreach ( $_POST['cf'] as $field ) { $field = sanitize_text_field( $field ); $to_delete = array( 'custom-field-' . $field . '_compare', 'custom-field-' . $field . '_type', 'custom-field-' . $field . '_value', 'custom-field-' . $field . '_relationship' ); foreach ( $to_delete as $slug ) { if ( isset( $view_array[$slug] ) ) { unset( $view_array[$slug] ); } } } } if ( isset( $_POST['tax'] ) && is_array( $_POST['tax'] ) ) { foreach ( $_POST['tax'] as $tax_name ) { $tax_name = sanitize_text_field( $tax_name ); $to_delete = array( 'tax_'.$tax_name.'_relationship' , 'taxonomy-'.$tax_name.'-attribute-url', // 'taxonomy-'.$tax_name.'-attribute-url-format', ); foreach ( $to_delete as $slug ) { if ( isset( $view_array[$slug] ) ) { unset( $view_array[$slug] ); } } } } if ( isset( $_POST['rel'] ) && is_array( $_POST['rel'] ) && ! empty( $_POST['rel'] ) ) { $to_delete = array( 'post_relationship_mode', 'post_relationship_shortcode_attribute', 'post_relationship_url_parameter', 'post_relationship_id', 'post_relationship_url_tree', ); foreach ( $to_delete as $slug ) { if ( isset( $view_array[$slug] ) ) { unset( $view_array[$slug] ); } } } if ( isset( $_POST['search'] ) && is_array( $_POST['search'] ) && ! empty( $_POST['search'] ) ) { $to_delete = array( 'search_mode', 'post_search_value', 'post_search_content', ); foreach ( $to_delete as $slug ) { if ( isset( $view_array[$slug] ) ) { unset( $view_array[$slug] ); } } } update_post_meta( $_POST["id"], '_wpv_settings', $view_array ); do_action( 'wpv_action_wpv_save_item', $_POST["id"] ); // Filters list ob_start(); wpv_display_filters_list( $view_array['query_type'][0], $view_array ); $filters_list = ob_get_contents(); ob_end_clean(); $data = array( 'id' => $_POST["id"], 'updated_filters_list' => $filters_list, 'message' => __( 'Success', 'wpv-views' ) ); wp_send_json_success( $data ); }