@@ -164,6 +164,7 @@ public function action_init() {
164
164
'SITE_TITLE ' => get_bloginfo ( 'name ' ),
165
165
'COOL_MODE ' => (bool ) $ this ->get_cool_mode_filtered (),
166
166
'NETWORK ' => esc_textarea ( $ this ->get_infura_network_filtered () ),
167
+ 'ATTRIBUTES ' => $ this ->get_frontend_attributes (),
167
168
]
168
169
);
169
170
wp_localize_script (
@@ -180,10 +181,66 @@ public function action_init() {
180
181
'LOGOUT_URL ' => wp_logout_url (),
181
182
'COOL_MODE ' => (bool ) $ this ->get_cool_mode_filtered (),
182
183
'NETWORK ' => esc_textarea ( $ this ->get_infura_network_filtered () ),
184
+ 'ATTRIBUTES ' => $ this ->get_frontend_attributes (),
183
185
]
184
186
);
185
187
}
186
188
189
+ /**
190
+ * Get a parsed version of filtered user attributes mapping.
191
+ */
192
+ public function get_parsed_user_attributes_mapping () {
193
+ $ csv = explode ( "\n" , $ this ->get_user_attributes_mapping_filtered () );
194
+
195
+ return array_map (
196
+ function ( $ row ) {
197
+ return explode ( ', ' , $ row );
198
+ },
199
+ $ csv
200
+ );
201
+ }
202
+
203
+ /**
204
+ * Get and parse use attributes for frontend.
205
+ *
206
+ * @return array Attributes for frontend
207
+ */
208
+ public function get_frontend_attributes () {
209
+ return array_reduce (
210
+ $ this ->get_parsed_user_attributes_mapping (),
211
+ function ( $ agg , $ item ) {
212
+ if ( ! empty ( $ item ) && ! empty ( $ item [0 ] ) ) {
213
+ $ agg [] = $ item [0 ];
214
+ }
215
+
216
+ return $ agg ;
217
+ },
218
+ []
219
+ );
220
+ }
221
+
222
+ /**
223
+ * Provide filter for user attributes mapping.
224
+ *
225
+ * @return array Filtered user attributes mapping
226
+ */
227
+ public function get_user_attributes_mapping_filtered () {
228
+ $ options = get_option (
229
+ 'wp_rainbow_options ' ,
230
+ [
231
+ 'wp_rainbow_field_user_attributes_mapping ' =>
232
+ 'url,user_url ' ,
233
+ ]
234
+ );
235
+
236
+ /**
237
+ * Filter the user attributes mapping for WP Rainbow users.
238
+ *
239
+ * @param array $default Default user attributes mapping.
240
+ */
241
+ return apply_filters ( 'wp_rainbow_user_attributes_mapping ' , $ options ['wp_rainbow_field_user_attributes_mapping ' ] ?? '' );
242
+ }
243
+
187
244
// LOGIN SCRIPTS.
188
245
189
246
/**
@@ -219,6 +276,7 @@ public function action_login_enqueue_scripts() {
219
276
'SITE_TITLE ' => get_bloginfo ( 'name ' ),
220
277
'COOL_MODE ' => (bool ) $ this ->get_cool_mode_filtered (),
221
278
'NETWORK ' => esc_textarea ( $ this ->get_infura_network_filtered () ),
279
+ 'ATTRIBUTES ' => $ this ->get_frontend_attributes (),
222
280
]
223
281
);
224
282
}
0 commit comments