Posts: 25
Threads: 5
Joined: Jul 2014
2014-07-11, 07:17:11
(This post was last modified: 2014-07-17, 08:20:41 by lukinhasb.)
How can I get the admin e-mail inside a plugin php?
The same entered during install, and seen on Settings
Thanks.
-- Edit --
If someone looks for this function on the future, here it is:
PHP Code: /* * Return email of the first GS user found * @return string */
function simple_c_default_email() { $files = scandir(GSUSERSPATH); foreach ($files as $filename) { if (preg_match("#\.xml$#", $filename)) { $data = getXML(GSUSERSPATH . $filename); return $data->EMAIL; } } return ""; }
This function is from Simple ©ontact plugin: http://get-simple.info/forums/showthread...7#pid44287
Posts: 32
Threads: 8
Joined: Jul 2014
This data is stored in /data/users/admin.xml so you can pull the email address from there.
Posts: 25
Threads: 5
Joined: Jul 2014
2014-07-11, 22:59:45
(This post was last modified: 2014-07-11, 23:19:16 by lukinhasb.)
Yes, but the name of the file is dynamic, the username isn't necessarily "admin"
I was trying something like this:
PHP Code: function admin_email() { $admin_file = scandir(GSUSERSPATH, 1); $data = getXML($admin_file[0]); return $data->EMAIL; }
$xml->addChild('RECIPIENT_EMAIL', admin_email());
It returns a blank page though
Edit:
My second try, didn't work neither
PHP Code: <?php $dir = GSUSERSPATH;
$dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; }
rsort($files); print_r($files); $xml=simplexml_load_file($files[0]);
echo $xml->email . "<br>"; ?>
Posts: 3,491
Threads: 106
Joined: Mar 2010
Maybe with:
Code: global $EMAIL;
// ... then use the $EMAIL variable
Posts: 25
Threads: 5
Joined: Jul 2014
(2014-07-11, 23:27:50)Carlos Wrote: Maybe with:
Code: global $EMAIL;
// ... then use the $EMAIL variable
Sorry, I didn't understand your answer, can you explain it a little further please?
Thanks
Posts: 6,266
Threads: 181
Joined: Sep 2011
you did not specifcy from frontend or backend ?
Logged in user, or any arbitrary user email ?
There is no such thing as "admin" in getsimple.
PHP Code: $user = 'admin'; $file = _id($user) .'.xml'; $data = getXML(GSUSERSPATH . $file); $email = (string)$data->EMAIL;
Posts: 3,491
Threads: 106
Joined: Mar 2010
I think that the global $EMAIL variable contains the current (logged in) user name.
However, I hadn't realized you said this:
(2014-07-11, 07:17:11)lukinhasb Wrote: The same entered during install, and seen on Settings
If there are several users in the site, you cannot know which one did the install (or if it still exists)
Posts: 25
Threads: 5
Joined: Jul 2014
2014-07-12, 00:52:12
(This post was last modified: 2014-07-12, 00:52:51 by lukinhasb.)
(2014-07-12, 00:44:54)shawn_a Wrote: you did not specifcy from frontend or backend ?
Logged in user, or any arbitrary user email ?
There is no such thing as "admin" in getsimple.
PHP Code: $user = 'admin'; $file = _id($user) .'.xml'; $data = getXML(GSUSERSPATH . $file); $email = $data->EMAIL;
I'm sorry, it's from the backend. Assuming there will be only one user, and I don't know his username, how can I retrieve his e-mail?
(I'm trying to do a website that can be set up in less than 5 minutes, and the contact form should be pre-configured with the e-mail inserted during Get-Simple installation, to save time. I'll block the add/remove user functions)
Posts: 6,266
Threads: 181
Joined: Sep 2011
global $EMAIL like carlos said probably does not exists but you can use.
$datau->EMAIL
there is
get_site_email($echo=true);
But it uses global $EMAIL, but i do not see if ever getting set in common.php so i am not sure it works.
It is also only available on front end pre 3.4
new issue ( https://github.com/GetSimpleCMS/GetSimpleCMS/issues/868)
so nevermind
use
$USR_email = trim(stripslashes($datau->EMAIL));
Posts: 3,491
Threads: 106
Joined: Mar 2010
Sorry for my misleading reply. As Shawn says $EMAIL does not currently work. That was in GS 2.x
If you want to get the current (logged in) user's email you can do as Shawn suggests above.
However if you want a main email address that also works for frontend anonymous users, I suggest you define it in gsconfig.php, changing:
Code: #define('GSFROMEMAIL', 'noreply@get-simple.info');
by:
Code: define('GSFROMEMAIL', 'youremail@domain.com');
and then check this constant in your code like, for example:
Code: if (defined('GSFROMEMAIL')) {
$email = GSFROMEMAIL;
} else {
$email = 'someemail@domain.com';
}
I hope you get the idea.
Posts: 6,266
Threads: 181
Joined: Sep 2011
Just be aware that this is the sending email used for sending emails, and it could be a noreply@ etc. which would go nowhere.
I wonder if $EMAIL got removed.
Posts: 3,491
Threads: 106
Joined: Mar 2010
Yup, another wrong answer... definitely not my day, sorry.
Posts: 25
Threads: 5
Joined: Jul 2014
Thanks for all your help guys.
It's solved though, found this code on Simple ©ontact plugin: http://get-simple.info/forums/showthread...7#pid44287
PHP Code: /* * Return email of the first GS user found * @return string */
function simple_c_default_email() { $files = scandir(GSUSERSPATH); foreach ($files as $filename) { if (preg_match("#\.xml$#", $filename)) { $data = getXML(GSUSERSPATH . $filename); return $data->EMAIL; } } return ""; }
Posts: 6,266
Threads: 181
Joined: Sep 2011
|