1: <?php
2:
3: global $bright_update_user_meta;
4:
5: function bright_log($message,$doecho=false) {
6: $trace=debug_backtrace();
7: $c=$trace[1];
8: if (isset($c['class']))
9: $caller = $c['class'] . '::' . $c['function'];
10: else
11: $caller = $c['function'];
12:
13: $caller .= ' - ';
14:
15: if ($doecho)
16: if ( is_array($message) || is_object($message) )
17: echo var_dump("{$caller}{$message}");
18: else
19: echo "<pre class=\"xdebug-var-dump\">{$caller}{$message}</pre>";
20: if ( WP_DEBUG === true ) {
21: if ( is_array($message) || is_object($message) )
22: error_log( $caller .print_r($message, true) );
23: else
24: error_log( $caller . $message );
25: }
26: }
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50: function bright_update_all_users($args) {
51: $skiptoday = $args['skip-today'];
52: $max_records = $args['max-records'];
53:
54: global $wpdb;
55: $sql = "SELECT ID, user_email FROM " . $wpdb->prefix . "users";
56: $myrows = $wpdb->get_results($sql);
57:
58: global $bright_curl_error;
59: $today = date("d-m-Y");
60: $recno = 0;
61: foreach ( $myrows as $user ) {
62:
63: $current = get_user_meta($user->ID, 'bright-last-fullsync',true);
64: if (!empty($skiptoday) && $current === $today) {
65: echo "Skipped Bright User MetaData for {$user->user_email} {$bright_curl_error}<br/>";
66: next;
67: } else {
68: echo "Updated Bright User MetaData for {$user->user_email} {$bright_curl_error}<br/>";
69: bright_update_user_meta('id',$user->ID);
70: if(! isset($bright_curl_error))
71: add_user_meta($user->ID, 'bright-last-fullsync',$today,true) || update_user_meta($user->ID, 'bright-last-fullsync',$today);
72: $recno++;
73: if (!empty($max_records) && $recno >= $max_records)
74: break;
75: }
76: }
77: }
78:
79: function bright_update_user_meta($field,$learner) {
80: $current_user = ($field === "bright_user") ? $learner : get_user_by($field,$learner);
81: if (!empty($current_user)){
82: bright_log('updating user meta for '. $current_user->user_email);
83: Bright::realm_user_gcustom($current_user->user_email,bright_fetch_user_attributes($current_user));
84: } else {
85: echo '<span class="error">skipping null record for {$id} {$learner}</span><br/>';
86: }
87: }
88:
89: add_action( 'profile_update', 'bright_update_realmuser_meta', PHP_INT_MAX, 2 );
90:
91: function bright_update_realmuser_meta( $user_id, $old_user_data) {
92: bright_log("in function bright_update_realmuser_meta (profile_update)");
93: bright_update_user_meta("id",$user_id);
94: }
95:
96:
97:
98:
99:
100:
101:
102:
103:
104: