Export Users to CSV - Version 0.3

Version Description

Download this release

Release Info

Developer sorich87
Plugin Icon 128x128 Export Users to CSV
Version 0.3
Comparing to
See all releases

Code changes from version 0.2 to 0.3

export-users-to-csv.php CHANGED
@@ -1,16 +1,17 @@
1
  <?php
2
  /**
3
  * @package Export_Users_to_CSV
4
- * @version 0.2
5
  */
6
  /*
7
  Plugin Name: Export Users to CSV
8
  Plugin URI: http://pubpoet.com/plugins/
9
  Description: Export Users data and metadata to a csv file.
10
- Version: 0.2
11
  Author: PubPoet
12
  Author URI: http://pubpoet.com/
13
  License: GPL2
 
14
  */
15
  /* Copyright 2011 Ulrich Sossou (http://github.com/sorich87)
16
 
@@ -28,6 +29,8 @@ License: GPL2
28
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
  */
30
 
 
 
31
  /**
32
  * Main plugin class
33
  *
@@ -52,7 +55,7 @@ class PP_EU_Export_Users {
52
  * @since 0.1
53
  **/
54
  public function add_admin_pages() {
55
- add_users_page( __( 'Export to CSV' ), __( 'Export to CSV' ), 'list_users', 'export-users-to-csv', array( $this, 'users_page' ) );
56
  }
57
 
58
  /**
@@ -69,14 +72,6 @@ class PP_EU_Export_Users {
69
  'role' => stripslashes( $_POST['role'] )
70
  );
71
 
72
- if ( ! empty( $args['role'] ) ) {
73
- global $wp_roles;
74
- $roles = array_keys( $wp_roles->role_names );
75
-
76
- if ( ! in_array( $_POST['role'], $roles ) )
77
- $args['role'] = '';
78
- }
79
-
80
  add_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
81
  $users = get_users( $args );
82
  remove_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
@@ -98,8 +93,18 @@ class PP_EU_Export_Users {
98
 
99
  $exclude_data = apply_filters( 'pp_eu_exclude_data', array() );
100
 
101
- $first_user = reset( $users );
102
- $fields = array_keys( (array) $first_user->data );
 
 
 
 
 
 
 
 
 
 
103
  $headers = array();
104
  foreach ( $fields as $key => $field ) {
105
  if ( in_array( $field, $exclude_data ) )
@@ -112,9 +117,9 @@ class PP_EU_Export_Users {
112
  foreach ( $users as $user ) {
113
  $data = array();
114
  foreach ( $fields as $field ) {
115
- $user_data = (array) $user->data;
116
- $value = $user_data[$field];
117
- $data[] = is_array( $value ) ? '"' . serialize( $value ) . '"' : '"' . $value . '"';
118
  }
119
  echo implode( ',', $data ) . "\n";
120
  }
@@ -130,25 +135,25 @@ class PP_EU_Export_Users {
130
  **/
