@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * Display the importer administration screen |
| 107 | 107 | */ |
| 108 | 108 | public function display_page() { |
| 109 | - ?> |
|
| 109 | + ?> |
|
| 110 | 110 | <div class="wrap"> |
| 111 | 111 | <?php screen_icon(); ?> |
| 112 | 112 | |
@@ -232,13 +232,13 @@ discard block |
||
| 232 | 232 | $result = $this->update_options(); |
| 233 | 233 | |
| 234 | 234 | if(true === $result){ |
| 235 | - echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
| 236 | - }else{ |
|
| 237 | - echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
| 238 | - } |
|
| 235 | + echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
|
| 236 | + }else{ |
|
| 237 | + echo '<span style="color:red;">'.wp_kses_post($result).'</span>'; |
|
| 238 | + } |
|
| 239 | 239 | }else{ |
| 240 | 240 | echo '<span style="color:green;">'.esc_attr('Connected','wetu-importer').'</span>'; |
| 241 | - } |
|
| 241 | + } |
|
| 242 | 242 | echo '</h3></div>'; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -250,8 +250,8 @@ discard block |
||
| 250 | 250 | $tours = json_decode($data, true); |
| 251 | 251 | |
| 252 | 252 | if(isset($tours['error'])){ |
| 253 | - return $tours['error']; |
|
| 254 | - }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
| 253 | + return $tours['error']; |
|
| 254 | + }elseif (isset($tours['itineraries']) && !empty($tours['itineraries'])) { |
|
| 255 | 255 | set_transient('lsx_ti_tours',$tours['itineraries'],60*60*2); |
| 256 | 256 | return true; |
| 257 | 257 | } |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | $keyphrases = $_POST['keyword']; |
| 301 | 301 | }else{ |
| 302 | 302 | $keyphrases = array(0); |
| 303 | - } |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | 305 | if(!is_array($keyphrases)){ |
| 306 | 306 | $keyphrases = array($keyphrases); |
@@ -329,15 +329,15 @@ discard block |
||
| 329 | 329 | |
| 330 | 330 | foreach($tours as $row_key => $row){ |
| 331 | 331 | |
| 332 | - if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
| 333 | - continue; |
|
| 334 | - } |
|
| 332 | + if(isset($row['is_disabled']) && true === $row['is_disabled']){ |
|
| 333 | + continue; |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - /*if('Sample' === $row['type']){ |
|
| 336 | + /*if('Sample' === $row['type']){ |
|
| 337 | 337 | continue; |
| 338 | 338 | }*/ |
| 339 | 339 | |
| 340 | - //If this is a current tour, add its ID to the row. |
|
| 340 | + //If this is a current tour, add its ID to the row. |
|
| 341 | 341 | $row['post_id'] = 0; |
| 342 | 342 | if(false !== $current_tours && array_key_exists($row['identifier'], $current_tours)){ |
| 343 | 343 | $row['post_id'] = $current_tours[$row['identifier']]->post_id; |
@@ -346,31 +346,31 @@ discard block |
||
| 346 | 346 | //If we are searching for |
| 347 | 347 | if(false !== $post_status){ |
| 348 | 348 | |
| 349 | - if('import' === $post_status){ |
|
| 349 | + if('import' === $post_status){ |
|
| 350 | 350 | |
| 351 | 351 | if(0 !== $row['post_id']){ |
| 352 | - continue; |
|
| 352 | + continue; |
|
| 353 | 353 | }else{ |
| 354 | 354 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
| 355 | - } |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | 357 | |
| 358 | - }else{ |
|
| 358 | + }else{ |
|
| 359 | 359 | |
| 360 | 360 | if(0 === $row['post_id']){ |
| 361 | 361 | continue; |
| 362 | 362 | }else{ |
| 363 | 363 | $current_status = get_post_status($row['post_id']); |
| 364 | 364 | if($current_status !== $post_status){ |
| 365 | - continue; |
|
| 366 | - } |
|
| 365 | + continue; |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | 368 | } |
| 369 | 369 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
| 370 | 370 | |
| 371 | - } |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - }else{ |
|
| 373 | + }else{ |
|
| 374 | 374 | //Search through each keyword. |
| 375 | 375 | foreach($keyphrases as $keyphrase){ |
| 376 | 376 | |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | $searched_items[sanitize_title($row['name']).'-'.$row['identifier']] = $this->format_row($row); |
| 385 | 385 | } |
| 386 | 386 | } |
| 387 | - } |
|
| 387 | + } |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | |
@@ -449,17 +449,17 @@ discard block |
||
| 449 | 449 | $content = false; |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
| 452 | + $jdata=file_get_contents("http://wetu.com/API/Itinerary/V7/Get?id=".$wetu_id); |
|
| 453 | 453 | |
| 454 | - if($jdata) |
|
| 455 | - { |
|
| 454 | + if($jdata) |
|
| 455 | + { |
|
| 456 | 456 | $jdata=json_decode($jdata,true); |
| 457 | - if(!empty($jdata)) |
|
| 458 | - { |
|
| 459 | - $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
| 460 | - $this->format_completed_row($return); |
|
| 461 | - } |
|
| 462 | - } |
|
| 457 | + if(!empty($jdata)) |
|
| 458 | + { |
|
| 459 | + $return = $this->import_row($jdata,$wetu_id,$post_id,$content); |
|
| 460 | + $this->format_completed_row($return); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | 463 | die(); |
| 464 | 464 | } |
| 465 | 465 | |
@@ -467,61 +467,61 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | /** |
| 469 | 469 | * Connect to wetu |
| 470 | - * |
|
| 471 | - * @param $data array |
|
| 472 | - * @param $wetu_id string |
|
| 470 | + * |
|
| 471 | + * @param $data array |
|
| 472 | + * @param $wetu_id string |
|
| 473 | 473 | */ |
| 474 | 474 | public function import_row($data,$wetu_id,$id=0,$importable_content=false,$old1=false,$old2=false) { |
| 475 | - $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 476 | - $post = array( |
|
| 477 | - 'post_type' => 'tour', |
|
| 478 | - ); |
|
| 475 | + $post_name = $data_post_content = $data_post_excerpt = ''; |
|
| 476 | + $post = array( |
|
| 477 | + 'post_type' => 'tour', |
|
| 478 | + ); |
|
| 479 | 479 | |
| 480 | - //Set the post_content |
|
| 480 | + //Set the post_content |
|
| 481 | 481 | $content_used_general_description = false; |
| 482 | - if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 483 | - $data_post_content = ''; |
|
| 484 | - |
|
| 485 | - if(isset($data['description'])){ |
|
| 486 | - $data_post_content = $data['description']; |
|
| 487 | - }elseif(isset($data['summary'])){ |
|
| 488 | - $data_post_content = $data['summary']; |
|
| 489 | - $content_used_general_description = true; |
|
| 490 | - } |
|
| 491 | - $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - //set the post_excerpt |
|
| 495 | - if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
| 496 | - if(isset($data['summary']) && false === $content_used_general_description){ |
|
| 497 | - $post['post_excerpt'] = $data['summary']; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - //Create or update the post |
|
| 502 | - if(false !== $id && '0' !== $id){ |
|
| 503 | - $post['ID'] = $id; |
|
| 504 | - $post['post_status'] = 'pending'; |
|
| 505 | - $id = wp_update_post($post); |
|
| 506 | - $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 507 | - update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
| 508 | - }else{ |
|
| 509 | - |
|
| 510 | - //Set the name |
|
| 511 | - if(isset($data['name'])){ |
|
| 512 | - $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
| 513 | - } |
|
| 514 | - $post['post_name'] = $post_name; |
|
| 515 | - $post['post_title'] = $data['name']; |
|
| 516 | - $post['post_status'] = 'pending'; |
|
| 517 | - $id = wp_insert_post($post); |
|
| 518 | - |
|
| 519 | - //Save the WETU ID and the Last date it was modified. |
|
| 520 | - if(false !== $id){ |
|
| 521 | - add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 522 | - add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
| 523 | - } |
|
| 524 | - } |
|
| 482 | + if(false !== $importable_content && in_array('description',$importable_content)){ |
|
| 483 | + $data_post_content = ''; |
|
| 484 | + |
|
| 485 | + if(isset($data['description'])){ |
|
| 486 | + $data_post_content = $data['description']; |
|
| 487 | + }elseif(isset($data['summary'])){ |
|
| 488 | + $data_post_content = $data['summary']; |
|
| 489 | + $content_used_general_description = true; |
|
| 490 | + } |
|
| 491 | + $post['post_content'] = wp_strip_all_tags($data_post_content); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + //set the post_excerpt |
|
| 495 | + if(false !== $importable_content && in_array('excerpt',$importable_content)){ |
|
| 496 | + if(isset($data['summary']) && false === $content_used_general_description){ |
|
| 497 | + $post['post_excerpt'] = $data['summary']; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + //Create or update the post |
|
| 502 | + if(false !== $id && '0' !== $id){ |
|
| 503 | + $post['ID'] = $id; |
|
| 504 | + $post['post_status'] = 'pending'; |
|
| 505 | + $id = wp_update_post($post); |
|
| 506 | + $prev_date = get_post_meta($id,'lsx_wetu_modified_date',true); |
|
| 507 | + update_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified']),$prev_date); |
|
| 508 | + }else{ |
|
| 509 | + |
|
| 510 | + //Set the name |
|
| 511 | + if(isset($data['name'])){ |
|
| 512 | + $post_name = wp_unique_post_slug(sanitize_title($data['name']),$id, 'draft', 'tour', 0); |
|
| 513 | + } |
|
| 514 | + $post['post_name'] = $post_name; |
|
| 515 | + $post['post_title'] = $data['name']; |
|
| 516 | + $post['post_status'] = 'pending'; |
|
| 517 | + $id = wp_insert_post($post); |
|
| 518 | + |
|
| 519 | + //Save the WETU ID and the Last date it was modified. |
|
| 520 | + if(false !== $id){ |
|
| 521 | + add_post_meta($id,'lsx_wetu_id',$wetu_id); |
|
| 522 | + add_post_meta($id,'lsx_wetu_modified_date',strtotime($data['last_modified'])); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | 525 | |
| 526 | 526 | |
| 527 | 527 | //Set the price |
@@ -534,9 +534,9 @@ discard block |
||
| 534 | 534 | $this->set_duration($data,$id); |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
| 538 | - $this->process_itineraries($data,$id,$importable_content); |
|
| 539 | - } |
|
| 537 | + if(in_array('itineraries',$importable_content) && isset($data['legs']) && !empty($data['legs'])){ |
|
| 538 | + $this->process_itineraries($data,$id,$importable_content); |
|
| 539 | + } |
|
| 540 | 540 | |
| 541 | 541 | if(in_array('map',$importable_content) && isset($data['routes']) && !empty($data['routes'])){ |
| 542 | 542 | $this->process_map_points($data,$id); |
@@ -547,24 +547,24 @@ discard block |
||
| 547 | 547 | if(false !== $importable_content && (in_array('itinerary_gallery',$importable_content) || in_array('gallery',$importable_content) || in_array('banner_image',$importable_content) || in_array('featured_image',$importable_content))){ |
| 548 | 548 | $this->find_attachments($id); |
| 549 | 549 | } |
| 550 | - //Set the featured image |
|
| 551 | - //TODO Test These |
|
| 552 | - if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
| 553 | - $this->set_featured_image($data,$id); |
|
| 554 | - } |
|
| 550 | + //Set the featured image |
|
| 551 | + //TODO Test These |
|
| 552 | + if(false !== $importable_content && in_array('featured_image',$importable_content)){ |
|
| 553 | + $this->set_featured_image($data,$id); |
|
| 554 | + } |
|
| 555 | 555 | |
| 556 | 556 | //TODO Test These |
| 557 | - if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
| 558 | - $this->set_banner_image($data,$id); |
|
| 559 | - } |
|
| 557 | + if(false !== $importable_content && in_array('banner_image',$importable_content)){ |
|
| 558 | + $this->set_banner_image($data,$id); |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | 561 | //TODO Test These |
| 562 | - //Import the main gallery |
|
| 563 | - if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
| 564 | - $this->create_main_gallery($data,$id); |
|
| 565 | - } |
|
| 562 | + //Import the main gallery |
|
| 563 | + if(false !== $importable_content && in_array('gallery',$importable_content)){ |
|
| 564 | + $this->create_main_gallery($data,$id); |
|
| 565 | + } |
|
| 566 | 566 | |
| 567 | - return $id; |
|
| 567 | + return $id; |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | /** |
@@ -676,31 +676,31 @@ discard block |
||
| 676 | 676 | */ |
| 677 | 677 | public function process_map_points($data,$id) { |
| 678 | 678 | |
| 679 | - if(!empty($data['routes'])){ |
|
| 679 | + if(!empty($data['routes'])){ |
|
| 680 | 680 | |
| 681 | - delete_post_meta($id,'wetu_map_points'); |
|
| 681 | + delete_post_meta($id,'wetu_map_points'); |
|
| 682 | 682 | |
| 683 | - $points = array(); |
|
| 683 | + $points = array(); |
|
| 684 | 684 | |
| 685 | - foreach($data['routes'] as $route){ |
|
| 685 | + foreach($data['routes'] as $route){ |
|
| 686 | 686 | |
| 687 | 687 | |
| 688 | - if(isset($route['points']) && '' !== $route['points']){ |
|
| 688 | + if(isset($route['points']) && '' !== $route['points']){ |
|
| 689 | 689 | |
| 690 | - $temp_points = explode(';',$route['points']); |
|
| 691 | - $point_counter = count($temp_points); |
|
| 690 | + $temp_points = explode(';',$route['points']); |
|
| 691 | + $point_counter = count($temp_points); |
|
| 692 | 692 | |
| 693 | 693 | for ($x = 0; $x <= $point_counter; $x++) { |
| 694 | - $y = $x+1; |
|
| 694 | + $y = $x+1; |
|
| 695 | 695 | $points[] = $temp_points[$x].','.$temp_points[$y]; |
| 696 | 696 | $x++; |
| 697 | 697 | } |
| 698 | 698 | } |
| 699 | - } |
|
| 700 | - if(!empty($points)){ |
|
| 699 | + } |
|
| 700 | + if(!empty($points)){ |
|
| 701 | 701 | $this->save_custom_field(implode(' ',$points),'wetu_map_points',$id,false,true); |
| 702 | - } |
|
| 703 | - } |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | 704 | |
| 705 | 705 | } |
| 706 | 706 | |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * Set the Itinerary Day |
| 709 | 709 | */ |
| 710 | 710 | public function set_itinerary_day($day,$id) { |
| 711 | - $this->save_custom_field($day,'itinerary',$id,false,false); |
|
| 711 | + $this->save_custom_field($day,'itinerary',$id,false,false); |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** |
@@ -716,8 +716,8 @@ discard block |
||
| 716 | 716 | */ |
| 717 | 717 | public function set_price($data,$id) { |
| 718 | 718 | if(isset($data['price']) && ''!== $data['price']){ |
| 719 | - $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
| 720 | - $this->save_custom_field($price,'price',$id); |
|
| 719 | + $price = preg_replace("/[^0-9,.]/", "", $data['price']); |
|
| 720 | + $this->save_custom_field($price,'price',$id); |
|
| 721 | 721 | } |
| 722 | 722 | } |
| 723 | 723 | |
@@ -738,35 +738,35 @@ discard block |
||
| 738 | 738 | */ |
| 739 | 739 | public function set_accommodation($day,$id) { |
| 740 | 740 | |
| 741 | - $ac_id = false; |
|
| 741 | + $ac_id = false; |
|
| 742 | 742 | $this->current_accommodation = $this->find_current_accommodation(); |
| 743 | 743 | |
| 744 | 744 | if(isset($day['content_entity_id']) && !empty($day['content_entity_id'])){ |
| 745 | 745 | |
| 746 | 746 | if(false !== $this->current_accommodation && !empty($this->current_accommodation) && array_key_exists($day['content_entity_id'],$this->current_accommodation)){ |
| 747 | - $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
| 747 | + $ac_id = $this->current_accommodation[$day['content_entity_id']]; |
|
| 748 | 748 | }else{ |
| 749 | 749 | $ac_id = wp_insert_post(array( |
| 750 | - 'post_type' => 'accommodation', |
|
| 751 | - 'post_status' => 'draft', |
|
| 752 | - 'post_title' => $day['content_entity_id'] |
|
| 753 | - )); |
|
| 750 | + 'post_type' => 'accommodation', |
|
| 751 | + 'post_status' => 'draft', |
|
| 752 | + 'post_title' => $day['content_entity_id'] |
|
| 753 | + )); |
|
| 754 | 754 | $this->save_custom_field($day['content_entity_id'],'lsx_wetu_id',$ac_id); |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | if('' !== $ac_id && false !== $ac_id){ |
| 758 | - $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
| 758 | + $this->save_custom_field($ac_id,'accommodation_to_tour',$id,false,false); |
|
| 759 | 759 | $this->save_custom_field($id,'tour_to_accommodation',$ac_id,false,false); |
| 760 | - } |
|
| 760 | + } |
|
| 761 | 761 | } |
| 762 | 762 | return $ac_id; |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
| 766 | 766 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
| 767 | - * |
|
| 768 | - * @param $post_type string |
|
| 769 | - * @return boolean / array |
|
| 767 | + * |
|
| 768 | + * @param $post_type string |
|
| 769 | + * @return boolean / array |
|
| 770 | 770 | */ |
| 771 | 771 | public function find_current_accommodation($post_type='accommodation') { |
| 772 | 772 | global $wpdb; |
@@ -774,16 +774,16 @@ discard block |
||
| 774 | 774 | |
| 775 | 775 | $return = false; |
| 776 | 776 | if(!empty($accommodation)){ |
| 777 | - foreach($accommodation as $key => $acc){ |
|
| 777 | + foreach($accommodation as $key => $acc){ |
|
| 778 | 778 | $return[$acc->meta_value] = $acc->post_id; |
| 779 | - } |
|
| 780 | - } |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | 781 | return $return; |
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
| 785 | 785 | * Grab all the current accommodation posts via the lsx_wetu_id field. |
| 786 | - * @return boolean / array |
|
| 786 | + * @return boolean / array |
|
| 787 | 787 | */ |
| 788 | 788 | public function find_current_destinations() { |
| 789 | 789 | return $this->find_current_accommodation('destination'); |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | $country_wetu_id = get_post_meta($potential_id,'lsx_wetu_id',true); |
| 811 | 811 | if(false !== $country_wetu_id){ |
| 812 | 812 | $this->set_country($country_wetu_id, $id); |
| 813 | - } |
|
| 813 | + } |
|
| 814 | 814 | |
| 815 | 815 | }else { |
| 816 | 816 | |
@@ -821,27 +821,27 @@ discard block |
||
| 821 | 821 | |
| 822 | 822 | if (!empty($destination_data) && !isset($destination_data['error'])) { |
| 823 | 823 | |
| 824 | - $destination_title = $day['destination_content_entity_id']; |
|
| 824 | + $destination_title = $day['destination_content_entity_id']; |
|
| 825 | 825 | |
| 826 | - if(isset($destination_data[0]['name'])){ |
|
| 826 | + if(isset($destination_data[0]['name'])){ |
|
| 827 | 827 | $destination_title = $destination_data[0]['name']; |
| 828 | - } |
|
| 828 | + } |
|
| 829 | 829 | |
| 830 | - if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
| 831 | - && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
| 830 | + if(isset($destination_data[0]['map_object_id']) && isset($destination_data[0]['position']['country_content_entity_id']) |
|
| 831 | + && $destination_data[0]['map_object_id'] !== $destination_data[0]['position']['country_content_entity_id']){ |
|
| 832 | 832 | |
| 833 | 833 | $country_id = $this->set_country($destination_data[0]['position']['country_content_entity_id'], $id); |
| 834 | - } |
|
| 834 | + } |
|
| 835 | 835 | |
| 836 | - $dest_post = array( |
|
| 836 | + $dest_post = array( |
|
| 837 | 837 | 'post_type' => 'destination', |
| 838 | 838 | 'post_status' => 'draft', |
| 839 | 839 | 'post_title' => $destination_title |
| 840 | 840 | ); |
| 841 | 841 | |
| 842 | - if(false !== $country_id){ |
|
| 842 | + if(false !== $country_id){ |
|
| 843 | 843 | $dest_post['post_parent'] = $country_id; |
| 844 | - } |
|
| 844 | + } |
|
| 845 | 845 | $dest_id = wp_insert_post($dest_post); |
| 846 | 846 | |
| 847 | 847 | //Make sure we register the |
@@ -863,50 +863,50 @@ discard block |
||
| 863 | 863 | * Connects the destinations post type |
| 864 | 864 | * |
| 865 | 865 | * @param $dest_id string |
| 866 | - * @param $country_id array |
|
| 866 | + * @param $country_id array |
|
| 867 | 867 | * @param $id string |
| 868 | 868 | */ |
| 869 | 869 | public function set_country($country_wetu_id, $id) { |
| 870 | - $country_id = false; |
|
| 870 | + $country_id = false; |
|
| 871 | 871 | $this->current_destinations = $this->find_current_destinations(); |
| 872 | 872 | |
| 873 | - if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
| 874 | - $country_id = $this->current_destinations[$country_wetu_id]; |
|
| 875 | - } else { |
|
| 873 | + if (false !== $this->current_destinations && !empty($this->current_destinations) && array_key_exists($country_wetu_id, $this->current_destinations)) { |
|
| 874 | + $country_id = $this->current_destinations[$country_wetu_id]; |
|
| 875 | + } else { |
|
| 876 | 876 | |
| 877 | - $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
| 877 | + $country_json = file_get_contents("http://wetu.com/API/Pins/".$this->api_key."/Get?ids=" . $country_wetu_id); |
|
| 878 | 878 | |
| 879 | - if ($country_json) { |
|
| 880 | - $country_data = json_decode($country_json, true); |
|
| 879 | + if ($country_json) { |
|
| 880 | + $country_data = json_decode($country_json, true); |
|
| 881 | 881 | |
| 882 | - if (!empty($country_data) && !isset($country_data['error'])) { |
|
| 882 | + if (!empty($country_data) && !isset($country_data['error'])) { |
|
| 883 | 883 | |
| 884 | 884 | //Format the title of the destination if its available, otherwise default to the WETU ID. |
| 885 | - $country_title = $country_wetu_id; |
|
| 886 | - if (isset($country_data[0]['name'])) { |
|
| 885 | + $country_title = $country_wetu_id; |
|
| 886 | + if (isset($country_data[0]['name'])) { |
|
| 887 | 887 | $country_title = $country_data[0]['name']; |
| 888 | - } |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | 890 | $country_id = wp_insert_post(array( |
| 891 | - 'post_type' => 'destination', |
|
| 892 | - 'post_status' => 'draft', |
|
| 893 | - 'post_title' => $country_title |
|
| 894 | - )); |
|
| 891 | + 'post_type' => 'destination', |
|
| 892 | + 'post_status' => 'draft', |
|
| 893 | + 'post_title' => $country_title |
|
| 894 | + )); |
|
| 895 | 895 | //add the country to the current destination stack |
| 896 | 896 | $this->current_destinations[$country_wetu_id] = $country_id; |
| 897 | 897 | |
| 898 | 898 | //Save the wetu field |
| 899 | - $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 899 | + $this->save_custom_field($country_wetu_id, 'lsx_wetu_id', $country_id); |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - if ('' !== $country_id && false !== $country_id) { |
|
| 905 | - $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
| 906 | - $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
| 904 | + if ('' !== $country_id && false !== $country_id) { |
|
| 905 | + $this->save_custom_field($country_id, 'destination_to_tour', $id, false, false); |
|
| 906 | + $this->save_custom_field($id, 'tour_to_destination', $country_id, false, false); |
|
| 907 | 907 | |
| 908 | - return $country_id; |
|
| 909 | - } |
|
| 908 | + return $country_id; |
|
| 909 | + } |
|
| 910 | 910 | } |
| 911 | 911 | } |
| 912 | 912 | $wetu_importer_tours = new WETU_Importer_Tours(); |
| 913 | 913 | \ No newline at end of file |