3

Ok then Joomla Masters, Fasten your seat belts!

It's quite complex but I will try my best to elaborate my goal.

I want to make a custom page which will only be accessible to the Registered users of my Joomla Website but I want it to display different elements to different users. Here's an example :

Supposition : Two Registered Users (User1 and User2)

When User1 opens the custom page, it should display the text "ABC"

&

When User2 opens the same custom page, it should display the text "XYZ"

But, the catch is I should able to edit that page for any particular user. I mean, i should be able to show any particular user, the stuff i want to.

Is there any body to help me out and push the limitations of Joomla user management to a next level?

4
  • When you say custom page, do you mean an external php page that isn't a standard article? And when you say I should able to edit that page, do you mean you as an administrator? And edit it how, via the article manager? which leads me back to my first question
    – Lodder
    May 22, 2014 at 13:52
  • Well, as far as i know, it will require PHP! which my editor doesn't allow to save in an article, so surely i will prefer an EXTERNAL PHP Page. Ya, only i should be able to edit it. Just like $user->username returns the username of the logged in user, i want some kind of script which when detects a specific logged in user should execute a specific code for that user only, is that possible?
    – saibbyweb
    May 22, 2014 at 13:57
  • If you want to use PHP within an article, then have a look at this: nonumber.nl/extensions/sourcerer
    – Lodder
    May 22, 2014 at 13:59
  • ok fine, i will do that but i want the code! That's why i posted this question! Remember?
    – saibbyweb
    May 22, 2014 at 14:00

3 Answers 3

4
I want some kind of script which when detects a specific logged in user should execute a specific code for that user only, is that possible?

You can use something like this:

$user = JFactory::getUser();

if( $user->username == 'Saibbyweb' )
{
     // code for Saibbyweb
}
elseif( $user->username == 'Lodder' ) 
{
    // code for Lodder
}
else 
{
    // else just some standard stuff
}
4
  • has anybody told you that you're awesome! Worked like a charm! Thanks, aton!
    – saibbyweb
    May 22, 2014 at 14:12
  • It's been mentioned a few times :P ... you're welcome :)
    – Lodder
    May 22, 2014 at 14:15
  • It's better if you compare ids and not usernames, since the latter can change.
    – mattosmat
    May 8, 2015 at 14:00
  • @mattosmat - Yes, please write an answer as you make a good point
    – Lodder
    May 8, 2015 at 14:01
3

Lodder's answer is great, but it might be better if you compare ids and not usernames, since the latter can change.

Try this:

$user = JFactory::getUser();

if( $user->id == 32 ) // Saibbyweb's
{
     // code for Saibbyweb
}
elseif( $user->id == 15 ) // Lodder's id
{
    // code for Lodder
}
else 
{
    // else just some standard stuff
}
1

You can use the core profile plugin to do this. Here is a Tutorial for Joomla2.5 to create a plugin to adding custom user profile fields. You can adapt this tutorial for Joomla 3.3.0, too.

http://www.inmotionhosting.com/support/edu/joomla-25/user-profile/copy-user-profile-plugin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.