131
  public function users_page() {
132
  if ( ! current_user_can( 'list_users' ) )
133
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
134
  ?>
135
 
136
  <div class="wrap">
137
- <h2><?php _e( 'Export users to a CSV file' ); ?></h2>
138
  <?php
139
  if ( isset( $_GET['error'] ) ) {
140
- echo '<div class="updated"><p><strong>' . __( 'No user found.' ) . '</strong></p></div>';
141
  }
142
  ?>
143
  <form method="post" action="" enctype="multipart/form-data">
144
  <?php wp_nonce_field( 'pp-eu-export-users-users-page_export', '_wpnonce-pp-eu-export-users-users-page_export' ); ?>
145
  <table class="form-table">
146
  <tr valign="top">
147
- <th scope="row"><label for"pp_eu_users_role"><?php _e( 'Role' ); ?></label></th>
148
  <td>
149
  <select name="role" id="pp_eu_users_role">
150
  <?php
151
- echo '<option value="">' . __( 'Every Role' ) . '</option>';
152
  global $wp_roles;
153
  foreach ( $wp_roles->role_names as $role => $name ) {
154
  echo "\n\t<option value='" . esc_attr( $role ) . "'>$name</option>";
@@ -158,14 +163,14 @@ class PP_EU_Export_Users {
158
  </td>
159
  </tr>
160
  <tr valign="top">
161
- <th scope="row"><label><?php _e( 'Date range' ); ?></label></th>
162
  <td>
163
  <select name="start_date" id="pp_eu_users_start_date">
164
- <option value="0"><?php _e( 'Start Date' ); ?></option>
165
  <?php $this->export_date_options(); ?>
166
  </select>
167
  <select name="end_date" id="pp_eu_users_end_date">
168
- <option value="0"><?php _e( 'End Date' ); ?></option>
169
  <?php $this->export_date_options(); ?>
170
  </select>
171
  </td>
@@ -173,17 +178,14 @@ class PP_EU_Export_Users {
173
  </table>
174
  <p class="submit">
175
  <input type="hidden" name="_wp_http_referer" value="<?php echo $_SERVER['REQUEST_URI'] ?>" />
176
- <input type="submit" class="button-primary" value="<?php _e( 'Export' ); ?>" />
177
  </p>
178
  </form>
179
  <?php
180
  }
181
 
182
  public function exclude_data() {
183
- $exclude = array( 'user_pass', 'user_activation_key', 'user_status', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'show_admin_bar_admin', 'wp_capabilities', 'wp_user_level', 'wp_usersettings', 'wp_usersettingstime', 'wp_dashboard_quick_press_last_post_id', 'metaboxorder_dashboard', 'screen_layout_dashboard', 'closedpostboxes_dashboard', 'metaboxhidden_dashboard', 'metaboxhidden_forum', 'closedpostboxes_forum', 'plugins_last_view', 'metaboxhidden_program', 'closedpostboxes_program', 'metaboxhidden_navmenus', 'managenavmenuscolumnshidden', 'user_level', 'user_firstname', 'user_lastname', 'user_description' );
184
-
185
- if ( ! is_multisite() )
186
- $exclude = array_merge( $exclude, array( 'spam', 'deleted', 'primary_blog', 'source_domain' ) );
187
 
188
  return $exclude;
189
  }
@@ -194,7 +196,7 @@ class PP_EU_Export_Users {
194
  $where = '';
195
 
196
  if ( ! empty( $_POST['start_date'] ) )
197
- $where .= $wpdb->prepare( " AND $wpdb->users.user_registered >= %s", date( 'Y-m-d', strtotime($_POST['start_date']) ) );
198
 
199
  if ( ! empty( $_POST['end_date'] ) )
200
  $where .= $wpdb->prepare( " AND $wpdb->users.user_registered < %s", date( 'Y-m-d', strtotime( '+1 month', strtotime( $_POST['end_date'] ) ) ) );
1
  <?php
2
  /**
3
  * @package Export_Users_to_CSV
4
+ * @version 0.3
5
  */
6
  /*
7
  Plugin Name: Export Users to CSV
8
  Plugin URI: http://pubpoet.com/plugins/
9
  Description: Export Users data and metadata to a csv file.
10
+ Version: 0.3
11
  Author: PubPoet
12
  Author URI: http://pubpoet.com/
13
  License: GPL2
14
+ Text Domain: export-users-to-csv
15
  */
16
  /* Copyright 2011 Ulrich Sossou (http://github.com/sorich87)
17
 
29
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
  */
31
 
32
+ load_plugin_textdomain( 'export-users-to-csv', false, basename( dirname( __FILE__ ) ) . '/languages' );
33
+
34
  /**
35
  * Main plugin class
36
  *
55
  * @since 0.1
56
  **/
57
  public function add_admin_pages() {
58
+ add_users_page( __( 'Export to CSV', 'export-users-to-csv' ), __( 'Export to CSV', 'export-users-to-csv' ), 'list_users', 'export-users-to-csv', array( $this, 'users_page' ) );
59
  }
60
 
61
  /**
72
  'role' => stripslashes( $_POST['role'] )
73
  );
74
 
 
 
 
 
 
 
 
 
75
  add_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
76
  $users = get_users( $args );
77
  remove_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
93
 
94
  $exclude_data = apply_filters( 'pp_eu_exclude_data', array() );
95
 
96
+ global $wpdb;
97
+
98
+ $data_keys = array(
99
+ 'ID', 'user_login', 'user_pass',
100
+ 'user_nicename', 'user_email', 'user_url',
101
+ 'user_registered', 'user_activation_key', 'user_status',
102
+ 'display_name'
103
+ );
104
+ $meta_keys = $wpdb->get_results( "SELECT distinct(meta_key) FROM $wpdb->usermeta" );
105
+ $meta_keys = wp_list_pluck( $meta_keys, 'meta_key' );
106
+ $fields = array_merge( $data_keys, $meta_keys );
107
+
108
  $headers = array();
109
  foreach ( $fields as $key => $field ) {
110
  if ( in_array( $field, $exclude_data ) )
117
  foreach ( $users as $user ) {
118
  $data = array();
119
  foreach ( $fields as $field ) {
120
+ $value = isset( $user->{$field} ) ? $user->{$field} : '';
121
+ $value = is_array( $value ) ? serialize( $value ) : $value;
122
+ $data[] = '"' . str_replace( '"', '""', $value ) . '"';
123
  }
124
  echo implode( ',', $data ) . "\n";
125
  }
135
  **/
136
  public function users_page() {
137
  if ( ! current_user_can( 'list_users' ) )
138
+ wp_die( __( 'You do not have sufficient permissions to access this page.', 'export-users-to-csv' ) );
139
  ?>
140
 
141
  <div class="wrap">
142
+ <h2><?php _e( 'Export users to a CSV file', 'export-users-to-csv' ); ?></h2>
143
  <?php
144
  if ( isset( $_GET['error'] ) ) {
145
+ echo '<div class="updated"><p><strong>' . __( 'No user found.', 'export-users-to-csv' ) . '</strong></p></div>';
146
  }
147
  ?>
148
  <form method="post" action="" enctype="multipart/form-data">
149
  <?php wp_nonce_field( 'pp-eu-export-users-users-page_export', '_wpnonce-pp-eu-export-users-users-page_export' ); ?>
150
  <table class="form-table">
151
  <tr valign="top">
152
+ <th scope="row"><label for"pp_eu_users_role"><?php _e( 'Role', 'export-users-to-csv' ); ?></label></th>
153
  <td>
154
  <select name="role" id="pp_eu_users_role">
155
  <?php
156
+ echo '<option value="">' . __( 'Every Role', 'export-users-to-csv' ) . '</option>';
157
  global $wp_roles;
158
  foreach ( $wp_roles->role_names as $role => $name ) {
159
  echo "\n\t<option value='" . esc_attr( $role ) . "'>$name</option>";
163
  </td>
164
  </tr>
165
  <tr valign="top">
166
+ <th scope="row"><label><?php _e( 'Date range', 'export-users-to-csv' ); ?></label></th>
167
  <td>
168
  <select name="start_date" id="pp_eu_users_start_date">
169
+ <option value="0"><?php _e( 'Start Date', 'export-users-to-csv' ); ?></option>
170
  <?php $this->export_date_options(); ?>
171
  </select>
172
  <select name="end_date" id="pp_eu_users_end_date">
173
+ <option value="0"><?php _e( 'End Date', 'export-users-to-csv' ); ?></option>
174
  <?php $this->export_date_options(); ?>
175
  </select>
176
  </td>
178
  </table>
179
  <p class="submit">
180
  <input type="hidden" name="_wp_http_referer" value="<?php echo $_SERVER['REQUEST_URI'] ?>" />
181
+ <input type="submit" class="button-primary" value="<?php _e( 'Export', 'export-users-to-csv' ); ?>" />
182
  </p>
183
  </form>
184
  <?php
185
  }
186
 
187
  public function exclude_data() {
188
+ $exclude = array( 'user_pass', 'user_activation_key' );
 
 
 
189
 
190
  return $exclude;
191
  }
196
  $where = '';
197
 
198
  if ( ! empty( $_POST['start_date'] ) )
199
+ $where .= $wpdb->prepare( " AND $wpdb->users.user_registered >= %s", date( 'Y-m-d', strtotime( $_POST['start_date'] ) ) );
200
 
201
  if ( ! empty( $_POST['end_date'] ) )
202
  $where .= $wpdb->prepare( " AND $wpdb->users.user_registered < %s", date( 'Y-m-d', strtotime( '+1 month', strtotime( $_POST['end_date'] ) ) ) );
languages/export-users-to-csv-fr_FR.mo ADDED
Binary file
languages/export-users-to-csv-fr_FR.po ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Translation of the WordPress plugin Export Users to CSV 0.3 by PubPoet.
2
+ # Copyright (C) 2011 PubPoet
3
+ # This file is distributed under the same license as the Export Users to CSV package.
4
+ # Ulrich Sossou <http://github.com/sorich87>, 2011.
5
+ #
6
+ msgid ""
7
+ msgstr ""
8
+ "Project-Id-Version: Export Users to CSV 0.3\n"
9
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/export-users-to-csv\n"
10
+ "POT-Creation-Date: 2011-11-27 09:07+0100\n"
11
+ "PO-Revision-Date: 2011-11-27 09:24+0100\n"
12
+ "Last-Translator: Ulrich Sossou <sorich87@gmail.com>\n"
13
+ "Language-Team: Ulrich Sossou\n"
14
+ "Language: \n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=UTF-8\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+ "X-Poedit-Language: French\n"
19
+ "X-Poedit-Country: FRANCE\n"
20
+
21
+ #: export-users-to-csv.php:58
22
+ msgid "Export to CSV"
23
+ msgstr "Exporter en CSV"
24
+
25
+ #: export-users-to-csv.php:138
26
+ msgid "You do not have sufficient permissions to access this page."
27
+ msgstr "Vous n'avez pas les permissions suffisantes pour accéder à cette page."
28
+
29
+ #: export-users-to-csv.php:142
30
+ msgid "Export users to a CSV file"
31
+ msgstr "Exporter les utilisateurs vers un fichier CSV"
32
+
33
+ #: export-users-to-csv.php:145
34
+ msgid "No user found."
35
+ msgstr "Aucun utilisateur trouvé."
36
+
37
+ #: export-users-to-csv.php:152
38
+ msgid "Role"
39
+ msgstr "Role"
40
+
41
+ #: export-users-to-csv.php:156
42
+ msgid "Every Role"
43
+ msgstr "Tous les Roles"
44
+
45
+ #: export-users-to-csv.php:166
46
+ msgid "Date range"
47
+ msgstr "Date d'inscription"
48
+
49
+ #: export-users-to-csv.php:169
50
+ msgid "Start Date"
51
+ msgstr "De"
52
+
53
+ #: export-users-to-csv.php:173
54
+ msgid "End Date"
55
+ msgstr "A"
56
+
57
+ #: export-users-to-csv.php:181
58
+ msgid "Export"
59
+ msgstr "Exporter"
60
+
61
+ #. Plugin Name of the plugin/theme
62
+ msgid "Export Users to CSV"
63
+ msgstr "Export Users to CSV"
64
+
65
+ #. Plugin URI of the plugin/theme
66
+ msgid "http://pubpoet.com/plugins/"
67
+ msgstr "http://pubpoet.com/plugins/"
68
+
69
+ #. Description of the plugin/theme
70
+ msgid "Export Users data and metadata to a csv file."
71
+ msgstr "Exporte les données et métadonnées des utilisateurs de votre site dans un fichier csv."
72
+
73
+ #. Author of the plugin/theme
74
+ msgid "PubPoet"
75
+ msgstr "PubPoet"
76
+
77
+ #. Author URI of the plugin/theme
78
+ msgid "http://pubpoet.com/"
79
+ msgstr "http://pubpoet.com/"
80
+
languages/export-users-to-csv-tr_TR.mo ADDED
Binary file
languages/export-users-to-csv-tr_TR.po ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Export to CSV\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2011-10-30 17:05+0200\n"
6
+ "PO-Revision-Date: \n"
7
+ "Last-Translator: Tolga Kaprol <tolgakaprol@gmail.com>\n"
8
+ "Language-Team: Tolga Kaprol <wordpress@codementors.com>\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Poedit-Language: Turkish\n"
13
+ "X-Poedit-Country: TURKEY\n"
14
+ "X-Poedit-SourceCharset: iso-8859-1\n"
15
+ "X-Poedit-KeywordsList: __;_e\n"
16
+ "X-Poedit-Basepath: .\n"
17
+ "X-Poedit-SearchPath-0: .\n"
18
+
19
+ #: export-users-to-csv.php:57
20
+ msgid "Export to CSV"
21
+ msgstr "CSV'ye Aktar"
22
+
23
+ #: export-users-to-csv.php:135
24
+ msgid "You do not have sufficient permissions to access this page."
25
+ msgstr "Bu sayfaya ulaşmak için yetkiniz yoktur."
26
+
27
+ #: export-users-to-csv.php:139
28
+ msgid "Export users to a CSV file"
29
+ msgstr "Kullanıcıları CSV'ye Aktar"
30
+
31
+ #: export-users-to-csv.php:142
32
+ msgid "No user found."
33
+ msgstr "Kullanıcı bulunamadı."
34
+
35
+ #: export-users-to-csv.php:149
36
+ msgid "Role"
37
+ msgstr "Rol"
38
+
39
+ #: export-users-to-csv.php:153
40
+ msgid "Every Role"
41
+ msgstr "Tüm Roller"
42
+
43
+ #: export-users-to-csv.php:163
44
+ msgid "Date range"
45
+ msgstr "Tarih Aralığı"
46
+
47
+ #: export-users-to-csv.php:166
48
+ msgid "Start Date"
49
+ msgstr "Başlangıç Tarihi"
50
+
51
+ #: export-users-to-csv.php:170
52
+ msgid "End Date"
53
+ msgstr "Bitiş Tarihi"
54
+
55
+ #: export-users-to-csv.php:178
56
+ msgid "Export"
57
+ msgstr "Dışa Aktar"
58
+
59
+ #~ msgid "Do you want to continue?"
60
+ #~ msgstr "Devam etmek istiyor musunuz?"
61
+
62
+ #~ msgid "What it does "
63
+ #~ msgstr "Ne yapar?"
64
+
65
+ #~ msgid "Parameters"
66
+ #~ msgstr "Parametreler"
67
+
68
+ #~ msgid "Example"
69
+ #~ msgstr "Örnek"
70
+
71
+ #~ msgid "Popular Posts"
72
+ #~ msgstr "Popüler İçerikler"
73
+
74
+ #~ msgid "Success! The cache table has been cleared!"
75
+ #~ msgstr "Tebrikler! Önbellek tablosu temizlendi!"
76
+
77
+ #~ msgid "Wordpress Popular Posts Stats"
78
+ #~ msgstr "Wordpress Popüler İçerikler İstatistikleri"
languages/export-users-to-csv.pot ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Translation of the WordPress plugin Export Users to CSV 0.3 by PubPoet.
2
+ # Copyright (C) 2011 PubPoet
3
+ # This file is distributed under the same license as the Export Users to CSV package.
4
+ # Ulrich Sossou <http://github.com/sorich87>, 2011.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: Export Users to CSV 0.3\n"
10
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/export-users-to-csv\n"
11
+ "POT-Creation-Date: 2011-11-27 09:07+0100\n"
12
+ "PO-Revision-Date: 2011-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: Ulrich Sossou <http://github.com/sorich87>\n"
14
+ "Language-Team: Ulrich Sossou <http://github.com/sorich87>\n"
15
+ "Language: \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=utf-8\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+
20
+ #: export-users-to-csv.php:58
21
+ msgid "Export to CSV"
22
+ msgstr ""
23
+
24
+ #: export-users-to-csv.php:138
25
+ msgid "You do not have sufficient permissions to access this page."
26
+ msgstr ""
27
+
28
+ #: export-users-to-csv.php:142
29
+ msgid "Export users to a CSV file"
30
+ msgstr ""
31
+
32
+ #: export-users-to-csv.php:145
33
+ msgid "No user found."
34
+ msgstr ""
35
+
36
+ #: export-users-to-csv.php:152
37
+ msgid "Role"
38
+ msgstr ""
39
+
40
+ #: export-users-to-csv.php:156
41
+ msgid "Every Role"
42
+ msgstr ""
43
+
44
+ #: export-users-to-csv.php:166
45
+ msgid "Date range"
46
+ msgstr ""
47
+
48
+ #: export-users-to-csv.php:169
49
+ msgid "Start Date"
50
+ msgstr ""
51
+
52
+ #: export-users-to-csv.php:173
53
+ msgid "End Date"
54
+ msgstr ""
55
+
56
+ #: export-users-to-csv.php:181
57
+ msgid "Export"
58
+ msgstr ""
59
+
60
+ #. Plugin Name of the plugin/theme
61
+ msgid "Export Users to CSV"
62
+ msgstr ""
63
+
64
+ #. Plugin URI of the plugin/theme
65
+ msgid "http://pubpoet.com/plugins/"
66
+ msgstr ""
67
+
68
+ #. Description of the plugin/theme
69
+ msgid "Export Users data and metadata to a csv file."
70
+ msgstr ""
71
+
72
+ #. Author of the plugin/theme
73
+ msgid "PubPoet"
74
+ msgstr ""
75
+
76
+ #. Author URI of the plugin/theme
77
+ msgid "http://pubpoet.com/"
78
+ msgstr ""
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: sorich87
3
  Tags: user, users, csv, batch, export, exporter, admin
4
  Requires at least: 3.2
5
  Tested up to: 3.3
6
- Stable tag: 0.2
7
 
8
  Export users data and metadata to a csv file
9
 
3
  Tags: user, users, csv, batch, export, exporter, admin
4
  Requires at least: 3.2
5
  Tested up to: 3.3
6
+ Stable tag: 0.3
7
 
8
  Export users data and metadata to a csv file
9