<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Matt [Danger] &#187; Drupal</title>
	<atom:link href="http://mattdanger.net/category/php/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattdanger.net</link>
	<description>One step closer to world domination</description>
	<lastBuildDate>Thu, 06 May 2010 21:31:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Programmatically create users in Drupal 6.x</title>
		<link>http://mattdanger.net/2009/12/programmatically-create-users-in-drupal-6-x/</link>
		<comments>http://mattdanger.net/2009/12/programmatically-create-users-in-drupal-6-x/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 02:30:49 +0000</pubDate>
		<dc:creator>Matt Danger</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://mattdanger.net/?p=252</guid>
		<description><![CDATA[You can create a Drupal user by sending user_save() a null parameter and an array of user information. You can also assign a role by setting an array that is keyed with the role ID (rid). This can be obtained by calling user_roles() as shown in the example below.

// Get an array of roles
$roles = [...]]]></description>
			<content:encoded><![CDATA[<p>You can create a Drupal user by sending <code>user_save()</code> a null parameter and an array of user information. You can also assign a role by setting an array that is keyed with the role ID (rid). This can be obtained by calling <code>user_roles()</code> as shown in the example below.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get an array of roles</span>
<span style="color: #000088;">$roles</span> <span style="color: #339933;">=</span> user_roles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Basic account information</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="">'Some User'</span><span style="color: #339933;">,</span>
  <span style="">'pass'</span> <span style="color: #339933;">=&gt;</span> <span style="">'some_password'</span><span style="color: #339933;">,</span>
  <span style="">'mail'</span> <span style="color: #339933;">=&gt;</span> <span style="">'user@example.com'</span><span style="color: #339933;">,</span>
  <span style="">'status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
  <span style="">'init'</span> <span style="color: #339933;">=&gt;</span> <span style="">'user@example.com'</span><span style="color: #339933;">,</span>
  <span style="">'roles'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_search</span><span style="color: #009900;">&#40;</span><span style="">'some_role'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$roles</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// See if the user exists by calling Drupal's user_load()</span>
<span style="color: #000088;">$existing_user</span> <span style="color: #339933;">=</span> user_load<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$existing_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">uid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Save the user</span>
  <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> user_save<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://mattdanger.net/2009/12/programmatically-create-users-in-drupal-6-x/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
