PluginProbe ʕ •ᴥ•ʔ
Wp Social Login and Register Social Counter / 2.2.4
Wp Social Login and Register Social Counter v2.2.4
trunk 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.10 1.3.11 1.3.2 1.3.3 1.3.4 1.3.6 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.4 1.4.5 1.4.6 1.4.8 1.4.9 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.5 1.8.6 1.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.8 2.2.9 3.0.0 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0
wp-social / helper / user-helper.php
wp-social / helper Last commit date
helper.php 3 years ago share-style-settings.php 3 years ago social-share-style.php 3 years ago user-helper.php 3 years ago view-helper.php 3 years ago
user-helper.php
113 lines
1 <?php
2
3 namespace WP_Social\Helper;
4
5 use WP_User_Query;
6
7 defined('ABSPATH') || exit;
8
9 class User_Helper
10 {
11 public static function provider()
12 {
13 global $wpdb;
14
15 $socials_sql = "SELECT DISTINCT meta_value FROM $wpdb->usermeta WHERE meta_key = 'xs_social_register_by'";
16
17 return $wpdb->get_results($socials_sql);
18 }
19
20 public static function export_users_content_csv($type)
21 {
22 if ($type != 'all') {
23 $args_type = array(
24 'key' => 'xs_social_register_by',
25 'value' => $type
26 );
27 } else {
28 $args_type = array(
29 'key' => 'xs_social_register_by',
30 );
31 }
32 $args = array(
33 'meta_query' => array($args_type)
34 );
35
36 $wp_user_query = new WP_User_Query($args);
37
38 $users = $wp_user_query->get_results();
39
40 $user_table_data = array("ID", "user_login", "user_email", "user_pass", "user_nicename", "user_url", "user_registered", "display_name");
41
42 $data = [];
43 $row = [];
44 $usermeta = self::get_user_meta_keys();
45
46 foreach ($users as $user) {
47 foreach ($user_table_data as $key) {
48 $row[$key] = $user->data->{$key};
49 }
50 $row['role'] = get_userdata($user->data->ID)->roles[0];
51 foreach ($usermeta as $key) {
52 $row[$key] = self::user_data_filter(get_user_meta($user->data->ID, $key, true));
53 }
54 $data[] = array_values($row);
55 }
56
57 $user_table_data[] = 'role';
58 $usernd = array_merge($user_table_data, $usermeta);
59 $data = array_merge(array($usernd), $data);
60
61 $upload_dir = wp_upload_dir();
62
63 $csv = $upload_dir['basedir'] . "/users-list.csv";
64
65 $file = fopen($csv, 'w');
66
67 foreach ($data as $line) {
68 fputcsv($file, $line, ',');
69 }
70
71 fclose($file);
72
73 $fsize = filesize($csv) + 3;
74 $path_parts = pathinfo($csv);
75
76 header("Content-type: text/csv;charset=utf-8");
77 header("Content-Disposition: attachment; filename=\"" . $path_parts["basename"] . "\"");
78 header("Content-length: $fsize");
79
80 ob_clean();
81 flush();
82
83 // csv encoding format
84 echo esc_html("\xEF\xBB\xBF");
85 readfile($csv);
86 unlink($csv);
87 }
88
89 private static function user_data_filter($value)
90 {
91 if (is_array($value) || is_object($value)) {
92 return serialize($value);
93 }
94 return $value;
95 }
96
97 private static function get_user_meta_keys()
98 {
99 global $wpdb;
100
101 $meta_keys = [];
102
103 $select = "SELECT distinct $wpdb->usermeta.meta_key FROM $wpdb->usermeta";
104
105 $usermeta = $wpdb->get_results($select, ARRAY_A);
106
107 foreach ($usermeta as $key => $value) {
108 $meta_keys[] = $value["meta_key"];
109 }
110 return $meta_keys;
111 }
112 }
113