PluginProbe
Flamingo / trunk
Flamingo vtrunk
2.6.4 2.6.3 2.6.2 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.1.1 2.2 All 33 releases
flamingo / includes / user.php

user.php in Flamingo trunk, at includes/user.php

69 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Module for WordPress users handling
4 */
5
6
7 add_action( 'profile_update', 'flamingo_user_profile_update', 10, 1 );
8 add_action( 'user_register', 'flamingo_user_profile_update', 10, 1 );
9
10 /**
11 * Creates a Flamingo_Contact record for the given user.
12 */
13 function flamingo_user_profile_update( $user_id ) {
14 $user = new WP_User( $user_id );
15
16 $email = $user->user_email;
17 $name = $user->display_name;
18
19 $props = array(
20 'first_name' => $user->first_name,
21 'last_name' => $user->last_name,
22 );
23
24 if ( ! empty( $email ) ) {
25 Flamingo_Contact::add( array(
26 'email' => $email,
27 'name' => $name,
28 'props' => $props,
29 'channel' => 'user',
30 ) );
31 }
32 }
33
34
35 add_action( 'activate_' . FLAMINGO_PLUGIN_BASENAME,
36 'flamingo_collect_contacts_from_users',
37 10, 0
38 );
39
40 /**
41 * Creates Flamingo_Contact records for existing users.
42 */
43 function flamingo_collect_contacts_from_users() {
44 $users = get_users( array(
45 'number' => 20,
46 ) );
47
48 foreach ( $users as $user ) {
49 $email = $user->user_email;
50 $name = $user->display_name;
51
52 if ( empty( $email ) ) {
53 continue;
54 }
55
56 $props = array(
57 'first_name' => empty( $user->first_name ) ? '' : $user->first_name,
58 'last_name' => empty( $user->last_name ) ? '' : $user->last_name,
59 );
60
61 Flamingo_Contact::add( array(
62 'email' => $email,
63 'name' => $name,
64 'props' => $props,
65 'channel' => 'user',
66 ) );
67 }
68 }
69