PDA

View Full Version : Plug-in syntax help


James Birkett
08-21-2009, 04:20 PM
I'm trying to create a nice little plug-in to annoy my forum users (I'm so kind, right?).
Anyway: I am having a little trouble with the code.


if(($user['userid'] != 1) || ($user['userid'] != 2)) {
$user['musername'] = $vbulletin->usergroupcache["$displaygroupid"]['opentag'] . str_shuffle($username) .
$vbulletin->usergroupcache["$displaygroupid"]['closetag'];
}

Basically I want to omit user ID 1 AND 2 from the str_shuffle. So basically ID 3 and onwards gets a shuffled username, whereas IDs 1 and 2 don't.

I am going wrong here:
if(($user['userid'] != 1) || ($user['userid'] != 2)) I just can't get the syntax right to omit both.

Lynne
08-21-2009, 05:03 PM
It would help if you would tell us the plugin location because maybe you are using the wrong variable? Anyway, try this:
if (!in_array($user['userid'], array(1,2))

Adrian Schneider
08-21-2009, 05:07 PM
Use of an array is preferred, but to help you with your original logic:

if userid !=1 and userid != 2

using or means it would always be true

James Birkett
08-21-2009, 05:15 PM
Both methods work fine.
I was using the fetch_musername hook.

Thanks to both of you.

Lynne
08-21-2009, 06:52 PM
Just a word of caution.... watch it when switching usernames around because PMs may be sent to the wrong person. I switched some around a long time ago as an April Fool's joke and things got a bit messed up there. So, be sure to test this out on your test site and make sure it is working how you want it to in regards to profiles/PMs.

James Birkett
08-21-2009, 07:07 PM
I don't think anything on vbulletin uses the markup username does it? I thought it was just for display purposes?
Changing $user['username'] or $username would be stupid indeed. I didn't think markup usernames had anything relying on it in terms of PMs etc..

Lynne
08-21-2009, 08:47 PM
You know, it was four years ago that I did this, so I don't remember the particulars. But I do remember the screwed up PMs. Like I said, test it and see what happens.

James Birkett
08-21-2009, 09:33 PM
PMs and Profiles work fine.

I appreciate the heads up though - thanks Lynne.