Custom field
-
Hi,
First thanks for your plugin, it works great.
I would like to use the plugin for an intranet and il would like to get the phone value from AD to create the value in budypress.
Is this possible to do ?
-
Currently, no. but that doesn’t mean we can’t add something. I could add a filter after the user creation process that you could hook into and grab the phone number.
the filter could pass you the UserID, and the full record returned for the user from ldap_get_entries(). Have you ever dealt with ldap records in PHP?
just following up again. Would providing you with a filter you could hook into work for your situation? If so, I’ll send you a version you can test. if it works, i’ll incorporate those changes into the next version of the plugin.
Hi thanks for your fast answer !
No i never dealed with ldap records in PHP.
The field i want to get is the field “telephoneNumber”.
I will be happy to test the new version and to tell you if it works.Sorry it took a little bit. There were a couple of sections I wanted to refactor to make all of this work more smoothly. If you’ve never dealt with ldap search results, it can be a bit… frustrating. It’s a multi-dimensional nested array. I’ve included a sample of what it looks like at the bottom of this post. The PHP Documentation will help as well.
Beta version for you to test: https://gist.github.com/gilzow/a051e5ace829c9b1e99d37d7f25a800c
There are now 2 actions and 1 filter you can hook into:
Filter
wpdirauth_ldapreturnkeys
Fires before making an ldap_search. Will pass your function a single argument: an array of extra keys that should be included in the ldap return. Your function should add to this array and then return the array.Example:
add_filter('wpdirauth_ldapreturnkeys',function($aryKeys){ $myKeys = array('department','telephoneNumber'); return array_merge($aryKeys,$myKeys); },10,1);
Actions:
wpdirauth_usercreated
Fires right after a new AD-authenticated user has been created in WordPress. This occurs either right after an ad-authed user has authenticated and Auto Register is enabled in the plugin, or when adding an AD-authenticated user from the Users panel. Will pass your function two parameters: WordPress User ID and an array of user details (see example below). One key in the array will be ldap_entry and will be the search result from the ldap search. Function does not need to return a value.Example:
/** * Add an AD-authenticated user's department and phone number to their WordPress User meta data */ add_action('wpdirauth_usercreated',function($intUserID,$aryUserDetails){ if(isset($aryUserDetails['ldap_entry']['telephonenumber'][0]) && '' != $aryUserDetails['ldap_entry']['telephonenumber'][0] ){ add_user_meta($intUserID,'telephone',$aryUserDetails['ldap_entry']['telephonenumber'][0]); } if(isset($aryUserDetails['ldap_entry']['department'][0]) && '' != $aryUserDetails['ldap_entry']['department'][0] ){ add_user_meta($intUserID,'department',$aryUserDetails['ldap_entry']['department'][0]); } },10,2);
wpdirauth_userauthenticated
Fires right after an ad-authenticated user has authenticated. Will pass your function two parameters: WordPress User ID, and an array of user details (see example below). One key in the array will be ldap_entry and will be the search result from the ldap search. Function does not need to return a value.Example:
/** * Update a user's phone number if they've updated it in AD, or add it here if they've added it in AD */ add_action('wpdirauth_userauthenticated',function($intUserID,$aryUserDetails){ $strOldPhone = get_user_meta($intUserID,'telephone',true); if(isset($aryUserDetails['ldap_entry']['telephonenumber'][0]) && '' != $aryUserDetails['ldap_entry']['telephonenumber'][0] ){ if($strOldPhone != $aryUserDetails['ldap_entry']['telephonenumber'][0]){ update_user_meta($intUserID,'telephone',$aryUserDetails['ldap_entry']['telephonenumber'][0],$strOldPhone); } } },10,2);
Example of user details array
array ( 'email' => '[email protected]', 'last_name' => 'Gilzow', 'first_name' => 'Paul', 'ldap_entry' => array ( 'sn' => array ( 'count' => 1, 0 => 'Gilzow', ), 0 => 'sn', 'telephonenumber' => array ( 'count' => 1, 0 => '(555) 555-1212', ), 1 => 'telephonenumber', 'givenname' => array ( 'count' => 1, 0 => 'Paul', ), 2 => 'givenname', 'department' => array ( 'count' => 1, 0 => 'Some Department', ), 3 => 'department', 'mail' => array ( 'count' => 1, 0 => '[email protected]', ), 4 => 'mail', 'count' => 5, 'dn' => 'CN=Gilzow\\, Paul,CN=Users,DC=domain,DC=tld', ), )
-
This reply was modified 7 years, 10 months ago by
Paul Gilzow. Reason: left my email address in there. doh
WordPress forums keep eating my replies. Let’s break this into a couple of replies.
Sorry it took a little bit. There were a couple of sections I wanted to refactor to make all of this work more smoothly. If you’ve never dealt with ldap search results, it can be a bit… frustrating. It’s a multi-dimensional nested array. I’ve included a sample of what it looks like at the bottom of this post. The PHP Documentation will help as well.
Beta version for you to test: https://gist.github.com/gilzow/a051e5ace829c9b1e99d37d7f25a800c
There are now 2 actions and 1 filter you can hook into:
Filter
wpdirauth_ldapreturnkeys
Fires before making an ldap_search. Will pass your function a single argument: an array of extra keys that should be included in the ldap return. Your function should add to this array and then return the array.Example:
add_filter('wpdirauth_ldapreturnkeys',function($aryKeys){ $myKeys = array('department','telephoneNumber'); return array_merge($aryKeys,$myKeys); },10,1);
Actions:
wpdirauth_usercreated
Fires right after a new AD-authenticated user has been created in WordPress. This occurs either right after an ad-authed user has authenticated and Auto Register is enabled in the plugin, or when adding an AD-authenticated user from the Users panel. Will pass your function two parameters: WordPress User ID and an array of user details (see example below). One key in the array will be ldap_entry and will be the search result from the ldap search. Function does not need to return a value.Example:
/** * Add an AD-authenticated user's department and phone number to their WordPress User meta data */ add_action('wpdirauth_usercreated',function($intUserID,$aryUserDetails){ if(isset($aryUserDetails['ldap_entry']['telephonenumber'][0]) && '' != $aryUserDetails['ldap_entry']['telephonenumber'][0] ){ add_user_meta($intUserID,'telephone',$aryUserDetails['ldap_entry']['telephonenumber'][0]); } if(isset($aryUserDetails['ldap_entry']['department'][0]) && '' != $aryUserDetails['ldap_entry']['department'][0] ){ add_user_meta($intUserID,'department',$aryUserDetails['ldap_entry']['department'][0]); } },10,2);
wpdirauth_userauthenticated
Fires right after an ad-authenticated user has authenticated. Will pass your function two parameters: WordPress User ID, and an array of user details (see example below). One key in the array will be ldap_entry and will be the search result from the ldap search. Function does not need to return a value.Example:
/** * Update a user's phone number if they've updated it in AD, or add it here if they've added it in AD */ add_action('wpdirauth_userauthenticated',function($intUserID,$aryUserDetails){ $strOldPhone = get_user_meta($intUserID,'telephone',true); if(isset($aryUserDetails['ldap_entry']['telephonenumber'][0]) && '' != $aryUserDetails['ldap_entry']['telephonenumber'][0] ){ if($strOldPhone != $aryUserDetails['ldap_entry']['telephonenumber'][0]){ update_user_meta($intUserID,'telephone',$aryUserDetails['ldap_entry']['telephonenumber'][0],$strOldPhone); } } },10,2);
Example of user details array
array ( 'email' => '[email protected]', 'last_name' => 'Gilzow', 'first_name' => 'Paul', 'ldap_entry' => array ( 'sn' => array ( 'count' => 1, 0 => 'Gilzow', ), 0 => 'sn', 'telephonenumber' => array ( 'count' => 1, 0 => '(555) 555-1212', ), 1 => 'telephonenumber', 'givenname' => array ( 'count' => 1, 0 => 'Paul', ), 2 => 'givenname', 'department' => array ( 'count' => 1, 0 => 'Some Department', ), 3 => 'department', 'mail' => array ( 'count' => 1, 0 => '[email protected]’, ), 4 => 'mail', 'count' => 5, 'dn' => 'CN=Gilzow\\, Paul,CN=Users,DC=domain,DC=tld', ), )
Nice additions Paul – could be very useful ??
thanks! i’m actually really excited about it as it gives me the ability to make plugins that extend wpDirAuth’s functionality without having to build in excess complexity into wpDirAuth.
Thanks, i will test that as soon as i have a little time.
another updated version if you can test. Same functionality as the version you are testing, but i’ve also added ability to change cookie expiration times as well as a couple of other bug fixes.
https://gist.github.com/gilzow/febf6c36fd46dd24dba7b2bbbbd7c375
-
This reply was modified 7 years, 10 months ago by
Paul Gilzow. Reason: actually include the link
version 1.9.3 is now out with all of the above hooks (actions+filter) baked in. If you can, test and let me know if this addresses your issue.
-
This reply was modified 7 years, 10 months ago by
- The topic ‘Custom field’ is closed to new replies.