Support Forum
OK - I am now going to probably delight and annoy you at the same time! I am going to recommend a small change to SP core code that will help you and is a reasonable and useful change. That's the good bit. The annoying bit is that it will probably mean you can throw away much of the code we have done so far!
So - first - the SP core code change. I will ensure that this is applied to version 5.1 due out some time next week so you can make this change with that assurance.
Open the file /simple-press/sp-api/sp-api-common-display.php
Locate in that file the function sp_build_name_display() - which is about three-quarters of the way through it.
Immediately after the 'global' statement at the top - add the following line of code:
$username = apply_filters('sph_build_name_display', $username, $userid);
Now comment out ALL of the other filter functions you created earlier. Do NOT delete them yet as you may still need one or two. Now paste in the following code:
global $nameCache; $nameCache = array(); add_filter('sph_user_class_meta', 'sph_addMetatoObj'); function sph_addMetatoObj($objList) { $objList['cortesia'] = 'title'; return $objList; } add_action('sph_user_class', 'sph_insertMetaInDisplayName'); function sph_insertMetaInDisplayName($userObj) { global $nameCache; if(!isset($userObj->ID) || $userObj->ID == 0) return; if(array_key_exists($userObj->ID, $nameCache)) { $userObj->display_name = $nameCache[$userObj->ID]; } else { $name = $userObj->cortesia . $userObj->display_name; $userObj->display_name = $name; $nameCache[$userObj->ID] = $name; } } add_filter('sph_build_name_display', 'sph_insertMetaInBuildName', 1, 2); function sph_insertMetaInBuildName($name, $id) { global $nameCache; if($id == 0) return $name; if(array_key_exists($id, $nameCache)) { return $nameCache[$id]; } else { $name = get_user_meta($id, 'cortesia', True) . $name; $nameCache[$id]=$name; return $name; } }
This worked for me in tests but of course I have had to adapt it to read a usermeta item I do not have so I was unable to test it to 100%.
This should cover 90%+ of what you want. I have also included here an array cache to ensure that each user on any given page only gets processed once - save db reads and extra overhead.
You need to now go back through all display instances to see if they are covered. If not then re-introduce the appropriate code from before but see if you can also build in that cache check.
One area that is NOT covered and may be a real problem is Private Messaging. There is no way that the autocomplete of display names can be changed in this way I am afraid.
Anyway - try this and let me know how it goes. I will be in and out all day.
YELLOW
SWORDFISH
|
Hi Swordfish,
sorry for delay in my answer but I had to drop the project for a couple of days.
Thank you for your efforts, this is definitly an epic support!
I've tryed the new code, actally it covers quite every instance of the Display Name.
There are just a couple of places left:
1) the Name near the avatar on the forum heder (But actually that's not important, or even better witout)
2) on the stats block, last members (I'll clone the function sp_NewMembers)
3) I'm not sure about the Most active members (always on stats block, function sp_TopPostersStats) because it's now empty... I think I have to wait a cron job 😉
You are right, we have 2 false alarms. I'm doing too many things together!
- It's shown near the avatar, I was using an account that actually did not have that meta set
- It's shown on the last members list, just last members as well have not still that meta set
I still cannot see any user on the "most active" list, so I cannot say about that... but it looks like it's everywhere, so I'm quite confident that you're done all, and I'm evidently tired!
most active??
thanks for the update...
Visit Cruise Talk Central and Mr Papa's World
1 Guest(s)