2

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!

1
  • Have you tried using an absolute path instead of relative? i.e.: require('/path/to/simplemodal-login/simplemodal-login.php'); Commented Aug 7, 2012 at 18:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That worked! Thank you so much! I would vote you up if I could.
@AndrewAnon Glad that worked, you are able to accept the answer by clicking the checkmark to the left of the answer. That will build up your rep so you can soon vote on questions.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.