We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

New Plug-in: Member Online?

Development and Programming

Nathan Pitman's avatar
Nathan Pitman
531 posts
17 years ago
Nathan Pitman's avatar Nathan Pitman

Whilst working on the Wired In website I came up against a little problem. I wanted to be ale to show if a specific user was online or offline, much like you would on a social networking site. However although there are tags to return a list of online users within Expression Engine, you cannot pass this a specific username with a view to returning a true/false response.

So, after poking around a few plug-ins which queried the DB for values (specifically the ‘Member Info’ plug-in) I decided to launch in and write my first plug-in to do the job for me.

The plug-in is called ‘Member Online?’ and it accepts a ‘username’ for which it will then simply return a true or false value. Using the optional ‘return’ parameter you can specify the values you would like returned in place of true or false.

So, typical usage would be as follows:

{exp:np_memberonline username="{username}" return="Online,Offline"}

You could either use this to simply write a string out into the page, as I am, or use it to change the class of a page element to highlight online users perhaps.

Download: pi.np_memberonline.php.zip

At the moment I’m using this alongside the Solspace ‘User Module’ to build the community aspects of the Wired In website so I’ve only developed it so far as required to meet those requirements. If you have any further ideas as to how the plug-in could be developed do let me know. 😊

       
Danny T.'s avatar
Danny T.
426 posts
17 years ago
Danny T.'s avatar Danny T.

I didn’t understand what you meant by the “class of a page element”.. But would you be able to apply this to a conditional so you can optionally display something if the user was, indeed online?

       
Nathan Pitman's avatar
Nathan Pitman
531 posts
17 years ago
Nathan Pitman's avatar Nathan Pitman

So for example you could do:

<style>
p.on {
    color: green;
}
p.off {
    color: red;
}
</style>
{username}

I’ve not played with using this with conditionals yet, I will take a look at that…

       
Nathan Pitman's avatar
Nathan Pitman
531 posts
17 years ago
Nathan Pitman's avatar Nathan Pitman

Update: Version 1.1 (at the same URL) now performs the same action with one less query thanks to a suggestion from Drew McLellan. 😊

       
Nathan Pitman's avatar
Nathan Pitman
531 posts
17 years ago
Nathan Pitman's avatar Nathan Pitman

Just tried a few things with conditionals, this will work:

{if {exp:np_memberonline username="nathanpitman"}!="true"}Nathan is offline{/if}

Hope that helps!

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
17 years ago
Ingmar Greil's avatar Ingmar Greil

Just cross-referencing 😊

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.