function wpv_create_view_callback() { if (!current_user_can('manage_options')) { die("Untrusted user"); } if (!wp_verify_nonce($_POST["wpnonce"], 'wp_nonce_create_view')) { die("Security check"); } if (!isset($_POST["title"]) || $_POST["title"] == '') { $_POST["title"] = __('Unnamed View', 'wp-views'); } if (!isset($_POST["kind"]) || $_POST["kind"] == '') { $_POST["kind"] = 'normal'; } if (!isset($_POST["purpose"]) || $_POST["purpose"] == '') { $_POST["purpose"] = 'full'; } $args = array('title' => $_POST["title"], 'settings' => array('view-query-mode' => $_POST["kind"], 'view_purpose' => $_POST["purpose"])); $response = wpv_create_view($args); $result = array(); if (isset($response['success'])) { echo $response['success']; } else { if (isset($response['error'])) { $result['error'] = 'error'; $result['error_message'] = $response['error']; echo json_encode($result); } else { $result['error'] = 'error'; $result['error_message'] = __('The View could not be created', 'wpv-views'); echo json_encode($result); } } die; }
function wpv_create_view_callback() { wpv_ajax_authenticate( 'wp_nonce_create_view', array( 'parameter_source' => 'post', 'type_of_death' => 'data' ) ); if ( ! isset( $_POST["title"] ) || $_POST["title"] == '' ) { $_POST["title"] = __('Unnamed View', 'wp-views'); } if ( ! isset( $_POST["kind"] ) || $_POST["kind"] == '' ) { $_POST["kind"] = 'normal'; } if ( ! isset( $_POST["purpose"] ) || $_POST["purpose"] == '' ) { $_POST["purpose"] = 'full'; } $args = array( 'title' => $_POST["title"], 'settings' => array( 'view-query-mode' => $_POST["kind"], 'view_purpose' => $_POST["purpose"] ) ); $response = wpv_create_view( $args ); $result = array(); if ( isset( $response['success'] ) ) { $data = array( 'new_view_id' => $response['success'] ); wp_send_json_success( $data ); } else if ( isset( $response['error'] ) ) { $data = array( 'message' => $response['error'] ); wp_send_json_error( $data ); } else { $data = array( 'message' => __('The View could not be created', 'wpv-views') ); wp_send_json_error( $data ); } }
function ddl_create_new_view() { global $wpdb; if (WPDD_Utils::user_not_admin()) { die(__("You don't have permission to perform this action!", 'ddl-layouts')); } if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'ddl_layout_view_nonce')) { die('verification failed'); } $view_type = 'normal'; if (isset($_POST['is_archive'])) { $view_type = 'layouts-loop'; } $view_purpose = 'full'; if (isset($_POST['purpose'])) { $view_purpose = $_POST['purpose']; } $name = $original_name = $_POST['cell_name']; $i = 0; $name_in_use = true; while ($name_in_use) { $i++; $postid = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts}\r\n\t\t\tWHERE ( post_title = %s OR post_name = %s )\r\n\t\t\tAND post_type = 'view'\r\n\t\t\tLIMIT 1", $name, strtolower($name))); if ($postid) { $name = $original_name . ' ' . $i; } else { $name_in_use = false; } } $args = array('title' => $name, 'settings' => array('view_purpose' => $view_purpose, 'view-query-mode' => $view_type)); $view_id = wpv_create_view($args); if (isset($view_id['success'])) { $id = $view_id['success']; // set it to filter posts by default. $view_settings = get_post_meta($id, '_wpv_settings', true); $view_settings['post_type'] = array('post'); if (isset($_POST['purpose'])) { $view_settings['view_purpose'] = $_POST['purpose']; } else { $view_settings['view_purpose'] = 'full'; } if ($view_type == 'layouts-loop') { // show the content section for pagination. unset($view_settings['sections-show-hide']['content']); } update_post_meta($id, '_wpv_settings', $view_settings); $res = $wpdb->get_results("SELECT post_name FROM {$wpdb->posts} WHERE ID = '" . $id . "' AND post_type='view'"); $post_name = $res[0]->post_name; $output = wp_json_encode(array('id' => $id, 'post_name' => $post_name, 'post_title' => $name)); //print wp_json_encode(array( 'id'=>$id, 'post_name' => $post_name, 'post_title'=> $name)); } else { $output = wp_json_encode(array('error' => $view_id, 'message' => $view_id)); } die($output); }