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
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 23, 2012 - 2:22 pm

Yes but I need time for that which I am a little short off at the moment. I will do my best to help.

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

Thank you Swordfish, take your time I'm not in a hurry.

I think this single topic is something like the best support I have ever had! 🙂

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 23, 2012 - 2:43 pm

Actually it is not as difficult as I first thought.

Define a new add-filter and function - just like before - only this one will use the 'sph_groupview_stats_records' filter.

In this case the $objData that will be passed in will have the display name available as:

$objData->display_name

so you will also need the $objData->user_id

So - using the $objData->user_id - go and get hold of the item you need from the userneta table and load it into a variable (say $x)

Then set $objData->display_name = $x . $objData->display_name;

Then return $iobjData at the end of the function as we did before (the line I missed first time round).

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 25, 2012 - 5:14 am

Hi Swordfirsh,

thanks to your tips I've made it! this works on Group View:

add_filter('sph_groupview_stats_records', 'sph_addMetatoGroupViewObj');

function sph_addMetatoGroupViewObj($objData) {
      $cortesiaTitle = get_user_meta($objData->user_id, 'cortesia', True);
      $objData->display_name = $cortesiaTitle . ' '.$objData->display_name;

      return $objData;

}

I must say that is actually easier than the previous one (I do not understand how the 2 add_filter and add_action work together)

Anyway... it seems I have left only "last message from" and "topic started by" on forum view. Could you suggest a further Object to work on?

I tried with just adding the same funciton in a "sph_forumview_stats_records" filter, but it didn't work

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 25, 2012 - 7:09 am

You DO need to use 'sph_forumview_stats_records' but the data items have different names.
In this case you will need to use the following:

$objData->first_user_id
$objData->first_display_name

and

$objData->last_user_id
$objData->last_display_name

However - before you do anything check that $objData->last_user_id exists using:

if(property_exists($objData->last_user_id))

Only perform your trabnsforms if it DOES exist.

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 25, 2012 - 7:34 am

So I've made other 2 filters, one for last_user and one for first_user

add_filter('sph_forumview_stats_records', 'sph_addMetatoLastPostedByForumViewObj');
function sph_addMetatoLastPostedByForumViewObj($objData) {
if(property_exists($objData->last_user_id)){
    $cortesiaTitle = get_user_meta($objData->last_user_id, 'cortesia', True);
    $objData->last_display_name = $cortesiaTitle . ' '.$objData->last_display_name;
}

    return $objData;
}

add_filter('sph_forumview_stats_records', 'sph_addMetatoTopicStartedByForumViewObj');
function sph_addMetatoTopicStartedByForumViewObj($objData) {
if(property_exists($objData->first_user_id)){
    $cortesiaTitle = get_user_meta($objData->first_user_id, 'cortesia', True);
    $objData->first_display_name = $cortesiaTitle . ' '.$objData->first_display_name;
}

    return $objData;
}

but I have errors on the use of property_exist: Wrong parameter count for property_exists()

I've searched for that php function, and it actually needs a second parameter, but I don't understand what to use

SO I've tried using isset instead : if(isset($objData->first_user_id))

and it looks like it's working, but on the  $objData->first_display_name the "cortesia" title is prepend 2 times before display name...odd

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 25, 2012 - 7:44 am

Yes - use isset instead. Probably better.
You should do all of this in just one function. if the last_user_id is set then you have access to all 4 of these data items. That is why you are getting it twice as it was already done first time around.

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 25, 2012 - 7:46 am

Doing in one function is the first thing I've thought as well:

add_filter('sph_forumview_stats_records', 'sph_addMetatoTopicStartedByForumViewObj');

function sph_addMetatoTopicStartedByForumViewObj($objData) {

if(isset($objData->first_user_id)){
    $cortesiaTitle = get_user_meta($objData->first_user_id, 'cortesia', True);
    $objData->first_display_name = $cortesiaTitle . ' '.$objData->first_display_name;
}

if(isset($objData->last_user_id)){
    $cortesiaTitle = get_user_meta($objData->last_user_id, 'cortesia', True);
    $objData->last_display_name = $cortesiaTitle . ' '.$objData->last_display_name;
}

return $objData;
}

But I still have that cortesia twice on "first_display_name"

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 25, 2012 - 7:56 am

You have still not done as I said. Test the last_user_id. Do NOT test the first_user_id. One test - both transforms within the same if statement.

andy-signature.png
YELLOW
SWORDFISH
Avatar
bluantinoo
ITA
Member
Free Members
sp_UserOfflineSmall Offline
May 25, 2012 - 8:15 am

You're right, sorry I've missed that point.

this works 🙂

add_filter('sph_forumview_stats_records', 'sph_addMetatoForumViewObj');

function sph_addMetatoForumViewObj($objData) {

if(isset($objData->last_user_id)){
    $cortesiaTitle = get_user_meta($objData->last_user_id, 'cortesia', True);
    $objData->last_display_name = $cortesiaTitle . ' '.$objData->last_display_name;
    
    $cortesiaTitle2 = get_user_meta($objData->first_user_id, 'cortesia', True);
    $objData->first_display_name = $cortesiaTitle2 . ' '.$objData->first_display_name;
}

return $objData;
}

Thank you very much for our patience

Let me ask just one last question about this.

Wandering in sp files I've found sp-api-filters.php that contains sp_filter_name_display function.

would not be quicker to filter just that?

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: 617
Members: 17359
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10125
Posts: 79620