1 | <?php |
||
3 | class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { |
||
4 | function name() { |
||
7 | |||
8 | public function init_listeners( $callable ) { |
||
36 | |||
37 | public function init_before_send() { |
||
38 | add_filter( 'jetpack_sync_before_send_jetpack_sync_save_user', array( $this, 'expand_user' ) ); |
||
39 | add_filter( 'jetpack_sync_before_send_wp_login', array( $this, 'expand_login_username' ), 10, 2 ); |
||
40 | add_filter( 'jetpack_sync_before_send_wp_logout', array( $this, 'expand_logout_username' ), 10, 2 ); |
||
41 | |||
42 | // full sync |
||
43 | add_filter( 'jetpack_sync_before_send_jetpack_full_sync_users', array( $this, 'expand_users' ) ); |
||
44 | } |
||
45 | |||
46 | public function sanitize_user_and_expand( $user ) { |
||
47 | $user = $this->sanitize_user( $user ); |
||
48 | |||
49 | return $this->add_to_user( $user ); |
||
50 | } |
||
51 | |||
52 | public function sanitize_user( $user ) { |
||
53 | unset( $user->data->user_pass ); |
||
54 | |||
55 | return $user; |
||
56 | } |
||
57 | |||
58 | public function add_to_user( $user ) { |
||
59 | $user->allowed_mime_types = get_allowed_mime_types( $user ); |
||
60 | |||
61 | return $user; |
||
62 | } |
||
63 | |||
64 | public function expand_user( $args ) { |
||
65 | list( $user ) = $args; |
||
66 | |||
67 | return array( $this->add_to_user( $user ) ); |
||
68 | } |
||
69 | |||
70 | public function expand_login_username( $args ) { |
||
71 | list( $login, $user ) = $args; |
||
72 | $user = $this->sanitize_user( $user ); |
||
73 | |||
74 | return array( $login, $user ); |
||
75 | } |
||
76 | |||
77 | public function expand_logout_username( $args, $user_id ) { |
||
78 | $user = get_userdata( $user_id ); |
||
79 | $user = $this->sanitize_user( $user ); |
||
80 | $login = $user->data->user_login; |
||
81 | |||
82 | return array( $login, $user ); |
||
83 | } |
||
84 | |||
85 | function save_user_handler( $user_id, $old_user_data = null ) { |
||
116 | |||
117 | function save_user_role_handler( $user_id, $role, $old_roles = null ) { |
||
118 | $user = $this->sanitize_user( get_user_by( 'id', $user_id ) ); |
||
119 | |||
120 | /** |
||
121 | * Fires when the client needs to sync an updated user |
||
122 | * |
||
123 | * @since 4.2.0 |
||
124 | * |
||
125 | * @param object The WP_User object |
||
126 | */ |
||
127 | do_action( 'jetpack_sync_save_user', $user ); |
||
128 | } |
||
129 | |||
130 | function save_user_cap_handler( $meta_id, $user_id, $meta_key, $capabilities ) { |
||
131 | |||
132 | // if a user is currently being removed as a member of this blog, we don't fire the event |
||
133 | if ( current_filter() === 'deleted_user_meta' |
||
134 | && |
||
135 | preg_match( '/capabilities|user_level/', $meta_key ) |
||
136 | && |
||
137 | ! is_user_member_of_blog( $user_id, get_current_blog_id() ) |
||
138 | ) { |
||
139 | return; |
||
140 | } |
||
141 | |||
142 | $user = $this->sanitize_user( get_user_by( 'id', $user_id ) ); |
||
143 | if ( $meta_key === $user->cap_key ) { |
||
144 | /** |
||
145 | * Fires when the client needs to sync an updated user |
||
146 | * |
||
147 | * @since 4.2.0 |
||
148 | * |
||
149 | * @param object The WP_User object |
||
150 | */ |
||
151 | do_action( 'jetpack_sync_save_user', $user ); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | public function enqueue_full_sync_actions() { |
||
156 | global $wpdb; |
||
157 | |||
158 | return $this->enqueue_all_ids_as_action( 'jetpack_full_sync_users', $wpdb->users, 'ID', null ); |
||
159 | } |
||
160 | |||
161 | function get_full_sync_actions() { |
||
164 | |||
165 | public function expand_users( $args ) { |
||
166 | $user_ids = $args[0]; |
||
167 | |||
168 | return array_map( array( $this, 'sanitize_user_and_expand' ), get_users( array( 'include' => $user_ids ) ) ); |
||
169 | } |
||
170 | } |
||
171 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.