PluginProbe
Import Users & Customers with Meta | WP Ultimate CSV Importer Add-on / 2.1
Import Users & Customers with Meta | WP Ultimate CSV Importer Add-on v2.1
2.1 2.0 1.7.1 1.2.9 1.3 1.4 1.4.1 1.4.2 1.4.3 1.5 1.6 1.7 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8
← All changes | importExtensions/BuddyImport.php +77 -69 1.7.1 → 2.1 View file →
@@ -8,9 +8,9 @@
8 8
9 9 namespace Smackcoders\SMUSERS;
10 10
11 11 if ( ! defined( 'ABSPATH' ) )
12 - exit; // Exit if accessed directly
12 +exit; // Exit if accessed directly
13 13
14 14 class BuddyImport extends UsersImport{
15 15 private static $buddy_instance = null;
16 16
@@ -19,79 +19,87 @@
19 19 if (BuddyImport::$buddy_instance == null) {
20 20 BuddyImport::$buddy_instance = new BuddyImport;
21 21 return BuddyImport::$buddy_instance;
22 22 }
23 - return BuddyImport::$buddy_instance;
24 - }
23 + return BuddyImport::$buddy_instance;
24 + }
25 25
26 - function set_buddy_values($header_array ,$value_array , $map, $post_id , $type){
27 - $post_values = [];
26 + function set_buddy_values($header_array ,$value_array , $map, $post_id , $type){
27 + $post_values = [];
28 28 $helpers_instance = ImportHelpers::getInstance();
29 29 $post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
30 30 $this->buddy_import_function($post_values,$type, $post_id);
31 +
32 + }
31 33
32 - }
33 -
34 - function buddy_import_function($data_array, $importas,$uID) {
35 -
36 - global $wpdb;
37 - foreach($data_array as $data_key => $data_value) {
38 - $get_buddy_fields = $wpdb->get_results($wpdb->prepare("select type , name from {$wpdb->prefix}bp_xprofile_fields where id= $data_key" ), ARRAY_A);
39 - foreach($get_buddy_fields as $buddy_fields){
40 - $field_type = $buddy_fields['type'];
41 - if($field_type == 'multiselect_custom_post_type')
42 - {
43 - $explode = explode('|',$data_value);
44 - $data_value = serialize($explode);
45 - }
46 - elseif($field_type == 'multiselectbox')
47 - {
48 - $explode = explode('|',$data_value);
49 - $data_value = serialize($explode);
50 -
51 - }
52 - elseif($field_type == 'multiselect_custom_taxonomy')
53 - {
54 - $explode = explode('|',$data_value);
55 - $data_value = serialize($explode);
56 - }
57 -
58 - elseif($field_type == 'fromto')
59 - {
60 - $explode = explode('|',$data_value);
61 - $data_results['from'] = $explode[0];
62 - $data_results['to'] = $explode[1];
63 - $data_value = serialize($data_results);
64 - }
65 - elseif($field_type == 'image')
66 - {
67 - $image_name = $data_value;
68 - $upload_path = wp_upload_dir();
69 - $path = $upload_path['basedir'].'/bpxcftr-profile-uploads/'.$uID.'/image';
70 - $base_name=basename($image_name);
71 - wp_mkdir_p($path);
72 - $data = file_get_contents($image_name);
73 - $new = $path.'/'.$base_name;
74 - file_put_contents($new, $data);
75 - $image_path = "bpxcftr-profile-uploads/$uID/image/".basename($image_name);
76 - $data_value = $image_path;
77 - }
78 - elseif($field_type == 'file')
79 - {
80 - $file_name = $data_value;
81 - $upload_path = wp_upload_dir();
82 - $path = $upload_path['basedir'].'/bpxcftr-profile-uploads/'.$uID.'/file';
83 - $base_name=basename($file_name);
84 - wp_mkdir_p($path);
85 - $data = file_get_contents($file_name);
86 - $new = $path.'/'.$base_name;
87 - file_put_contents($new, $data);
88 - $file_path = "bpxcftr-profile-uploads/$uID/file/".basename($file_name);
89 - $data_value = $file_path;
90 - }
91 - }
92 - $wpdb->insert("{$wpdb->prefix}bp_xprofile_data", array('field_id' => $data_key,'user_id' => $uID,'value' => $data_value));
93 - }
94 - }
34 + function buddy_import_function($data_array, $importas,$uID) {
35 +
36 + global $wpdb;
37 + foreach($data_array as $data_key => $data_value) {
38 + $get_buddy_fields = $wpdb->get_results($wpdb->prepare("select type , name from {$wpdb->prefix}bp_xprofile_fields where id= %d", absint($data_key) ), ARRAY_A);
39 + foreach($get_buddy_fields as $buddy_fields){
40 + $field_type = $buddy_fields['type'];
41 + if($field_type == 'multiselect_custom_post_type')
42 + {
43 + $explode = explode('|',$data_value);
44 + $data_value = serialize($explode);
45 + }
46 + elseif($field_type == 'multiselectbox')
47 + {
48 + $explode = explode('|',$data_value);
49 + $data_value = serialize($explode);
50 +
51 + }
52 + elseif($field_type == 'multiselect_custom_taxonomy')
53 + {
54 + $explode = explode('|',$data_value);
55 + $data_value = serialize($explode);
56 + }
57 +
58 + elseif($field_type == 'fromto')
59 + {
60 + $explode = explode('|',$data_value);
61 + $data_results['from'] = $explode[0];
62 + $data_results['to'] = $explode[1];
63 + $data_value = serialize($data_results);
64 + }
65 + elseif($field_type == 'image')
66 + {
67 + $image_name = $data_value;
68 + $upload_path = wp_upload_dir();
69 + $path = $upload_path['basedir'].'/bpxcftr-profile-uploads/'.$uID.'/image';
70 + $base_name = sanitize_file_name(basename((string) wp_parse_url($image_name, PHP_URL_PATH)));
71 + $file_type = wp_check_filetype($base_name);
72 + if (empty($file_type['type']) || strpos($file_type['type'], 'image/') !== 0) {
73 + continue 2;
74 + }
75 + wp_mkdir_p($path);
76 + $data = file_get_contents($image_name);
77 + $new = $path.'/'.$base_name;
78 + file_put_contents($new, $data);
79 + $image_path = "bpxcftr-profile-uploads/$uID/image/".$base_name;
80 + $data_value = $image_path;
81 + }
82 + elseif($field_type == 'file')
83 + {
84 + $file_name = $data_value;
85 + $upload_path = wp_upload_dir();
86 + $path = $upload_path['basedir'].'/bpxcftr-profile-uploads/'.$uID.'/file';
87 + $base_name = sanitize_file_name(basename((string) wp_parse_url($file_name, PHP_URL_PATH)));
88 + $file_type = wp_check_filetype($base_name);
89 + if (empty($file_type['type'])) {
90 + continue 2;
91 + }
92 + wp_mkdir_p($path);
93 + $data = file_get_contents($file_name);
94 + $new = $path.'/'.$base_name;
95 + file_put_contents($new, $data);
96 + $file_path = "bpxcftr-profile-uploads/$uID/file/".$base_name;
97 + $data_value = $file_path;
98 + }
99 + }
100 + $wpdb->insert("{$wpdb->prefix}bp_xprofile_data", array('field_id' => $data_key,'user_id' => $uID,'value' => $data_value));
101 + }
102 + }
95 103 }
96 104 global $buddy_class;
97 -$buddy_class = new BuddyImport;
105 +$buddy_class = new BuddyImport;