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
import-users / importExtensions / BuddyImport.php

BuddyImport.php in Import Users & Customers with Meta | WP Ultimate CSV Importer Add-on 2.1, at importExtensions/BuddyImport.php

105 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /******************************************************************************************
3 * Copyright (C) Smackcoders. - All Rights Reserved under Smackcoders Proprietary License
4 * Unauthorized copying of this file, via any medium is strictly prohibited
5 * Proprietary and confidential
6 * You can contact Smackcoders at email address [email protected].
7 *******************************************************************************************/
8
9 namespace Smackcoders\SMUSERS;
10
11 if ( ! defined( 'ABSPATH' ) )
12 exit; // Exit if accessed directly
13
14 class BuddyImport extends UsersImport{
15 private static $buddy_instance = null;
16
17 public static function getInstance() {
18
19 if (BuddyImport::$buddy_instance == null) {
20 BuddyImport::$buddy_instance = new BuddyImport;
21 return BuddyImport::$buddy_instance;
22 }
23 return BuddyImport::$buddy_instance;
24 }
25
26 function set_buddy_values($header_array ,$value_array , $map, $post_id , $type){
27 $post_values = [];
28 $helpers_instance = ImportHelpers::getInstance();
29 $post_values = $helpers_instance->get_header_values($map , $header_array , $value_array);
30 $this->buddy_import_function($post_values,$type, $post_id);
31
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= %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 }
103 }
104 global $buddy_class;
105 $buddy_class = new BuddyImport;