Most of these configuration settings tend to be controlled by a variable, so Drupal uses variable_get()
and variable_set()
to retrieve and modify these values.
To find out the variable name and value you can have a look at the source page. For example:
<label for="edit-user-register">Who can register accounts? </label>
<div id="edit-user-register" class="form-radios">
<input type="radio" id="edit-user-register-0" name="user_register" value="0" class="form-radio">
<label class="option" for="edit-user-register-0">Administrators only </label>
<input type="radio" id="edit-user-register-1" name="user_register" value="1" class="form-radio">
<label class="option" for="edit-user-register-1">Visitors </label>
<input type="radio" id="edit-user-register-2" name="user_register" value="2" checked="checked" class="form-radio">
<label class="option" for="edit-user-register-2">Visitors, but administrator approval is required </label>
</div>
Here you can see that in order to change the "Who can register accounts?" option, you need to change the value of the user_register
variable. You can set it to 1
for visitors, so putting this code in your module will do the trick:
variable_set('user_register', 1);
Of course, this is if you're too lazy to open the source code :) . The other way is to find out which callback generates this form, and inspect user.module
:
function user_menu() {
//snip...
$items['admin/config/people/accounts'] = array(
'title' => 'Account settings',
'description' => 'Configure default behavior of users, including registration requirements, e-mails, fields, and user pictures.',
'page callback' => 'drupal_get_form',
'page arguments' => array('user_admin_settings'),
'access arguments' => array('administer users'),
'file' => 'user.admin.inc',
'weight' => -10,
);
Then find the callback function user_admin_settings()
in user.admin.inc
:
$form['registration_cancellation']['user_register'] = array(
'#type' => 'radios',
'#title' => t('Who can register accounts?'),
'#default_value' => variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL),
'#options' => array(
USER_REGISTER_ADMINISTRATORS_ONLY => t('Administrators only'),
USER_REGISTER_VISITORS => t('Visitors'),
USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => t('Visitors, but administrator approval is required'),
),
);
So there you have your variable and in fact there's some constant to set up the values: USER_REGISTER_VISITORS
.