Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
How to filter Forum Display Name?
Avatar
bluantinoo
ITA
Member
Free Members
Offline
May 17, 2012 - 11:36 am

Helllo,

I need to filter user's names to show a title before name.

I already have this info as a wp usermeta.

I've opened the spTopicView.php template, where I can find, for example, the author post column: sp_PostIndexUserName('tagClass=spPostUserName spCenter');

but I'm not able to create a filter to alter that function.

----

Same problem trying to show custom profile fields. I've found this topic https://simple-press.com/suppo.....-fields-4/ where Mr Papa tells how to show a custom profile field with sp_CustomProfileFieldsDisplay($name, $userid);

but how do I get the $userid in forum loops?

Avatar
bluantinoo
ITA
Member
Free Members
Offline
May 17, 2012 - 12:13 pm

I'm answering myself to the second question:

How to get user id inside Simple Press Post Loop?

This way: $spThisPostUser->ID

please correct me if I'm wrong.

 

But I still need to filter forum display name adding a title (Prof, Doc, Mr., etc...) before the name.

Is there a way to do this on forum display name or do I need to add this manually on template files?

Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
May 17, 2012 - 12:36 pm

Let's ask something else first. Are you wanting to do this everywhere the display name is used? because that can be a LOT of places... Or are we talking about very specific places?

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
Offline
May 17, 2012 - 1:51 pm

I know it's a lot of places we are talking about.

is for that I'm looking for a filter, because I need that title to be always before display name (if that field is set, obviously)

I asked about the $spThisPostUser just because it was a related issue that I was supposing quick to answer

Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
May 17, 2012 - 2:19 pm

OK. so confirm for me. This item of data is in the usermeta table? Correct?
Give me a little time to think abiyut this because there may be a better way.

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
Offline
May 17, 2012 - 2:28 pm

Yes is a usermeta that I've already asked in wp profile to users.

but if it becomes too difficult I can even ask it again in the forum profile, I do not want to edit SP core files.

Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
May 17, 2012 - 2:39 pm

Do you know how to use and code for WP filters?

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
Offline
May 17, 2012 - 2:45 pm

Not very well, but I can try if you give me some hint I'm not scared to study wp codex

Avatar
Yellow Swordfish
Glinton, England
SP Master
Offline
May 17, 2012 - 3:27 pm

Ok Try this. bear in miund I have not really tested this myself!

add_filter('sph_user_class_meta', 'function1');
function function1($objList) {
    $objList['XXX'] = 'title';
}

add_action('sph_user_class', 'function2');
function function2($userObj) {
    $userObj->display_name = $userObj->XXX . $userObj->display_name;
}

Change 'function1' and 'function2' for your own function names in both the add filter/action calls and in the small functions themselves.

Change the 2 instances of XXX for the NAME of the meta item in the usermeta table.

And this code is probably best placed in the spFunctions.php file of the SP theme.

If this works it isn't going to change every instance but it should change quite a lot of them.

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
Offline
May 17, 2012 - 4:30 pm

I'm having some troubles.

I've followed yourvery clear instructions, but maybe I'm done something wrong.

this is what I've pasted in the spFunctions.php of my SP theme

add_filter('sph_user_class_meta', 'sph_addMetatoObj');
function sph_addMetatoObj($objList) {
    $objList['cortesia'] = 'title';
}

add_action('sph_user_class', 'sph_insertMetaInDisplayBame');
function sph_insertMetaInDisplayBame($userObj) {
    $userObj->display_name = $userObj->cortesia . $userObj->display_name;
}

I'm having 3 different error messages, first two repeats a lot of times and the page looks like hanging in an infinite loop, at the end loads the third message and the whole site (without the meta before the names)

Theese are the 3 errors:

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /web/problem-with-post-edit-buttontdocs/www.[...]/wp-content/plugins/simple-press/sp-api/sp-api-class-user.php on line 131

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /web/problem-with-post-edit-buttontdocs/www.[...]/wp-content/plugins/simple-press/sp-api/sp-api-class-user.php on line 142

Warning: Invalid argument supplied for foreach() in /web/problem-with-post-edit-buttontdocs/www.sviluppointergraf.it/problem-with-post-edit-buttonome/[...]/wp-content/plugins/simple-press/sp-api/sp-api-class-user.php on line 294

(I've added the [...] to hide real URL)

THis happens in forum home, forum view and topic view

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626