Ejemplo n.º 1
0
 /**
  *
  *
  * @since 1.0
  * */
 function _save_separated_field($post_id)
 {
     if (!empty($_POST['st_custom_price_nonce'])) {
         if (!wp_verify_nonce($_POST['st_custom_price_nonce'], plugin_basename(__FILE__))) {
             return $post_id;
         }
         if (!current_user_can('edit_post', $post_id)) {
             return $post_id;
         }
         $price_new = STInput::request('st_price');
         $price_type = STInput::request('st_price_type');
         $start_date = STInput::request('st_start_date');
         $end_date = STInput::request('st_end_date');
         $status = STInput::request('st_status');
         $priority = STInput::request('st_priority');
         STAdmin::st_delete_price($post_id);
         if ($price_new and $start_date and $end_date) {
             foreach ($price_new as $k => $v) {
                 if (!empty($v)) {
                     STAdmin::st_add_price($post_id, $price_type[$k], $v, $start_date[$k], $end_date[$k], $status[$k], $priority[$k]);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 function st_insert_post_type_room()
 {
     if (!empty($_REQUEST['btn_insert_post_type_room'])) {
         if (wp_verify_nonce($_REQUEST['st_insert_room'], 'user_setting')) {
             if (st()->get_option('partner_post_by_admin', 'on') == 'on') {
                 $post_status = 'draft';
             } else {
                 $post_status = 'publish';
             }
             $current_user = wp_get_current_user();
             $title = $_REQUEST['title'];
             $st_content = $_REQUEST['st_content'];
             $my_post = array('post_title' => $title, 'post_content' => $st_content, 'post_status' => $post_status, 'post_author' => $current_user->ID, 'post_type' => 'hotel_room', 'post_excerpt' => $_REQUEST['desc']);
             $id_post = wp_insert_post($my_post);
             wp_set_post_terms($id_post, $_REQUEST['id_category'], 'room_type');
             if (!empty($id_post)) {
                 $featured_image = $_FILES['featured-image'];
                 // set featured_image
                 $id_featured_image = self::upload_image_return($featured_image, 'featured-image', $featured_image['type']);
                 set_post_thumbnail($id_post, $id_featured_image);
                 update_post_meta($id_post, 'room_parent', $_REQUEST['room_parent']);
                 update_post_meta($id_post, 'number_room', $_REQUEST['number_room']);
                 update_post_meta($id_post, 'price', $_REQUEST['price']);
                 update_post_meta($id_post, 'discount_rate', $_REQUEST['discount_rate']);
                 update_post_meta($id_post, 'adult_number', $_REQUEST['adult_number']);
                 update_post_meta($id_post, 'children_number', $_REQUEST['children_number']);
                 update_post_meta($id_post, 'bed_number', $_REQUEST['bed_number']);
                 update_post_meta($id_post, 'room_footage', $_REQUEST['room_footage']);
                 if (!empty($_REQUEST['taxonomy'])) {
                     $taxonomy = $_REQUEST['taxonomy'];
                     if (!empty($taxonomy)) {
                         foreach ($taxonomy as $k => $v) {
                             $tmp = explode(",", $v);
                             $term = get_term($tmp[0], $tmp[1]);
                             $ids = array();
                             $term_up = get_the_terms($id_post, $tmp[1]);
                             if (!empty($term_up)) {
                                 foreach ($term_up as $key => $value) {
                                     array_push($ids, $value->term_id);
                                 }
                             }
                             array_push($ids, $term->term_taxonomy_id);
                             wp_set_post_terms($id_post, $ids, $tmp[1]);
                         }
                     }
                 }
                 if (!empty($_REQUEST['st_price'])) {
                     $price_new = $_REQUEST['st_price'];
                     $price_type = $_REQUEST['st_price_type'];
                     $start_date = $_REQUEST['st_start_date'];
                     $end_date = $_REQUEST['st_end_date'];
                     $status = $_REQUEST['st_status'];
                     $priority = $_REQUEST['st_priority'];
                     STAdmin::st_delete_price($id_post);
                     if ($price_new and $start_date and $end_date) {
                         foreach ($price_new as $k => $v) {
                             if (!empty($v)) {
                                 STAdmin::st_add_price($id_post, $price_type[$k], $v, $start_date[$k], $end_date[$k], $status[$k], $priority[$k]);
                             }
                         }
                     }
                 }
                 self::_update_content_meta_box($_REQUEST['room_parent']);
                 self::$msg = array('status' => 'success', 'msg' => 'Create room successfully !');
             } else {
                 self::$msg = array('status' => 'danger', 'msg' => 'Error : Create room not successfully !');
             }
         }
     }
 }