Support Forum
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).
YELLOW
SWORDFISH
|
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
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.
YELLOW
SWORDFISH
|
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
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"
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?
1 Guest(s)