I'm developing a plugin. At present I have two files. dotmailer.php and dotmailer-add.php. I'm creating a newsletter widget.
My dotmailer.php
plugin adds an admin menu, with options. It allows the admin to store an email address which is used as authentication for the API I'm using. This is taken from the options page form and stored as such:
$apiemail = get_option('apiemail');
I've also created a widget, this is the front-facing bit. The user inputs their email in the form and the form POSTs to a new file called dotmailer-add.php. So this file has the variable $useremail
taken from the form.
Now I'm stuck, because I need the var $useremail
to be useable witin dotmailer-add.php. There is no way to send this through a form or anything because the form already posts through to the wordpress options.php file.
I know when working with PHP sessions are often used to store variables that are needed across multiple files. My issue is that the admin will not be submitting the API emal to the Wordpress options page every time they log in, so they won't be starting a new session each time. I need the var $useremail
to be available across all my plugin files at all times.
I tried using include
but unfortunately I get whitescreened with no errors (error messages are on).
How can I set a global variable through Wordpress options and have it available across multiple files within a plugin?
options.php
file, why don't you retrieve the value via get_option('useremail') Or am I missing something?dotmailer-add.php
you could put it in your widget. have the form submit to the current page and include a URL parameter that passes the value of the email address. have the widget code check for the existence of the parameter and perform the processing. this also allows you to replace the widget form with a 'thanks for signing up' message.