Reputation: 33
This is my first post on stack overflow, so I apologize if I have violated etiquette or otherwise did something dumb. I'm also a novice programmer as well, so I apologize in advance if this question seems dumb.
Now on to the main point: I'm trying to create a WordPress plugin for a website while our main programmer is on vacation. I've had some success, and now what I need to do is call simplemodal-login from the plugin after the user does a certain action on the webpage. Currently, I am trying this in order to include the files, which are in a separate directory one level up from the plugin in file(I'm going to block out files names to preserve anonymity):
include ("../simplemodal-login/simplemodal-login.php");
I've also tried prefixing the simplemodal-login directory part with /../
, ../../
, and /../../
. I've also tried
include ("{$_SERVER['DOCUMENT_ROOT']}/[project name]/wp-content/plugins/simplemodal-login");
and some variations of it. Nothing has worked. I keep on getting variations of this error message:
Warning: include(../simplemodal-login/simplemodal-login.php) [function.include]: failed to open stream: No such file or directory in /home/[user name]/public_html/[website name]/[project name]/wp-content/plugins/[my plugin]/[plugin file] on line 29
Warning: include() [function.include]: Failed opening '../simplemodal-login/simplemodal-login.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/[user name]/public_html/[website name]/[project name]/wp-content/plugins/[plugin name]/[plugin file].php on line 29
What am I doing wrong? I simply want to run the simplemodal-login plugin after the user sees the webpage a certain amount of times. How can I include the file properly? I apologize for my inexperience - I've taken an intro course in Java at college (which I did well in) and I've learned a little (I mean LITTLE) bit of PHP this summer as an intern. If anyone could guide me so I don't get that error message when I try to include the files, it would be very helpful.
Thanks!
Upvotes: 2
Views: 1671
Reputation: 69967
If the file you are trying to include is one directory level up from the plugin file you are writing the code in, a portable solution would be to use:
include dirname(__FILE__) . '/../file.php';
dirname(__FILE__)
returns the path of the file that that statement is executed in (regardless of whether or not it has been included itself). I use this in Wordpress plugins without any issues.
Hope that helps.
Upvotes: 1