summaryrefslogtreecommitdiffstats
path: root/modules/core/docs/authproc_php.md
blob: 66968eda1a7b9853c2a3b9eafacb784cd7e0d79b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
`core:PHP`
==========

This is a filter which makes it possible to run arbitrary PHP code to modify the attributes of an user.

Parameters
----------

`class`
:   This is the name of the filter.
    It must be `'core:PHP'`.

`code`
:   The PHP code that should be run. This code will have only one variable available: `$attributes`.
    This is an associative array of attributes, and can be modified to add or remove attributes.

Examples
--------

Add the `mail` attribute based on the user's `uid` attribute:

    10 => array(
        'class' => 'core:PHP',
        'code' => '
            if (empty($attributes["uid"])) {
                throw new Exception("Missing uid attribute.");
            }

            $uid = $attributes["uid"][0];
            $mail = $uid . "@example.net";
            $attributes["mail"] = array($mail);
        ',
    ),


Create a random number variable:

    10 => array(
        'class' => 'core:PHP',
        'code' => '
            $attributes["random"] = array(
                (string)rand(),
            );
        ',
    ),