The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Cannot access lastposterid from within plugin
Hello
I'm attempting to create a plugin that retrieves a user profile field to display on the forum home page. The code is as follows. $lastpostuserid = $lastpostinfo['lastposterid']; /*write custom query here to get display name*/ $lastposter = $db->query_first("SELECT field6 FROM " . TABLE_PREFIX . "userfield WHERE userid = '$lastpostuserid'"); $lastposterhome_var = $lastposter['field6'];*/ /* register variable in the 'memberaction_dropdown' template */ vB_Template:reRegister('memberaction_dropdown',a rray('lastposterhome_var'=> $lastposterhome_var)); The hook I'm using is forumbit_display. The problem is that the value of last $lastpostinfo['lastposterid'] is not available and subsequently I'm not getting a result. The value is available though in the template containing memberaction_dropdown (forumhome_lastpostby). The plugin does work if I assign arbitrary text to my variable just to test. I do have a very similar plugin working on the forum display page which is using the threadbit_display hook and $thread['lastposterid'] I'm quite new to this so any advice would be most welcome. Thanks. Mike |
#2
|
|||
|
|||
It looks like you should be able to use $lastpostinfo['lastposterid'] . Are you sure that's the problem?
|
#3
|
|||
|
|||
Hi
I've just run a check by trying to return the $lastpostinfo['lastposterid'] value directly to the memberaction_dropdown e.g. $lastposterhome_var = $lastpostuserid; I have discovered a value is being returned, as you said it should, but there's an anomalie. The lastposterid is in fact the id of the poster of the last thread in the forum above (this is the forum home page where each forum is listed). The database query was failing because the first forum on the page had no post. Any ideas why the ids are out of sync like this? Thanks. Mike |
#4
|
|||
|
|||
Yeah, the problem might be that $lastpostinfo is an empty array if there is no last thread (a forum is private or doesn't allow posts). So maybe if you do something like:
Code:
if (!empty($lastpostinfo)) { // your code here } |
#5
|
|||
|
|||
Yes, the first forum in the list had no threads. I added your suggested test which did not catch an empty array. I added a thread to the forum which had no affect either. I have also removed the first forum from the list (display order set to zero) but the issue is then transferred to the forum that moves to the top of the list. It appears the first forum in the list has no access to the $lastpostinfo array. Any ideas?
|
#6
|
|||
|
|||
The problem is that the memberaction_dropdown is created before the forumbit_display hook is called (sorry, I should have realized that yesterday). I think you can use the memberaction_dropdown hook, I'm trying to work that out now.
Edit: OK, this seems to work (using hook memberaction_dropdown): Code:
$lastpostuserid = $memberinfo['userid']; /*write custom query here to get display name*/ global $db; $lastposter = $db->query_first("SELECT field6 FROM " . TABLE_PREFIX . "userfield WHERE userid = '$lastpostuserid'"); $lastposterhome_var = $lastposter['field6']; /* register variable in the 'memberaction_dropdown' template */ vB_Template::preRegister('memberaction_dropdown',array('lastposterhome_var'=> $lastposterhome_var)); |
#7
|
|||
|
|||
Thanks but I don't see the hook memberaction_dropdown in the dropdown list of hook locations. Isn't this the name of the template?
|
#8
|
|||
|
|||
It's also a hook location. I had trouble finding it at first too, because it comes before all the "member_" hooks so it kind of looks like it's out of order. It's just after the "mail_" hooks.
|
#9
|
|||
|
|||
I've double checked and it's definately not in the list.
|
#10
|
|||
|
|||
What version are you running? Maybe it was added recently (although I thought I checked a previous version to make sure it was there).
Edit: I checked again and it looks like it's in vb4.1.3 (which is the earliest vb4 version I have the source for). |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|