Events Made Easy › Forums › How do I … › How modify eme_create_user function
- This topic has 17 replies, 2 voices, and was last updated 2 years, 6 months ago by Franky.
-
AuthorPosts
-
Sun 8 May 2022 at 15:08 #64191AnonymousInactive
Hi Franky
The WP user is created by the eme_create_user function. I would like to modify this function to impose the following format on the display_name and user_nicename:
First name and after a space the first letter of the lastname.
I do this by adding the following 2 lines (2972 and 2973) to eme_functions.php:
2972 display_name’=> $person[‘firstname’] ‘.substr($person[‘lastname’],0,1), 2973 user_nicename’=> $person[‘firstname’].’ ‘.substr($person[‘lastname’],0,1)
But, of course, this is not perennial. Do you have a solution?
Thanks in advance.
FrédéricSun 8 May 2022 at 23:03 #64192FrankyKeymasterThis should help:
https://plugins.trac.wordpress.org/changeset/2720265/events-made-easy/trunk/eme_functions.php
Filter eme_wp_userdata_filter allows you to set extra info for the WP user being created after a booking (if that option is set). The current EME person is given as argument (array), the result should be an array that is accepted by wp_update_user
Tue 10 May 2022 at 07:55 #64193AnonymousInactiveThanks a lot Franky. I was absent yesterday. I’ll look at this
Tue 10 May 2022 at 08:32 #64194FrankyKeymasterI forgot to add: last name and first name are set after the filter (I need those to be the same as in EME), but all the other settings can be changed/set.
Wed 11 May 2022 at 08:37 #64195AnonymousInactiveI think the filter hook will be call eme_wp_userdata_filter but is not yet written ?
Wed 11 May 2022 at 11:11 #64196FrankyKeymasterIn dev of coursen see the changeset I mentioned.
Wed 11 May 2022 at 11:20 #64197AnonymousInactiveI have seen the changeset. But where is define the filter eme_wp_userdata_filter ?
I suppose i have to write it in the function.php of my theme ? and I dont know what filterhook must be chosen ? eme_insert_person_filter ? eme_insert_member_filter ?Wed 11 May 2022 at 11:22 #64198FrankyKeymasterYou need to define the filter eme_wp_userdata_filter (that is the name of the filter you need to create) in your theme/functions.php (or use the plugin “snippets”)
Wed 11 May 2022 at 11:25 #64199AnonymousInactiveWhen I create the filter eme_wp_userdata_filter I have to hook it to an existing hook? and what is it?
Wed 11 May 2022 at 11:37 #64200FrankyKeymasterThat is the name of the filter to hook into. Your own function can be called anything you like, see examples here: https://www.e-dynamics.be/wordpress/category/documentation/12-hooks-and-filters/ (search “add_filter”)
Wed 11 May 2022 at 11:41 #64201AnonymousInactiveWell I did that
“add_filter(’eme_insert_member_filter’,’eme_wp_userdata_filter’);
function eme_wp_userdata_filter(){
$userdata[‘display_name’]=$person[‘firstname’].’ ‘.substr($person[‘lastname’],0,1);
}”but it doesn’t work.
Wed 11 May 2022 at 11:47 #64202FrankyKeymasterThat is not what I said, nor what the examples specify. A simple example (untested, but should work):
add_filter('eme_wp_userdata_filter','eme_my_wp_userdata_function'); function eme_my_wp_userdata_function($person){ $userdata=array(); $userdata['display_name']=$person['firstname'].' '.substr($person['lastname'],0,1); return $userdata; }
Wed 11 May 2022 at 11:51 #64203AnonymousInactiveMy experience with php is poor. I didn’t understand because I couldn’t find it because I thought the eme_wp_userdata_filter hook had to be defined somewhere. So I will test your example. Thanks
Wed 11 May 2022 at 11:59 #64204AnonymousInactiveIt works perfectly. Once again, thank you Franky for your quick support.
Wed 11 May 2022 at 12:03 #64205FrankyKeymasterOk, cool. I’ve already added that to the filter-doc on the site.
Wed 11 May 2022 at 12:46 #64206FrankyKeymasterDon’t forget: if you put it in your theme’s functions.php, it will get removed when upgrading your theme. In fact the snippet plugin is then easier ..
Thu 12 May 2022 at 09:13 #64207AnonymousInactiveDo you think snippet is better than child theme and function.php?
Thu 12 May 2022 at 10:13 #64208FrankyKeymasterI think it is easier to maintain. But if you feel confident with a child theme: go with that, it avoids the use of an extra plugin 🙂
-
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.