Events Made Easy Forums How do I … How modify eme_create_user function

Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #64191
    Fred17
    Participant

    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éric

    #64192
    Franky
    Keymaster

    This 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

    #64193
    Fred17
    Participant

    Thanks a lot Franky. I was absent yesterday. I’ll look at this

    #64194
    Franky
    Keymaster

    I 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.

    #64195
    Fred17
    Participant

    I think the filter hook will be call eme_wp_userdata_filter but is not yet written ?

    #64196
    Franky
    Keymaster

    In dev of coursen see the changeset I mentioned.

    #64197
    Fred17
    Participant

    I 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 ?

    #64198
    Franky
    Keymaster

    You 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”)

    #64199
    Fred17
    Participant

    When I create the filter eme_wp_userdata_filter I have to hook it to an existing hook? and what is it?

    #64200
    Franky
    Keymaster

    That 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”)

    #64201
    Fred17
    Participant

    Well 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.

    #64202
    Franky
    Keymaster

    That 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;
    }
    
    #64203
    Fred17
    Participant

    My 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

    #64204
    Fred17
    Participant

    It works perfectly. Once again, thank you Franky for your quick support.

    #64205
    Franky
    Keymaster

    Ok, cool. I’ve already added that to the filter-doc on the site.

    #64206
    Franky
    Keymaster

    Don’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 ..

    #64207
    Fred17
    Participant

    Do you think snippet is better than child theme and function.php?

    #64208
    Franky
    Keymaster

    I 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 🙂

Viewing 18 posts - 1 through 18 (of 18 total)
  • You must be logged in to reply to this topic.