0

Im working on a simple plugin that just needs to get the current logged users screen name, email address and username into some javascript and inject that js on every page.

My hope is to juse the exiwting CP CSS & JS plugin and past the javascript..

I found the EE global variable in the javascript and it looks like EE.username is the current logged in users name. Is there similar way to get email and/or screen name?

1 Answer 1

1

The EE global only has username and shouldn't be relied upon as it's not a formal documented method to get information (and so could change or be manipulated).

If you're already writing a module/extension (a "plugin" is frontend only), then output your JavaScript from there instead of relying on the "CP CSS & JS" extension.

You can access all the user information via the session class:

ee()->session->userdata['screen_name'];
ee()->session->userdata['email'];
ee()->session->userdata['username'];

Add your own external JS file:

ee()->add_js_script('file', 'insert filename here');

The Docs on the CP class can be found here. Full Developer documentation here.

Consider using an Extension hook to inject your javascript - this would probably be the easiest route.

Note: These classes are automatically available from within your module/extension and don't have to be loaded.

Your Answer

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

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