dongtaotao19830418 2012-08-07 18:38
浏览 25
已采纳

PHP包含()用于WordPress插件 - 错误/警告消息

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条回答 默认 最新

  • douyiji3919 2012-08-07 18:43
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥23 (标签-bug|关键词-密码错误加密)
  • ¥66 比特币地址如何生成taproot地址
  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决