I have installed the plugin and clicks “export users” from the plugins screen.
A couple of minutes it’s says “waiting for (domain)” in the browser and then eventually I get a timeout error from Cloudflare
Error 524 Ray ID: 55311692894f3cd5 ? 2020-01-10 19:36:04 UTC
A timeout occurred
There are about 22,000 users in the database.
What do you suggest?
]]>This new version is more performant, automatically ignore some fields that are default in wordpress and fix the issue of the blank page.
<?php
/*
Plugin Name: Export Users to CSV
description: Export Users to CSV Plugin allows you to export users list and their metadata in CSV file.
Version: 1.4
Author: Boopathi Rajan
Author URI: https://www.boopathirajan.com
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function eu_register_export_page() {
add_submenu_page('tools.php', 'Export Users', 'Export Users', 'manage_options', 'wp-export-users', 'eu_export_users_page');
}
add_action('admin_menu', 'eu_register_export_page');
function eu_export_users_page() {
}
add_action('admin_init', 'eu_export');
function eu_export() {
if (!isset($_GET['page']) || isset($_GET['page']) && $_GET['page'] !== 'wp-export-users') {
return;
}
global $wpdb, $table_prefix;
ob_end_clean();
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="' . time() . '.csv";');
$file = fopen('php://output', 'w');
$ignore_sql = ' WHERE ';
foreach (array(
'meta-box',
'metabox',
'closedpostboxes',
'dashboard',
'nag',
'managenav',
'password',
'ssl',
'dismissed',
'admin',
'token',
'jetpack',
'menu',
'elementor',
'wpcom',
'submit',
'syntax',
'panel',
'shortcut',
'editing',
$table_prefix
) as $ignore_me) {
$ignore_sql .= "meta_key NOT LIKE '%" . $ignore_me . "%' AND ";
}
$meta_sql = 'SELECT meta_key FROM ' . $wpdb->usermeta . $ignore_sql . " meta_key!='first_name' AND meta_key!='last_name' GROUP BY meta_key";
$users = get_users( array( 'orderby' => 'ID','order' => 'ASC' ) );
$meta_keys = $wpdb->get_results($meta_sql);
$datas = array();
$headers = array(
'ID',
'Username',
'Email',
'Display Name',
'First Name',
'Last Name',
'Registered Date'
);
if ($users) {
foreach ($users as $user) {
$user_meta = get_userdata($user->ID);
$user_data = array();
$user_data[] = $user->ID;
$user_data[] = $user->user_login;
$user_data[] = $user->user_email;
$user_data[] = $user->display_name;
$user_data[] = $user_meta->first_name;
$user_data[] = $user_meta->last_name;
$user_data[] = $user->user_registered;
if (!empty($meta_keys)) {
foreach ($meta_keys as $meta_key) {
$key = $meta_key->meta_key;
if (!isset($headers[$key])) {
$headers[$key] = $key;
}
if (is_object($user_meta->$key) || is_array($user_meta->$key)) {
if (is_array($user_meta->$key) && count($user_meta->$key) == 1 && isset($user_meta->$key[0])) {
$user_data[] = $user_meta->$key[0];
}
else {
$user_data[] = serialize($user_meta->$key);
}
}
else {
$user_data[] = $user_meta->$key;
}
}
}
$datas[] = $user_data;
}
}
fputcsv($file, $headers);
foreach ($datas as $data) {
fputcsv($file, $data);
}
fclose($file);
exit();
}
/* Add action links to plugin list*/
add_filter('plugin_action_links_' . plugin_basename(__FILE__) , 'eu_add_export_user_action_links');
function eu_add_export_user_action_links($links) {
$settings_link = array(
'<a href="' . admin_url('tools.php?page=wp-export-users') . '">Export Users</a>'
);
return array_merge($links, $settings_link);
}
]]>
Thanks for your plugin that worked fine until a recent update.
When I click on Export Users the output overlays the current page and I cannot find any CSV file.
Where is the CSV file supposed to be exported?
Is it a way to rollback to a previous version?
Thank you for your help.
]]>Hello,
When I visit /wp-admin/tools.php?page=wp-export-users, nothing is shown anymore. Please help.
~James
]]>Thanks for the plugin – appreciate the utility/simplicity.
I would like to be able to filter the meta_keys array so I can remove certain columns.
]]>Hi
I have also added phone contacts to user information, If you can add any code to export contact / phone information along with other information, it helps a lot
Thanks
]]>Hello,
How I can make it to also export Buddypress Xprofile fields for each user.
Thanks
]]>This is a super handy tool, I would love to have the ability to filter by user role, reorder columns, and relabel columns so it is a bit easier to digest in the export, specifically with user metadata. Currently doing this directly in excel is fairly tedious.
]]>Hi Rajan,
I have used this plugin. the export operation is good but i havn’t found any import alternative. all plugin in wp.org not support the csv format generated by plugin.
Please specifically mention the plugin name, if that helps to import csv file generated by this plugin.
That will be helpful.
Kind Regards
Naveen Giri
But I need to be able to export user metadata. Are you going to include that in the near future?
Thank you.
J
]]>