Export all users as a JSON object


/**
 * Implements hook_menu().
 */
function MYMODULE_export_menu() {
  $items = array();
  
  $items['export-users'] = array(
    'title' => 'Export users',
    'description' => 'Export users',
    'page callback' => '_export_users',
    'page arguments' => array(1),
    'access callback' => true,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/**
 * Export users.
 *
 */
function _export_users() {

  drupal_set_time_limit(0);

  $uids = db_select('users', 'u')
  ->fields('u', array('uid'))
  ->execute()
  ->fetchCol();

  $users = user_load_multiple($uids);
 
  $users = json_encode($users);

  drupal_add_http_header('Content-Type','text/plain; charset=UTF-8');

  print($users);

}

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.